It might be helpful for consumers to know the libmagic version they link against, e.g. MAGIC_VERSION from magic.h
See robo9k/rust-magic#454 (comment)
Build scripts can be overridden, see https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts
This is expected and supported for magic-sys if someone wants to use neither pkg-config nor vcpkg
Thus the libmagic version would have to be communicated with build script metadata (and not generated & included code files)
When the magic-sys build script runs
https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
cargo:version={libmagic_version}
When the script is overridden by a user
[target.x86_64-unknown-linux-gnu.magic]
metadata_version = "5xy"
Metadata might also have to be set to a fake but valid value for docs.rs, possibly approximated by using the greatest activated crate version feature "v5-xy"
pkg-config already provides Library::version
vcpkg however does not, see https://redirect.github.com/mcgoo/vcpkg-rs/pull/56
Our setup-libmagic action does something similar with external tools, i.e. also for vcpkg: pkgconf.exe --modversion libmagic
Without pkg-config {libmagic_version} could be determined using a dependency on cc
#include <magic.h>
RUST_LIBMAGIC_VERSION=MAGIC_VERSION
let mut cc = cc::Build::new();
cc.includes(include_dirs);
let expanded = cc.file("build/expando.c").try_expand()?;
// TODO: parse version, println! metadata
Then finally a dependent could use this in their own build script, e.g. in magic
let libmagic_version = env::var("DEP_MAGIC_VERSION");
This could be used to e.g. codegen a file with const MAGIC_VERSION: c_int = 547; and include! it
Note that libmagic.pc has Version as 5.47, but it might be more intuitive to match the number format from runtime magic_version
Downsides to the above solution are; a new dependency on cc in magic-sys
and a requirement for a build script in dependents, e.g. in magic
This might still be more acceptable than runtime bindgen. Maybe regex instead of full cc?
It might be helpful for consumers to know the
libmagicversion they link against, e.g.MAGIC_VERSIONfrommagic.hSee robo9k/rust-magic#454 (comment)
Build scripts can be overridden, see https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts
This is expected and supported for
magic-sysif someone wants to use neitherpkg-confignorvcpkgThus the
libmagicversion would have to be communicated with build script metadata (and not generated & included code files)When the
magic-sysbuild script runshttps://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
When the script is overridden by a user
Metadata might also have to be set to a fake but valid value for
docs.rs, possibly approximated by using the greatest activated crate version feature "v5-xy"pkg-configalready providesLibrary::versionvcpkghowever does not, see https://redirect.github.com/mcgoo/vcpkg-rs/pull/56Our
setup-libmagicaction does something similar with external tools, i.e. also forvcpkg:pkgconf.exe --modversion libmagicWithout
pkg-config{libmagic_version}could be determined using a dependency onccThen finally a dependent could use this in their own build script, e.g. in
magicThis could be used to e.g. codegen a file with
const MAGIC_VERSION: c_int = 547;andinclude!itNote that
libmagic.pchas Version as5.47, but it might be more intuitive to match the number format from runtimemagic_versionDownsides to the above solution are; a new dependency on
ccinmagic-sysand a requirement for a build script in dependents, e.g. in
magicThis might still be more acceptable than runtime
bindgen. Maybe regex instead of fullcc?