File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Add static and shared library support
2+
3+ Adds support for building ` tree_magic_mini ` as static and shared libraries with C FFI bindings.
4+
5+ - Added C FFI wrappers for all public APIs
6+ - Updated ` Cargo.toml ` to build ` cdylib ` and ` staticlib ` crate types
7+ - Added Nix package with C header generation via ` cbindgen ` and pkg-config support
Original file line number Diff line number Diff line change 1+ language = " C"
2+
3+ [struct ]
4+ derive_eq = true
5+
6+ [enum ]
7+ add_sentinel = true
8+ prefix_with_name = true
Original file line number Diff line number Diff line change 88 } ;
99
1010 outputs =
11- { nixpkgs , rust-overlay , ... } :
11+ {
12+ self ,
13+ nixpkgs ,
14+ rust-overlay ,
15+ } :
1216 let
1317 systems = [
1418 "x86_64-linux"
4145 RUST_SRC_PATH = "${ pkgs . rustToolchain } /lib/rustlib/src/rust/library" ;
4246 } ;
4347 } ) ;
48+
49+ packages = forAllSystems ( pkgs : {
50+ tree_magic_mini = pkgs . callPackage ./nix/package.nix { } ;
51+ default = self . packages . ${ pkgs . stdenv . hostPlatform . system } . tree_magic_mini ;
52+ } ) ;
4453 } ;
4554}
Original file line number Diff line number Diff line change 1+ {
2+ rustPlatform ,
3+ lib ,
4+ gcc ,
5+ stdenv ,
6+ rust-cbindgen ,
7+ } :
8+ let
9+ cargoToml = fromTOML ( builtins . readFile ../Cargo.toml ) ;
10+ in
11+ rustPlatform . buildRustPackage ( finalAttrs : {
12+ pname = "tree_magic_mini" ;
13+ inherit ( cargoToml . package ) version ;
14+
15+ cargoLock = {
16+ lockFile = ../Cargo.lock ;
17+ } ;
18+
19+ src = lib . cleanSourceWith {
20+ src = ../. ;
21+ filter =
22+ p : type :
23+ let
24+ relPath = lib . removePrefix ( toString ../. + "/" ) ( toString p ) ;
25+ in
26+ lib . any ( p : lib . hasPrefix p relPath ) [
27+ "src"
28+ "tests"
29+ "magic_db"
30+ "benches"
31+ "cbindgen.toml"
32+ "Cargo.toml"
33+ "Cargo.lock"
34+ "tree_magic_mini.pc.in"
35+ ] ;
36+ } ;
37+
38+ nativeBuildInputs = [
39+ rustPlatform . bindgenHook
40+ rust-cbindgen
41+ ] ;
42+
43+ buildInputs = [
44+ gcc
45+ ] ;
46+
47+ postInstall = ''
48+ mkdir -p $out/include
49+ cbindgen --config cbindgen.toml --crate tree_magic_mini --output $out/include/tree_magic_mini.h --lang C
50+
51+ mkdir -p $out/lib
52+ cp target/${ stdenv . hostPlatform . rust . rustcTarget } /release/libtree_magic_mini${ stdenv . hostPlatform . extensions . sharedLibrary } $out/lib
53+
54+ mkdir -p $out/lib/pkgconfig
55+
56+ sed \
57+ -e "s|@PREFIX@|$out|g" \
58+ -e "s|@INCLUDE@|$out/include|g" \
59+ -e "s|@LIBDIR@|$out/lib|g" \
60+ -e "s|@VERSION@|${ finalAttrs . version } |g" \
61+ < ./tree_magic_mini.pc.in > $out/lib/pkgconfig/tree_magic_mini.pc
62+ '' ;
63+
64+ doCheck = false ;
65+
66+ meta = {
67+ description = "Determines the MIME type of a file by traversing a filetype tree." ;
68+ homepage = "https://github.com/mbrubeck/tree_magic" ;
69+ license = lib . licenses . gpl3 ;
70+ maintainers = builtins . attrValues { inherit ( lib . maintainers ) r0chd ; } ;
71+ platforms = lib . platforms . all ;
72+ } ;
73+ } )
Original file line number Diff line number Diff line change 1+ prefix = @PREFIX@
2+ includedir = @INCLUDE@
3+ libdir = @LIBDIR@
4+
5+ Name : tree_magic_mini
6+ URL : https://github.com/mbrubeck/tree_magic
7+ Description : Determines the MIME type of a file by traversing a filetype tree.
8+ Version : @VERSION@
9+ Cflags : -I ${ includedir}
10+ Libs : -L ${ libdir} -l tree_magic_mini
You can’t perform that action at this time.
0 commit comments