From acb7767c63a97df8e3e8b04cd2a053763b8e1ecc Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Sat, 7 Oct 2023 17:10:44 +0800 Subject: [PATCH] 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. --- .github/workflows/develop.yml | 9 ++--- build.rs | 67 +++++++---------------------------- 2 files changed, 14 insertions(+), 62 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index abc2d530..48e73cd3 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -159,9 +159,7 @@ jobs: run: make ci-asm windows-x86-ci-asm: - # We must use windows-2019 here, otherwise we will encounter some bugs, for futher details, see - # https://github.com/yasm/yasm/issues/153 - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v3 - name: Install dependencies @@ -169,11 +167,8 @@ jobs: # https://github.com/ScoopInstaller/Install#for-admin run: | iex "& {$(irm get.scoop.sh)} -RunAsAdmin" - scoop install llvm - scoop install yasm + scoop install mingw - name: Run ci-asm shell: pwsh run: | - $env:path="C:\Users\runneradmin\scoop\apps\llvm\current;"+$env:path - $env:path="C:\Users\runneradmin\scoop\apps\yasm\current;"+$env:path make ci-asm diff --git a/build.rs b/build.rs index 8b77ca37..1f7e9e08 100644 --- a/build.rs +++ b/build.rs @@ -8,7 +8,9 @@ fn main() { let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default(); let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); + let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default(); let is_windows = target_family == "windows"; + let is_msvc = is_windows && (target_env == "msvc"); let is_unix = target_family == "unix"; let is_x86_64 = target_arch == "x86_64"; let is_aarch64 = target_arch == "aarch64"; @@ -28,63 +30,18 @@ fn main() { println!("cargo:rerun-if-changed=src/machine/asm/execute_aarch64.S"); println!("cargo:rerun-if-changed=src/machine/asm/cdefinitions_generated.h"); - use cc::Build; - use std::path::Path; - use std::process::Command; + let mut build = cc::Build::new(); - fn run_command(mut c: Command) { - println!("Running Command[{:?}]", c); - - let output = c.output().unwrap_or_else(|e| { - panic!("Error running Command[{:?}], error: {:?}", c, e); - }); - - if !output.status.success() { - use std::io::{self, Write}; - io::stdout() - .write_all(&output.stdout) - .expect("stdout write"); - io::stderr() - .write_all(&output.stderr) - .expect("stderr write"); - - panic!( - "Command[{:?}] exits with non-success status: {:?}", - c, output.status - ); - } - } - - let mut build = Build::new(); - - if is_windows && x64_asm { - let out_dir = env::var("OUT_DIR").unwrap(); - let expand_path = Path::new(&out_dir).join("execute_x64-expanded.S"); - let mut expand_command = Command::new("clang"); - expand_command - .arg("-E") - .arg("src/machine/asm/execute_x64.S") - .arg("-o") - .arg(&expand_path); - run_command(expand_command); - - let compile_path = Path::new(&out_dir).join("execute_x64.o"); - let mut compile_command = Command::new("yasm"); - compile_command - .arg("-p") - .arg("gas") - .arg("-f") - .arg("x64") - .arg("-m") - .arg("amd64") - .arg(&expand_path) - .arg("-o") - .arg(&compile_path); - run_command(compile_command); - - build.object(&compile_path); - } else if x64_asm { + if x64_asm { build.file("src/machine/asm/execute_x64.S"); + if is_msvc { + // For now, only an assembly source code is required for CKB-VM, we won't + // need to build any C source file here. Hence we can use this simpler solution + // to set the default compiler to GCC. We will need to manually trigger the + // command to assemble the assembly code file, should any C source file is also + // required here. + build.compiler("gcc"); + } } else if aarch64_asm { build.file("src/machine/asm/execute_aarch64.S"); }