Skip to content

Commit eee3999

Browse files
committed
feat: add aarch64-hyperlight-none target support
- Add aarch64-hyperlight-none target spec derived from aarch64-unknown-none with hyperlight customizations - Select correct musl arch headers (aarch64 vs x86_64) - Use appropriate clang --target for aarch64 - Make -mno-red-zone x86_64-only (aarch64 has no red zone) - Fix get_spec to pass --target as CLI arg instead of env var Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 2723f3b commit eee3999

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

src/sysroot.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,27 @@ pub fn build(args: &Args) -> Result<()> {
4545
spec.remove("rustc-abi");
4646
spec
4747
}
48+
"aarch64-hyperlight-none" => {
49+
let mut spec = get_spec(args, "aarch64-unknown-none")?;
50+
let Value::Object(custom) = json!({
51+
"code-model": "small",
52+
"linker": "rust-lld",
53+
"linker-flavor": "gnu-lld",
54+
"pre-link-args": {
55+
"gnu-lld": ["-znostart-stop-gc"],
56+
},
57+
}) else {
58+
unreachable!()
59+
};
60+
spec.extend(custom);
61+
spec.remove("rustc-abi");
62+
spec
63+
}
4864
triplet => bail!(
4965
"Unsupported target triple: {triplet:?}
5066
Supported values are:
51-
* x86_64-hyperlight-none"
67+
* x86_64-hyperlight-none
68+
* aarch64-hyperlight-none"
5269
),
5370
};
5471

@@ -180,7 +197,8 @@ fn get_spec(args: &Args, triplet: impl AsRef<str>) -> Result<Map<String, Value>>
180197
.envs(args.env.iter())
181198
.current_dir(&args.current_dir)
182199
.arg("rustc")
183-
.target(triplet)
200+
.arg("--target")
201+
.arg(triplet.as_ref())
184202
.manifest_path(&args.manifest_path)
185203
.arg("-Zunstable-options")
186204
.arg("--print=target-spec-json")

src/toolchain.rs

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,47 +53,52 @@ pub fn prepare(args: &Args) -> Result<()> {
5353
std::fs::create_dir_all(&include_dst_dir)
5454
.context("Failed to create sysroot include directory")?;
5555

56-
const INCLUDE_DIRS: &[&str] = &[
57-
"third_party/printf/",
58-
"third_party/musl/include",
59-
"third_party/musl/arch/generic",
60-
"third_party/musl/arch/x86_64",
61-
"third_party/musl/src/internal",
62-
];
63-
64-
for dir in INCLUDE_DIRS {
65-
let include_src_dir = hyperlight_guest_bin_dir.join(dir);
66-
let files = glob::glob(&format!("{}/**/*.h", include_src_dir.display()))
67-
.context("Failed to read include source directory")?;
68-
69-
for file in files {
70-
let src = file.context("Failed to read include source file")?;
71-
let dst = src.strip_prefix(&include_src_dir).unwrap();
72-
let dst = include_dst_dir.join(dst);
73-
74-
std::fs::create_dir_all(dst.parent().unwrap())
75-
.context("Failed to create include subdirectory")?;
76-
std::fs::copy(&src, &dst).context("Failed to copy include file")?;
56+
// Skip musl header copying on aarch64 — no musl/C support yet
57+
if !args.target.starts_with("aarch64") {
58+
let include_dirs: &[&str] = &[
59+
"third_party/printf/",
60+
"third_party/musl/include",
61+
"third_party/musl/arch/generic",
62+
"third_party/musl/arch/x86_64",
63+
"third_party/musl/src/internal",
64+
];
65+
66+
for dir in include_dirs {
67+
let include_src_dir = hyperlight_guest_bin_dir.join(dir);
68+
let files = glob::glob(&format!("{}/**/*.h", include_src_dir.display()))
69+
.context("Failed to read include source directory")?;
70+
71+
for file in files {
72+
let src = file.context("Failed to read include source file")?;
73+
let dst = src.strip_prefix(&include_src_dir).unwrap();
74+
let dst = include_dst_dir.join(dst);
75+
76+
std::fs::create_dir_all(dst.parent().unwrap())
77+
.context("Failed to create include subdirectory")?;
78+
std::fs::copy(&src, &dst).context("Failed to copy include file")?;
79+
}
7780
}
7881
}
7982

8083
Ok(())
8184
}
8285

8386
pub fn cflags(args: &Args) -> OsString {
84-
const FLAGS: &[&str] = &[
85-
// terrible hack, see
86-
// https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_guest_bin/build.rs#L80
87-
"--target=x86_64-unknown-linux-none",
87+
let clang_target = if args.target.starts_with("aarch64") {
88+
"--target=aarch64-unknown-linux-none"
89+
} else {
90+
"--target=x86_64-unknown-linux-none"
91+
};
92+
93+
let common_flags: &[&str] = &[
94+
clang_target,
8895
"-U__linux__",
89-
// Our rust target also has this set since it based off "x86_64-unknown-none"
9096
"-fPIC",
9197
// We don't support stack protectors at the moment, but Arch Linux clang
9298
// auto-enables them for -linux platforms, so explicitly disable them.
9399
"-fno-stack-protector",
94100
"-fstack-clash-protection",
95101
"-mstack-probe-size=4096",
96-
"-mno-red-zone",
97102
"-nostdinc",
98103
// Define HYPERLIGHT as we use this to conditionally enable/disable code
99104
// in the libc headers
@@ -102,10 +107,15 @@ pub fn cflags(args: &Args) -> OsString {
102107
];
103108

104109
let mut flags = OsString::new();
105-
for flag in FLAGS {
110+
for flag in common_flags {
106111
flags.push(flag);
107112
flags.push(" ");
108113
}
114+
115+
// x86_64-specific flags
116+
if args.target.starts_with("x86_64") {
117+
flags.push("-mno-red-zone ");
118+
}
109119
flags.push(" ");
110120
flags.push("-isystem");
111121
flags.push(" ");

0 commit comments

Comments
 (0)