Closed bossmc closed 4 years ago
Hey, thanks for that pull request! It implements #5 quite nicely.
I've only shallowly tested that plain cargo build && cargo test
still works in Ubuntu 20.04 LTS in WSLv2, will see how Travis CI likes this.
@bossmc Are you using rust-magic-sys
by itself or would you also like me to update robo9k/rust-magic
?
I'm using rust-magic-sys
through rust-magic
, but I don't think I need any changes to rust-magic
to be able to use this (assuming this is released in a version of rust-magic-sys
that's semver-compatible with the previous one, which I think should be possible since the fallback behaviour is unchanged?).
The only thing I'm not sure about is where the documentation for this should live, maybe leave the docs in this repo's README and link to them from rust-magic
's README with something like:
By default
rust-magic
will search your system library paths for a version oflibmagic.so
, if you're cross-compiling, or need more control over which library is selected, see [here]().
@bossmc I've updated this repo's README and reference it in rust-magic
's README. I've also published a new 0.2.1
version of rust-magic-sys
, which should be semver compatible with the 0.2.0
from rust-magic
's requirements.
CI build of rust-magic
is failing, but that's unrelated and should be fixed with the next commit. Please give it a try
Thanks, that's working for me!
$ X86_64_UNKNOWN_LINUX_MUSL_MAGIC_STATIC=true X86_64_UNKNOWN_LINUX_MUSL_MAGIC_DIR=$PWD/../libmagic/src/.libs cargo b --target x86_64-unknown-linux-musl
Compiling magic-sys v0.2.1
Compiling magic v0.12.2
Compiling magic-test v0.1.0 (/home/andy/src/magic-test)
Finished dev [unoptimized + debuginfo] target(s) in 0.78s
$ ldd target/x86_64-unknown-linux-musl/debug/magic-test
not a dynamic executable
$ target/x86_64-unknown-linux-musl/debug/magic-test
mime: text/x-python; charset=us-ascii
In a way similar to
openssl-sys
this allows the user to pass aMAGIC_DIR
environment variable that tells rustc where to findlibmagic.so/libmagic.a
. For finer grained control, the user can pass an environment variable likex86_64_UNKNOWN_LINUX_MUSL_MAGIC_DIR
to only set the custom search path for a specific target.Static linking is also now possible, detected either by only a
libmagic.a
found in the (provided) search path, or by explicitly passingMAGIC_STATIC=true
(or<TARGET>_MAGIC_STATIC=true
). SimilarlyMAGIC_STATIC=false
can be passed to choose to link dynamically. If neither is passed, but both libraries are available, thebuild.rs
bails out and asks the user to choose an implementation, an alternative would be to pick one (openssl-sys
picks "shared library" in this case).Tested with a local, static-only,
musl-gcc
-compiled libmagic:If neither environment variable is set, the behaviour is completely unchanged (we link dynamically with the system-wide library).