forked from mozilla/cbindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporate dtolnay/proc-macro2#220 to fix the case where a binary which is built with `panic = "abort"` aborts when calling into cbindgen functionality. mozilla#569 Signed-off-by: Grant Elbert <elbe0046@gmail.com>
- Loading branch information
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "panic_abort" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[profile.dev] | ||
panic = "abort" | ||
|
||
[profile.release] | ||
panic = "abort" | ||
|
||
[dependencies] | ||
cbindgen = { path = "../.." } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::{env, process}; | ||
|
||
fn exit_with_usage(exe_name: impl AsRef<str>) -> ! { | ||
eprintln!("Usage: {} MANIFEST_PATH PKG_NAME", exe_name.as_ref()); | ||
process::exit(1); | ||
} | ||
|
||
/// A cbindgen wrapper whose return status can be leveraged by tests. Of note is that it is built | ||
/// with `panic = "abort"` with respect to https://github.com/alexcrichton/proc-macro2/pull/220. | ||
pub fn main() { | ||
let opts = env::args().collect::<Vec<String>>(); | ||
if opts.len() < 3 { | ||
exit_with_usage(&opts[0]); | ||
} | ||
let crate_dir = &opts[1]; | ||
let pkg_name = &opts[2]; | ||
|
||
cbindgen::Builder::new() | ||
.with_crate(crate_dir) | ||
.with_parse_expand(&vec![pkg_name]) | ||
.generate() | ||
.expect("Unable to generate bindings"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::{env, path::PathBuf, process::Command}; | ||
|
||
#[test] | ||
fn test_panic_abort_strategy() { | ||
// Validates cbindgen's incorporation of https://github.com/alexcrichton/proc-macro2/issues/218. | ||
// | ||
// Run a binary whose profile specifies `panic = "abort"` and where the binary proceeds to | ||
// call into cbindgen's generation functionality. Prior to the incorporation of the above this | ||
// would result in the binary aborting. | ||
let cargo = env::var("CARGO").unwrap_or_else(|_| String::from("cargo")); | ||
let mut cmd = Command::new(cargo); | ||
|
||
let tests_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("tests"); | ||
let wrapper_manifest_path = tests_dir.join("basic_cbindgen_wrapper").join("Cargo.toml"); | ||
let arg_manifest_dir = tests_dir.join("rust").join("expand_dep"); | ||
|
||
cmd.arg("run"); | ||
cmd.arg("--manifest-path"); | ||
cmd.arg(wrapper_manifest_path.as_path().to_str().unwrap()); | ||
cmd.arg("--"); | ||
cmd.arg(arg_manifest_dir.as_path().to_str().unwrap()); | ||
cmd.arg("expand-dep"); | ||
|
||
let output = cmd.output().expect("Failed to run cargo command"); | ||
|
||
assert!( | ||
output.status.success(), | ||
"Cargo run failed: {}", | ||
String::from_utf8_lossy(&output.stderr) | ||
); | ||
} |