Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 26eacda

Browse files
committed
Reduce the hard-coding of the target
1 parent f6db971 commit 26eacda

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ install:
1717
- rustup component add rust-src rustfmt clippy
1818

1919
script:
20-
- ./tests/run_tests.py
20+
- ./tests/run_tests.py x86_64-linux-kernel
2121
- |
2222
for p in . hello-world tests/*; do
2323
if [ -d "$p" ]; then

build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ fn main() {
122122
std::process::exit(1);
123123
}
124124

125+
let target = env::var("TARGET").unwrap();
126+
125127
let mut builder = bindgen::Builder::default()
126128
.use_core()
127129
.ctypes_prefix("c_types")
128130
.derive_default(true)
129131
.rustfmt_bindings(true);
130132

131-
builder = builder.clang_arg("--target=x86_64-linux-kernel");
133+
builder = builder.clang_arg(format!("--target={}", target));
132134
for arg in shlex::split(std::str::from_utf8(&output.stdout).unwrap()).unwrap() {
133135
builder = builder.clang_arg(arg.to_string());
134136
}
@@ -161,7 +163,7 @@ fn main() {
161163
let mut builder = cc::Build::new();
162164
println!("cargo:rerun-if-env-changed=CLANG");
163165
builder.compiler(env::var("CLANG").unwrap_or("clang".to_string()));
164-
builder.target("x86_64-linux-kernel");
166+
builder.target(&target);
165167
builder.warnings(false);
166168
builder.file("src/helpers.c");
167169
for arg in shlex::split(std::str::from_utf8(&output.stdout).unwrap()).unwrap() {

tests/run_tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import subprocess
5+
import sys
56

67

78
BASE_DIR = os.path.realpath(os.path.dirname(__file__))
@@ -16,7 +17,8 @@ def run(*args, **kwargs):
1617
subprocess.check_call(list(args), cwd=cwd, env=environ)
1718

1819

19-
def main():
20+
def main(argv):
21+
[_, target] = argv
2022
for path in os.listdir(BASE_DIR):
2123
if (
2224
not os.path.isdir(os.path.join(BASE_DIR, path)) or
@@ -27,7 +29,7 @@ def main():
2729
print("+ [{}]".format(path))
2830
run(
2931
"cargo", "build", "-Zbuild-std=core,alloc",
30-
"--target", "x86_64-linux-kernel",
32+
"--target", target,
3133
cwd=os.path.join(BASE_DIR, path),
3234
environ=dict(
3335
os.environ,
@@ -60,4 +62,4 @@ def main():
6062

6163

6264
if __name__ == "__main__":
63-
main()
65+
main(sys.argv)

0 commit comments

Comments
 (0)