Skip to content

Commit 3baab79

Browse files
committed
Add a macro for switching the target architecture of Docker
This makes it a bit easier to test with an x86_64 Docker image on an aarch64 host.
1 parent 9211605 commit 3baab79

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

compiler/base/orchestrator/src/coordinator.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,11 +1191,24 @@ macro_rules! docker_command {
11911191
});
11921192
}
11931193

1194-
#[cfg(target_arch = "x86_64")]
1195-
const DOCKER_ARCH: &str = "linux/amd64";
1194+
macro_rules! docker_target_arch {
1195+
(x86_64: $x:expr, aarch64: $a:expr $(,)?) => {{
1196+
#[cfg(target_arch = "x86_64")]
1197+
{
1198+
$x
1199+
}
11961200

1197-
#[cfg(target_arch = "aarch64")]
1198-
const DOCKER_ARCH: &str = "linux/arm64";
1201+
#[cfg(target_arch = "aarch64")]
1202+
{
1203+
$a
1204+
}
1205+
}};
1206+
}
1207+
1208+
const DOCKER_ARCH: &str = docker_target_arch! {
1209+
x86_64: "linux/amd64",
1210+
aarch64: "linux/arm64",
1211+
};
11991212

12001213
fn basic_secure_docker_command() -> Command {
12011214
docker_command!(
@@ -1765,11 +1778,10 @@ mod tests {
17651778

17661779
let response = coordinator.compile(req).with_timeout().await.unwrap();
17671780

1768-
#[cfg(target_arch = "x86_64")]
1769-
let asm = "eax, [rsi + rdi]";
1770-
1771-
#[cfg(target_arch = "aarch64")]
1772-
let asm = "w0, w1, w0";
1781+
let asm = docker_target_arch! {
1782+
x86_64: "eax, [rsi + rdi]",
1783+
aarch64: "w0, w1, w0",
1784+
};
17731785

17741786
assert!(response.success, "stderr: {}", response.stderr);
17751787
assert_contains!(response.code, asm);

0 commit comments

Comments
 (0)