Skip to content

Commit

Permalink
move abi checks to a feature and build the C code at build time
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pbor committed Feb 7, 2021
1 parent 1c7b41a commit cead587
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 160 deletions.
41 changes: 39 additions & 2 deletions src/codegen/sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::collect_versions;
use crate::{codegen::general, env::Env, file_saver::save_to_file};
use crate::{codegen::general, env::Env, file_saver::save_to_file, library::MAIN_NAMESPACE};
use log::info;
use std::io::{Result, Write};

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

#[allow(clippy::write_literal)]
fn generate_build_script(w: &mut dyn Write, env: &Env, split_build_rs: bool) -> Result<()> {
let ns = env.library.namespace(MAIN_NAMESPACE);
let package_name = ns.package_name.as_ref().expect("Missing package name");

if !split_build_rs {
general::start_comments(w, &env.config)?;
writeln!(w)?;
}

writeln!(
w,
"{}",
Expand All @@ -55,10 +59,43 @@ fn main() {} // prevent linking libraries to avoid documentation failure
#[cfg(not(feature = "dox"))]
fn main() {
if let Err(s) = system_deps::Config::new().probe() {
let libs = system_deps::Config::new().probe();
if let Err(s) = libs {
println!("cargo:warning={}", s);
process::exit(1);
}
#[cfg(feature = "abi-tests")]
{
let libs = libs.unwrap();
"##
)?;

write!(
w,
" let includes = libs.get(\"{}\").unwrap().include_paths.clone();",
package_name
)?;

write!(
w,
"{}",
r##"
let mut cc = cc::Build::new();
cc.flag_if_supported("-Wno-deprecated-declarations");
cc.flag_if_supported("-std=c11"); // for _Generic
cc.file("tests/constant.c");
cc.file("tests/layout.c");
for i in includes {
cc.include(i);
}
cc.compile("cabitests");
}
}
"##
)
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/sys/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ fn fill_in(root: &mut Table, env: &Env) {

{
let build_deps = upsert_table(root, "build-dependencies");
set_string(build_deps, "cc", "1.0.0");
set_string(build_deps, "system-deps", "2.0");
}

{
let dev_deps = upsert_table(root, "dev-dependencies");
set_string(dev_deps, "shell-words", "1.0.0");
set_string(dev_deps, "tempfile", "3");
unset(dev_deps, "tempdir");
}

{
Expand All @@ -115,6 +114,7 @@ fn fill_in(root: &mut Table, env: &Env) {
.collect(),
),
);
features.insert("abi-tests".to_string(), Value::Array(Vec::new()));
}

{
Expand Down
Loading

0 comments on commit cead587

Please sign in to comment.