summaryrefslogtreecommitdiff
path: root/gcc/gcc-test/build.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2017-03-26 17:07:27 -0700
committerDaniel Mueller <deso@posteo.net>2017-03-26 17:07:27 -0700
commit86415f23a86b5a44aa000d513500a9d1d0df4bba (patch)
tree5a9c513c9531414502de67dda322fca9baac7563 /gcc/gcc-test/build.rs
parent547085cdefb3372e8c42beabac5d45f2f6b1a535 (diff)
downloadnitrocli-86415f23a86b5a44aa000d513500a9d1d0df4bba.tar.gz
nitrocli-86415f23a86b5a44aa000d513500a9d1d0df4bba.tar.bz2
Import subrepo gcc/:gcc at cf1f00bc038a0df769e14bb85480ab9c12eae08d
Diffstat (limited to 'gcc/gcc-test/build.rs')
-rw-r--r--gcc/gcc-test/build.rs90
1 files changed, 90 insertions, 0 deletions
diff --git a/gcc/gcc-test/build.rs b/gcc/gcc-test/build.rs
new file mode 100644
index 0000000..f81833b
--- /dev/null
+++ b/gcc/gcc-test/build.rs
@@ -0,0 +1,90 @@
+extern crate gcc;
+
+use std::env;
+use std::fs;
+use std::path::PathBuf;
+
+fn main() {
+ let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
+ fs::remove_dir_all(&out).unwrap();
+ fs::create_dir(&out).unwrap();
+
+ gcc::Config::new()
+ .file("src/foo.c")
+ .define("FOO", None)
+ .define("BAR", Some("1"))
+ .compile("libfoo.a");
+
+ gcc::Config::new()
+ .file("src/bar1.c")
+ .file("src/bar2.c")
+ .include("src/include")
+ .compile("libbar.a");
+
+ let target = std::env::var("TARGET").unwrap();
+ let file = target.split("-").next().unwrap();
+ let file = format!("src/{}.{}",
+ file,
+ if target.contains("msvc") { "asm" } else { "S" });
+ gcc::Config::new()
+ .file(file)
+ .compile("libasm.a");
+
+ gcc::Config::new()
+ .file("src/baz.cpp")
+ .cpp(true)
+ .compile("libbaz.a");
+
+ if target.contains("windows") {
+ gcc::Config::new()
+ .file("src/windows.c")
+ .compile("libwindows.a");
+ }
+
+ // Test that the `windows_registry` module will set PATH by looking for
+ // nmake which runs vanilla cl, and then also test it after we remove all
+ // the relevant env vars from our own process.
+ if target.contains("msvc") {
+ let out = out.join("tmp");
+ fs::create_dir(&out).unwrap();
+ println!("nmake 1");
+ let status = gcc::windows_registry::find(&target, "nmake.exe")
+ .unwrap()
+ .arg("/fsrc/NMakefile")
+ .env("OUT_DIR", &out)
+ .status()
+ .unwrap();
+ assert!(status.success());
+
+ fs::remove_dir_all(&out).unwrap();
+ fs::create_dir(&out).unwrap();
+
+ env::remove_var("PATH");
+ env::remove_var("VCINSTALLDIR");
+ env::remove_var("INCLUDE");
+ env::remove_var("LIB");
+ println!("nmake 2");
+ let status = gcc::windows_registry::find(&target, "nmake.exe")
+ .unwrap()
+ .arg("/fsrc/NMakefile")
+ .env("OUT_DIR", &out)
+ .status()
+ .unwrap();
+ assert!(status.success());
+ println!("cargo:rustc-link-lib=msvc");
+ println!("cargo:rustc-link-search={}", out.display());
+ }
+
+ // This tests whether we can build a library but not link it to the main
+ // crate. The test module will do its own linking.
+ gcc::Config::new()
+ .cargo_metadata(false)
+ .file("src/opt_linkage.c")
+ .compile("libOptLinkage.a");
+
+ let out = gcc::Config::new()
+ .file("src/expand.c")
+ .expand();
+ let out = String::from_utf8(out).unwrap();
+ assert!(out.contains("hello world"));
+}