-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Description
Hello, I've tried to use the cmake crate as a dependency in my crate and while it works locally it fails when I add my crate as a dependency (pulled from crates.io) in a test program:
Updating crates.io index
Compiling my_lib v0.1.0
error: failed to run custom build command for `my_lib v0.1.0`
Caused by:
process didn't exit successfully: `./hello_world/target/debug/build/my_lib-8352397569f3c080/build-script-build` (exit code: 101)
--- stdout
running: "cmake" "/Users/user/.cargo/registry/src/github.202132.xyz-1ecc6299db9ec823/my_lib-0.1.0/src/native" "-DENABLE_RUST=1" "-DCMAKE_INSTALL_PREFIX=target" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -arch x86_64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -arch x86_64" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -arch x86_64" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=Debug"
--- stderr
thread 'main' panicked at '
failed to execute command: No such file or directory (os error 2)
is `cmake` not installed?
build script failed, must exit now', /Users/user/.cargo/registry/src/github.202132.xyz-1ecc6299db9ec823/cmake-0.1.45/src/lib.rs:894:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
With RUST_BACKTRACE=full
:
0: 0x10aa098fe - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h04abbaabf148650a
1: 0x10aa44f4e - core::fmt::write::h14dac7cadec1cc70
2: 0x10aa08e1a - std::io::Write::write_fmt::hfaf2e10dfdcc61d8
3: 0x10aa25339 - std::panicking::default_hook::{{closure}}::h350fee0bf60f2674
4: 0x10aa24eab - std::panicking::default_hook::h0b4e3bc46e6dcb8d
5: 0x10aa258ca - std::panicking::rust_panic_with_hook::h8cdc0a575f4a5a7b
6: 0x10aa0a0c5 - std::panicking::begin_panic_handler::{{closure}}::h7a7b30fd1c313876
7: 0x10aa09a48 - std::sys_common::backtrace::__rust_end_short_backtrace::h2e099be83c81509d
8: 0x10aa25443 - _rust_begin_unwind
9: 0x10aa4e37b - std::panicking::begin_panic_fmt::h170f888f0234d849
10: 0x10a4ab797 - cmake::fail::hcc02c6703578abbb
at /Users/user/.cargo/registry/src/github.202132.xyz-1ecc6299db9ec823/cmake-0.1.45/src/lib.rs:894:5
11: 0x10a4ab01e - cmake::run::hbff0b8ae6b19dbe5
at /Users/user/.cargo/registry/src/github.202132.xyz-1ecc6299db9ec823/cmake-0.1.45/src/lib.rs:864:13
12: 0x10a4a7b12 - cmake::Config::build::h0f5bbc869444f990
at /Users/user/.cargo/registry/src/github.202132.xyz-1ecc6299db9ec823/cmake-0.1.45/src/lib.rs:707:13
13: 0x10a4a2333 - build_script_build::main::h2b88eca7a261b7c1
at /Users/user/.cargo/registry/src/github.202132.xyz-1ecc6299db9ec823/my_lib-0.1.0/build.rs:8:5
14: 0x10a4a333e - core::ops::function::FnOnce::call_once::h12e0ebb75b1fb6b6
at /private/tmp/rust-20210325-88347-hh2ixd/rustc-1.51.0-src/library/core/src/ops/function.rs:227:5
15: 0x10a4a3231 - std::sys_common::backtrace::__rust_begin_short_backtrace::h47609506cf3640de
at /private/tmp/rust-20210325-88347-hh2ixd/rustc-1.51.0-src/library/std/src/sys_common/backtrace.rs:125:18
16: 0x10a4a4b24 - std::rt::lang_start::{{closure}}::h0ceb54217ca0fbdd
at /private/tmp/rust-20210325-88347-hh2ixd/rustc-1.51.0-src/library/std/src/rt.rs:66:18
17: 0x10aa28a00 - std::rt::lang_start_internal::hf4b96bfc8c02c8b0
18: 0x10a4a4b01 - std::rt::lang_start::h454b772cdebf3322
at /private/tmp/rust-20210325-88347-hh2ixd/rustc-1.51.0-src/library/std/src/rt.rs:65:5
19: 0x10a4a27a2 - _main
My crate's build.rs
:
extern crate bindgen;
use cmake::Config;
use std::env;
use std::path::PathBuf;
fn main() {
Config::new("src/native").build_target("my_lib-static").define("ENABLE_RUST", "1").out_dir("target").build();
println!("cargo:rustc-link-search=target/build/lib");
println!("cargo:rustc-link-lib=static=my_lib");
// See here for reasoning: https://flames-of-code.netlify.app/blog/rust-and-cmake-cplusplus/
let target = env::var("TARGET").unwrap();
if target.contains("apple") {
println!("cargo:rustc-link-lib=dylib=c++");
} else if target.contains("linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
} else {
unimplemented!();
}
let bindings = bindgen::Builder::default()
.header("src/native/include/my_lib.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("my_lib.rs"))
.expect("Couldn't write bindings!");
}
- I have CMake installed
- CMake is in my path
- I have tested this on macOS and Ubuntu. Same result for both.
Any advice on how I should proceed?
NicolasRoelandt
Metadata
Metadata
Assignees
Labels
No labels