Skip to content

Commit acb7767

Browse files
authored
chore: Use as provided by mingw on Windows (#387)
Previously, we were using clang (as a preprocessor) & yasm to transform assembly source code on Windows. On the one hand, this is really a hack solution to build a GAS-coupled assembly source file, on the other hand, yasm hasn't seen a proper release in years, making us believe that yasm is slowly becoming unmaintained. This change switches to use mingw when building the assembly source code, mingw is actively maintained now, which will reduce any problems we might run into. Note that we only activate the new logic when target environment is `msvc`, for `x86_64-pc-windows-gnu` target, current logic would already work flawlessly.
1 parent 5a29e43 commit acb7767

File tree

2 files changed

+14
-62
lines changed

2 files changed

+14
-62
lines changed

.github/workflows/develop.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,16 @@ jobs:
159159
run: make ci-asm
160160

161161
windows-x86-ci-asm:
162-
# We must use windows-2019 here, otherwise we will encounter some bugs, for futher details, see
163-
# https://github.com/yasm/yasm/issues/153
164-
runs-on: windows-2019
162+
runs-on: windows-latest
165163
steps:
166164
- uses: actions/checkout@v3
167165
- name: Install dependencies
168166
shell: pwsh
169167
# https://github.com/ScoopInstaller/Install#for-admin
170168
run: |
171169
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
172-
scoop install llvm
173-
scoop install yasm
170+
scoop install mingw
174171
- name: Run ci-asm
175172
shell: pwsh
176173
run: |
177-
$env:path="C:\Users\runneradmin\scoop\apps\llvm\current;"+$env:path
178-
$env:path="C:\Users\runneradmin\scoop\apps\yasm\current;"+$env:path
179174
make ci-asm

build.rs

+12-55
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ fn main() {
88

99
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
1010
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
11+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
1112
let is_windows = target_family == "windows";
13+
let is_msvc = is_windows && (target_env == "msvc");
1214
let is_unix = target_family == "unix";
1315
let is_x86_64 = target_arch == "x86_64";
1416
let is_aarch64 = target_arch == "aarch64";
@@ -28,63 +30,18 @@ fn main() {
2830
println!("cargo:rerun-if-changed=src/machine/asm/execute_aarch64.S");
2931
println!("cargo:rerun-if-changed=src/machine/asm/cdefinitions_generated.h");
3032

31-
use cc::Build;
32-
use std::path::Path;
33-
use std::process::Command;
33+
let mut build = cc::Build::new();
3434

35-
fn run_command(mut c: Command) {
36-
println!("Running Command[{:?}]", c);
37-
38-
let output = c.output().unwrap_or_else(|e| {
39-
panic!("Error running Command[{:?}], error: {:?}", c, e);
40-
});
41-
42-
if !output.status.success() {
43-
use std::io::{self, Write};
44-
io::stdout()
45-
.write_all(&output.stdout)
46-
.expect("stdout write");
47-
io::stderr()
48-
.write_all(&output.stderr)
49-
.expect("stderr write");
50-
51-
panic!(
52-
"Command[{:?}] exits with non-success status: {:?}",
53-
c, output.status
54-
);
55-
}
56-
}
57-
58-
let mut build = Build::new();
59-
60-
if is_windows && x64_asm {
61-
let out_dir = env::var("OUT_DIR").unwrap();
62-
let expand_path = Path::new(&out_dir).join("execute_x64-expanded.S");
63-
let mut expand_command = Command::new("clang");
64-
expand_command
65-
.arg("-E")
66-
.arg("src/machine/asm/execute_x64.S")
67-
.arg("-o")
68-
.arg(&expand_path);
69-
run_command(expand_command);
70-
71-
let compile_path = Path::new(&out_dir).join("execute_x64.o");
72-
let mut compile_command = Command::new("yasm");
73-
compile_command
74-
.arg("-p")
75-
.arg("gas")
76-
.arg("-f")
77-
.arg("x64")
78-
.arg("-m")
79-
.arg("amd64")
80-
.arg(&expand_path)
81-
.arg("-o")
82-
.arg(&compile_path);
83-
run_command(compile_command);
84-
85-
build.object(&compile_path);
86-
} else if x64_asm {
35+
if x64_asm {
8736
build.file("src/machine/asm/execute_x64.S");
37+
if is_msvc {
38+
// For now, only an assembly source code is required for CKB-VM, we won't
39+
// need to build any C source file here. Hence we can use this simpler solution
40+
// to set the default compiler to GCC. We will need to manually trigger the
41+
// command to assemble the assembly code file, should any C source file is also
42+
// required here.
43+
build.compiler("gcc");
44+
}
8845
} else if aarch64_asm {
8946
build.file("src/machine/asm/execute_aarch64.S");
9047
}

0 commit comments

Comments
 (0)