Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "file"]
path = file
url = https://github.com/file/file
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ rust-version = "1.54"
maintenance = { status = "passively-maintained" }

[features]
default = ["pkg-config", "vcpkg"]
default = ["pkg-config", "vcpkg", "bundled"]
bundled = ["cc", "v5-40"]
# the "default" version feature would be v5-39, but that's API-wise the same as v5-38
v5-40 = []

[build-dependencies]
pkg-config = { version = "0.3.27", optional = true }
vcpkg = { version = "0.2.15", optional = true }
cc = { version = "1.0.79", optional = true }

[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ If you do _not_ use `cargo vcpkg build`, you will have to either
- `vcpkg install libmagic` and set the `VCPKG_ROOT` environment variable for your `vcpkg` root directory
- `vcpkg integrate install` your `vcpkg` root user-wide

## vendor

The `vendor` feature uses the [`cc` crate](https:/docs.rs/cc) to compile and
static link a vendored version of libmagic, currently based on 5.45.

## Override

If you disable or skip both `pkg-config` and `vcpkg` the `magic-sys` build script will fail.\
Expand Down
48 changes: 48 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,55 @@ fn try_vcpkg() -> LibraryResult<vcpkg::Error, vcpkg::Library> {
}
}

#[cfg(feature = "bundled")]
fn try_bundled() {
let out_dir = std::env::var("OUT_DIR").unwrap();
let out_dir = std::path::Path::new(&out_dir);
let include_dir = out_dir.join("include");

// First, copy magic.h.in into out_dir/include/magic.h, replacing the X.YY
// string with the actual versionversion.
std::fs::create_dir_all(&include_dir).unwrap();
let mut data = std::fs::read_to_string("file/src/magic.h.in").unwrap();
data = data.replace("X.YY", "5.45");
std::fs::write(include_dir.join("magic.h"), &data).unwrap();

cc::Build::new()
.include("file/src")
.include(include_dir)
.define("HAVE_UNISTD_H", "1")
.define("HAVE_INTTYPES_H", "1")
.define("VERSION", "5.45")
.file("file/src/buffer.c")
.file("file/src/magic.c")
.file("file/src/apprentice.c")
.file("file/src/softmagic.c")
.file("file/src/ascmagic.c")
.file("file/src/encoding.c")
.file("file/src/compress.c")
.file("file/src/is_csv.c")
.file("file/src/is_json.c")
.file("file/src/is_simh.c")
.file("file/src/is_tar.c")
.file("file/src/readelf.c")
.file("file/src/print.c")
.file("file/src/fsmagic.c")
.file("file/src/funcs.c")
.file("file/src/apptype.c")
.file("file/src/der.c")
.file("file/src/cdf.c")
.file("file/src/cdf_time.c")
.file("file/src/readcdf.c")
.file("file/src/fmtcheck.c")
.compile("magic");
}

fn main() {
#[cfg(feature = "bundled")]
{
let lib = try_bundled();
return;
}
#[cfg(feature = "pkg-config")]
{
let lib = try_pkgconfig();
Expand Down
1 change: 1 addition & 0 deletions file
Submodule file added at 4cbd5c