-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo check breaks build_ffi_test #197
Comments
I am facing a similar issue when exposing the C API from Rust. I am not sure if cc-rs can help in this case. It's used to integrate C/C++ code into a Rust library/application. But what mp4parse_capi wants is to integrate Rust code into C/C++ application. The simplest way is to run fn build_ffi_test() {
use std::process::Command;
const C_FILE: &str = "examples/test.cc";
const HEADER_DIR: &str = "include/";
const LIBRARY_DIR: &str = "../target/debug/";
const LIBRARY_NAME: &str = "mp4parse_capi";
const EXECUTABLE: &str = "examples/test";
// Generate a libmp4parse_capi.a if it doesn't exist.
let build_library = Command::new("cargo")
.arg("build")
.output()
.expect("failed to build library");
assert!(build_library.status.success());
let build_executable = Command::new("c++")
.arg(C_FILE)
.arg("-g")
.arg("-Wall")
.arg("-std=c++11")
.arg(format!("-I{}", HEADER_DIR))
.arg("-L")
.arg(LIBRARY_DIR)
.arg(format!("-l{}", LIBRARY_NAME))
.arg("-o")
.arg(EXECUTABLE)
.output()
.expect("failed to build executable");
assert!(build_executable.status.success());
let run_executable = Command::new(EXECUTABLE)
.output()
.expect("failed to run executable");
//let output = String::from_utf8(run_executable.stdout).unwrap();
//println!("{}", output);
assert!(run_executable.status.success());
let remove_executable = Command::new("rm")
.arg(EXECUTABLE)
.output()
.expect("failed to remove executable");
assert!(remove_executable.status.success());
} with adding [lib]
crate-type = ["staticlib", "rlib"]
# "staticlib" for `libmp4parse_capi.a` that will be linked to example/test.cc
# "rlib" for other code use `extern crate mp4parse_capi` in Cargo.toml The code will do the same thing as what Makefile used to do. |
Thanks Chun-Min. That's similar to the fix I'm working on. We can fix this immediate issue by invoking cargo rather than rustc in the Makefile and depending less on (guessing) the layout of cargo's build artifacts. I've got a patch that does that. cc-rs helps for easy cross-platform compiling, but it's restricted to producing libraries so it requires changing the structure of the test, and that introduces other build complexities. If we don't mind adding build-deps, cmake-rs with a simple CMakeLists.txt might work as a suitable cross-platform replacement for the existing Makefile, and should allow the test to still be built as a binary. Another possibility is to give up on trying to build and run C code as part of a Rust test and add extra test runner steps to the CI. |
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
It appears that e006607 broke extern crate byteorder;
extern crate mp4parse; I haven't dug into why, but I wanted an issue to reference in the change to have |
This was changed by rustfmt, but it breaks `build_ffi_test` for some reason. Add annotation to keep rustfmt from reordering them again (at least until we come up with a better fix). See #197 (comment)
This was changed by rustfmt, but it breaks `build_ffi_test` for some reason. Add annotation to keep rustfmt from reordering them again (at least until we come up with a better fix). See #197 (comment)
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes mozilla#197
The existing process invoked a Makefile from a Rust test, building test.cc and a statically linkable mp4parse_capi, then running a series of C API tests. This wasn't very portable due the reliable on a Makefile, which also made assumptions about the layout of cargo's build artifacts. The new process introduces a new crate (test_ffi) and changes mp4parse_capi to additionally build as a cdylib. A build.rs in test_ffi builds test.cc (which must now be written with a simple library API, rather than as a binary with a main() due to cc-rs limitations) into a static libtest, which is then linked to test_ffi's Rust binary in main.rs. test.cc is now split into run_main for the binary dumping tool and test_main for the API tests. `cargo run -p test_ffi path/to/a.mp4` invokes run_main, and test_ffi's ffi_test invokes test_main. Fixes #197
If
cargo check
is run beforecargo test
,build_ffi_test
breaks in the following manner:See #193 (comment) for some background.
In the meantime, we can work around the issue by running
cargo check
(for the sake of checking feature-specific code, since we can't run cargo test with themp4parse_fallible
feature) aftercargo test
.The text was updated successfully, but these errors were encountered: