Skip to content

Commit b856110

Browse files
bors[bot]mkroening
andauthored
Merge #195
195: Check for kernel manifest r=mkroening a=mkroening Closes #194. The essence of this PR is adding `--manifest-path Cargo.toml` to the kernel compilation command. Without it, Cargo searches for the Cargo.toml file in the current directory or any parent directory. That results in cargo compiling this repository with the kernel triple, causing #194. This does a little refactoring around the kernel triple, adds `--manifest-path Cargo.toml` and adds a manual check for the existence of the kernel manifest. I also added a note to the README for checking out submodules as requested by `@tlambertz.` Co-authored-by: Martin Kröning <mkroening@posteo.net>
2 parents 16d674b + 37c7ec7 commit b856110

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ rustup component add rust-src
4949
rustup component add llvm-tools-preview
5050
```
5151

52+
If you work with this repository, remember to checkout the submodules.
53+
5254
## Building your own applications
5355

5456
To give you an example on how to build your application with RustyHermit, lets create a new cargo project:

hermit-sys/build.rs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,32 @@ use std::process::Command;
1111
use walkdir::{DirEntry, WalkDir};
1212

1313
fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
14+
let manifest_path = src_dir.join("Cargo.toml");
1415
assert!(
15-
src_dir.exists(),
16-
"rusty_hermit source folder does not exist"
16+
manifest_path.exists(),
17+
"kernel manifest path `{}` does not exist",
18+
manifest_path.display()
1719
);
18-
let target_arch = env::var_os("CARGO_CFG_TARGET_ARCH").unwrap();
20+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
1921
let profile = env::var("PROFILE").expect("PROFILE was not set");
2022
let mut cmd = Command::new("cargo");
2123

24+
let kernel_triple = match target_arch.as_str() {
25+
"x86_64" => "x86_64-unknown-none-hermitkernel",
26+
"aarch64" => "aarch64-unknown-hermit",
27+
_ => panic!("Unsupported target arch: {}", target_arch),
28+
};
29+
30+
cmd.arg("build")
31+
.arg("-Z")
32+
.arg("build-std=core,alloc")
33+
.arg("--target")
34+
.arg(kernel_triple)
35+
.arg("--manifest-path")
36+
.arg("Cargo.toml");
37+
38+
cmd.current_dir(src_dir);
39+
2240
cmd.env_remove("RUSTUP_TOOLCHAIN");
2341
if option_env!("RUSTC_WORKSPACE_WRAPPER")
2442
.unwrap_or_default()
@@ -29,24 +47,6 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
2947

3048
cmd.env("CARGO_TERM_COLOR", "always");
3149

32-
if target_arch == "x86_64" {
33-
cmd.current_dir(src_dir)
34-
.arg("build")
35-
.arg("-Z")
36-
.arg("build-std=core,alloc")
37-
.arg("--target")
38-
.arg("x86_64-unknown-none-hermitkernel");
39-
} else if target_arch == "aarch64" {
40-
cmd.current_dir(src_dir)
41-
.arg("build")
42-
.arg("-Z")
43-
.arg("build-std=core,alloc")
44-
.arg("--target")
45-
.arg("aarch64-unknown-hermit");
46-
} else {
47-
panic!("Try to build for an unsupported platform");
48-
}
49-
5050
if let Some(target_dir) = target_dir_opt {
5151
cmd.arg("--target-dir").arg(target_dir);
5252
}
@@ -130,21 +130,12 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
130130
let status = cmd.status().expect("failed to start kernel build");
131131
assert!(status.success());
132132

133-
let lib_location = if target_arch == "x86_64" {
134-
target_dir
135-
.join("x86_64-unknown-none-hermitkernel")
136-
.join(&profile)
137-
.canonicalize()
138-
.unwrap() // Must exist after building
139-
} else if target_arch == "aarch64" {
140-
target_dir
141-
.join("aarch64-unknown-hermit")
142-
.join(&profile)
143-
.canonicalize()
144-
.unwrap() // Must exist after building
145-
} else {
146-
panic!("Try to build for an unsupported platform");
147-
};
133+
let lib_location = target_dir
134+
.join(kernel_triple)
135+
.join(&profile)
136+
.canonicalize()
137+
.unwrap();
138+
148139
println!("Lib location: {}", lib_location.display());
149140

150141
let lib = lib_location.join("libhermit.a");

0 commit comments

Comments
 (0)