From f3149d7f2802711791c490b71313aafc55f4809c Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Mon, 15 Jan 2018 09:36:38 -0800 Subject: Update hidapi-sys crate to 0.1.4 This change updates the hidapi-sys crate to version 0.1.4. In this version the cc crate (the stable and renamed version of the gcc crate) is used. Import subrepo hidapi-sys/:hidapi-sys at c01043da72c0cac898660017e4c4115278c14369 Import subrepo cc/:cc at 500c65b03775cecf55bd358e616963bc3222acca --- cc/cc-test/Cargo.toml | 15 +++++++ cc/cc-test/build.rs | 94 ++++++++++++++++++++++++++++++++++++++++++++ cc/cc-test/src/NMakefile | 14 +++++++ cc/cc-test/src/bar1.c | 7 ++++ cc/cc-test/src/bar2.c | 6 +++ cc/cc-test/src/baz.cpp | 9 +++++ cc/cc-test/src/expand.c | 4 ++ cc/cc-test/src/foo.c | 9 +++++ cc/cc-test/src/i686.S | 9 +++++ cc/cc-test/src/i686.asm | 9 +++++ cc/cc-test/src/include/foo.h | 0 cc/cc-test/src/lib.rs | 16 ++++++++ cc/cc-test/src/msvc.c | 7 ++++ cc/cc-test/src/opt_linkage.c | 5 +++ cc/cc-test/src/windows.c | 3 ++ cc/cc-test/src/x86_64.S | 9 +++++ cc/cc-test/src/x86_64.asm | 8 ++++ cc/cc-test/tests/all.rs | 60 ++++++++++++++++++++++++++++ 18 files changed, 284 insertions(+) create mode 100644 cc/cc-test/Cargo.toml create mode 100644 cc/cc-test/build.rs create mode 100644 cc/cc-test/src/NMakefile create mode 100644 cc/cc-test/src/bar1.c create mode 100644 cc/cc-test/src/bar2.c create mode 100644 cc/cc-test/src/baz.cpp create mode 100644 cc/cc-test/src/expand.c create mode 100644 cc/cc-test/src/foo.c create mode 100644 cc/cc-test/src/i686.S create mode 100644 cc/cc-test/src/i686.asm create mode 100644 cc/cc-test/src/include/foo.h create mode 100644 cc/cc-test/src/lib.rs create mode 100644 cc/cc-test/src/msvc.c create mode 100644 cc/cc-test/src/opt_linkage.c create mode 100644 cc/cc-test/src/windows.c create mode 100644 cc/cc-test/src/x86_64.S create mode 100644 cc/cc-test/src/x86_64.asm create mode 100644 cc/cc-test/tests/all.rs (limited to 'cc/cc-test') diff --git a/cc/cc-test/Cargo.toml b/cc/cc-test/Cargo.toml new file mode 100644 index 0000000..e83416a --- /dev/null +++ b/cc/cc-test/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cc-test" +version = "0.1.0" +authors = ["Alex Crichton "] + +[lib] +name = "cc_test" +doctest = false +test = false + +[build-dependencies] +cc = { path = ".." } + +[features] +parallel = ["cc/parallel"] diff --git a/cc/cc-test/build.rs b/cc/cc-test/build.rs new file mode 100644 index 0000000..5a7b178 --- /dev/null +++ b/cc/cc-test/build.rs @@ -0,0 +1,94 @@ +extern crate cc; + +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(); + + cc::Build::new() + .file("src/foo.c") + .flag_if_supported("-Wall") + .flag_if_supported("-Wfoo-bar-this-flag-does-not-exist") + .define("FOO", None) + .define("BAR", "1") + .compile("foo"); + + cc::Build::new() + .file("src/bar1.c") + .file("src/bar2.c") + .include("src/include") + .compile("bar"); + + 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" }); + cc::Build::new() + .file(file) + .compile("asm"); + + cc::Build::new() + .file("src/baz.cpp") + .cpp(true) + .compile("baz"); + + if target.contains("windows") { + cc::Build::new() + .file("src/windows.c") + .compile("windows"); + } + + // 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 = cc::windows_registry::find(&target, "nmake.exe") + .unwrap() + .env_remove("MAKEFLAGS") + .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 = cc::windows_registry::find(&target, "nmake.exe") + .unwrap() + .env_remove("MAKEFLAGS") + .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. + cc::Build::new() + .cargo_metadata(false) + .file("src/opt_linkage.c") + .compile("OptLinkage"); + + let out = cc::Build::new() + .file("src/expand.c") + .expand(); + let out = String::from_utf8(out).unwrap(); + assert!(out.contains("hello world")); +} diff --git a/cc/cc-test/src/NMakefile b/cc/cc-test/src/NMakefile new file mode 100644 index 0000000..03c73df --- /dev/null +++ b/cc/cc-test/src/NMakefile @@ -0,0 +1,14 @@ +all: $(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.exe + +$(OUT_DIR)/msvc.lib: $(OUT_DIR)/msvc.o + lib -nologo -out:$(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.o + rc -h + +$(OUT_DIR)/msvc.o: src/msvc.c + $(CC) -nologo -c -Fo:$@ src/msvc.c -MD + +$(OUT_DIR)/msvc.exe: $(OUT_DIR)/msvc2.o + $(CC) -nologo -Fo:$@ $(OUT_DIR)/msvc2.o + +$(OUT_DIR)/msvc2.o: src/msvc.c + $(CC) -nologo -c -Fo:$@ src/msvc.c -DMAIN -MD diff --git a/cc/cc-test/src/bar1.c b/cc/cc-test/src/bar1.c new file mode 100644 index 0000000..605be33 --- /dev/null +++ b/cc/cc-test/src/bar1.c @@ -0,0 +1,7 @@ +#include +#include "foo.h" + +int32_t bar1() { + return 5; +} + diff --git a/cc/cc-test/src/bar2.c b/cc/cc-test/src/bar2.c new file mode 100644 index 0000000..9be4291 --- /dev/null +++ b/cc/cc-test/src/bar2.c @@ -0,0 +1,6 @@ +#include + +int32_t bar2() { + return 6; +} + diff --git a/cc/cc-test/src/baz.cpp b/cc/cc-test/src/baz.cpp new file mode 100644 index 0000000..2d4b959 --- /dev/null +++ b/cc/cc-test/src/baz.cpp @@ -0,0 +1,9 @@ +#include + +extern "C" int32_t +baz() { + int *a = new int(8); + int b = *a; + delete a; + return b; +} diff --git a/cc/cc-test/src/expand.c b/cc/cc-test/src/expand.c new file mode 100644 index 0000000..2b492a2 --- /dev/null +++ b/cc/cc-test/src/expand.c @@ -0,0 +1,4 @@ +#define HELLO hello +#define WORLD world + +HELLO WORLD diff --git a/cc/cc-test/src/foo.c b/cc/cc-test/src/foo.c new file mode 100644 index 0000000..541e62c --- /dev/null +++ b/cc/cc-test/src/foo.c @@ -0,0 +1,9 @@ +#include + +#ifdef FOO +#if BAR == 1 +int32_t foo() { + return 4; +} +#endif +#endif diff --git a/cc/cc-test/src/i686.S b/cc/cc-test/src/i686.S new file mode 100644 index 0000000..3ed9e86 --- /dev/null +++ b/cc/cc-test/src/i686.S @@ -0,0 +1,9 @@ +.globl asm +asm: + mov $7, %eax + ret + +.globl _asm +_asm: + mov $7, %eax + ret diff --git a/cc/cc-test/src/i686.asm b/cc/cc-test/src/i686.asm new file mode 100644 index 0000000..6bf9676 --- /dev/null +++ b/cc/cc-test/src/i686.asm @@ -0,0 +1,9 @@ +.586 +.MODEL FLAT, C +.CODE + +asm PROC + MOV EAX, 7 + RET +asm ENDP +END diff --git a/cc/cc-test/src/include/foo.h b/cc/cc-test/src/include/foo.h new file mode 100644 index 0000000..e69de29 diff --git a/cc/cc-test/src/lib.rs b/cc/cc-test/src/lib.rs new file mode 100644 index 0000000..b42ebf7 --- /dev/null +++ b/cc/cc-test/src/lib.rs @@ -0,0 +1,16 @@ +extern "C" { + pub fn foo() -> i32; + + pub fn bar1() -> i32; + pub fn bar2() -> i32; + + pub fn asm() -> i32; + + pub fn baz() -> i32; + + #[cfg(windows)] + pub fn windows(); + + #[cfg(target_env = "msvc")] + pub fn msvc(); +} diff --git a/cc/cc-test/src/msvc.c b/cc/cc-test/src/msvc.c new file mode 100644 index 0000000..dbbc494 --- /dev/null +++ b/cc/cc-test/src/msvc.c @@ -0,0 +1,7 @@ +#include + +void msvc() {} + +#ifdef MAIN +int main() {} +#endif diff --git a/cc/cc-test/src/opt_linkage.c b/cc/cc-test/src/opt_linkage.c new file mode 100644 index 0000000..a74af8c --- /dev/null +++ b/cc/cc-test/src/opt_linkage.c @@ -0,0 +1,5 @@ +#include + +int32_t answer() { + return 42; +} diff --git a/cc/cc-test/src/windows.c b/cc/cc-test/src/windows.c new file mode 100644 index 0000000..0896aa0 --- /dev/null +++ b/cc/cc-test/src/windows.c @@ -0,0 +1,3 @@ +#include + +void windows() {} diff --git a/cc/cc-test/src/x86_64.S b/cc/cc-test/src/x86_64.S new file mode 100644 index 0000000..3ed9e86 --- /dev/null +++ b/cc/cc-test/src/x86_64.S @@ -0,0 +1,9 @@ +.globl asm +asm: + mov $7, %eax + ret + +.globl _asm +_asm: + mov $7, %eax + ret diff --git a/cc/cc-test/src/x86_64.asm b/cc/cc-test/src/x86_64.asm new file mode 100644 index 0000000..1c03101 --- /dev/null +++ b/cc/cc-test/src/x86_64.asm @@ -0,0 +1,8 @@ +_TEXT SEGMENT + +asm PROC + MOV EAX, 7 + RET +asm ENDP + +END diff --git a/cc/cc-test/tests/all.rs b/cc/cc-test/tests/all.rs new file mode 100644 index 0000000..59cb8e4 --- /dev/null +++ b/cc/cc-test/tests/all.rs @@ -0,0 +1,60 @@ +extern crate cc_test; + +use cc_test::*; + +#[link(name = "OptLinkage", kind = "static")] +extern "C" { + fn answer() -> i32; +} + +#[test] +fn foo_here() { + unsafe { + assert_eq!(foo(), 4); + } +} + +#[test] +fn bar_here() { + unsafe { + assert_eq!(bar1(), 5); + assert_eq!(bar2(), 6); + } +} + +#[test] +fn asm_here() { + unsafe { + assert_eq!(asm(), 7); + } +} + +#[test] +fn baz_here() { + unsafe { + assert_eq!(baz(), 8); + } +} + +#[test] +#[cfg(windows)] +fn windows_here() { + unsafe { + windows(); + } +} + +#[test] +#[cfg(target_env = "msvc")] +fn msvc_here() { + unsafe { + msvc(); + } +} + +#[test] +fn opt_linkage() { + unsafe { + assert_eq!(answer(), 42); + } +} -- cgit v1.2.3