Skip to content

Commit cead587

Browse files
committed
move abi checks to a feature and build the C code at build time
The abi tests are now conditional to the abi-tests feature, when that is enabled, the C code for the abi tests is now built at compile time, using the cc crate rather than having our own Compiler abstraction and having to compile stuff at runtime and deal with temp directories etc.
1 parent 1c7b41a commit cead587

File tree

12 files changed

+186
-160
lines changed

12 files changed

+186
-160
lines changed

src/codegen/sys/build.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::collect_versions;
2-
use crate::{codegen::general, env::Env, file_saver::save_to_file};
2+
use crate::{codegen::general, env::Env, file_saver::save_to_file, library::MAIN_NAMESPACE};
33
use log::info;
44
use std::io::{Result, Write};
55

@@ -30,10 +30,14 @@ pub fn generate(env: &Env) {
3030

3131
#[allow(clippy::write_literal)]
3232
fn generate_build_script(w: &mut dyn Write, env: &Env, split_build_rs: bool) -> Result<()> {
33+
let ns = env.library.namespace(MAIN_NAMESPACE);
34+
let package_name = ns.package_name.as_ref().expect("Missing package name");
35+
3336
if !split_build_rs {
3437
general::start_comments(w, &env.config)?;
3538
writeln!(w)?;
3639
}
40+
3741
writeln!(
3842
w,
3943
"{}",
@@ -55,10 +59,43 @@ fn main() {} // prevent linking libraries to avoid documentation failure
5559
5660
#[cfg(not(feature = "dox"))]
5761
fn main() {
58-
if let Err(s) = system_deps::Config::new().probe() {
62+
let libs = system_deps::Config::new().probe();
63+
if let Err(s) = libs {
5964
println!("cargo:warning={}", s);
6065
process::exit(1);
6166
}
67+
68+
#[cfg(feature = "abi-tests")]
69+
{
70+
let libs = libs.unwrap();
71+
"##
72+
)?;
73+
74+
write!(
75+
w,
76+
" let includes = libs.get(\"{}\").unwrap().include_paths.clone();",
77+
package_name
78+
)?;
79+
80+
write!(
81+
w,
82+
"{}",
83+
r##"
84+
85+
let mut cc = cc::Build::new();
86+
87+
cc.flag_if_supported("-Wno-deprecated-declarations");
88+
cc.flag_if_supported("-std=c11"); // for _Generic
89+
90+
cc.file("tests/constant.c");
91+
cc.file("tests/layout.c");
92+
93+
for i in includes {
94+
cc.include(i);
95+
}
96+
97+
cc.compile("cabitests");
98+
}
6299
}
63100
"##
64101
)

src/codegen/sys/cargo_toml.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ fn fill_in(root: &mut Table, env: &Env) {
8383

8484
{
8585
let build_deps = upsert_table(root, "build-dependencies");
86+
set_string(build_deps, "cc", "1.0.0");
8687
set_string(build_deps, "system-deps", "2.0");
8788
}
8889

8990
{
9091
let dev_deps = upsert_table(root, "dev-dependencies");
9192
set_string(dev_deps, "shell-words", "1.0.0");
92-
set_string(dev_deps, "tempfile", "3");
93-
unset(dev_deps, "tempdir");
9493
}
9594

9695
{
@@ -115,6 +114,7 @@ fn fill_in(root: &mut Table, env: &Env) {
115114
.collect(),
116115
),
117116
);
117+
features.insert("abi-tests".to_string(), Value::Array(Vec::new()));
118118
}
119119

120120
{

0 commit comments

Comments
 (0)