Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ jobs:
linux-arm64:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo test --features=asm --release

linux-x64:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo test --features=asm --release

macos-arm64:
runs-on: macos-15
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo test --features=asm --release

macos-x64:
runs-on: macos-15-intel
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo test --features=asm --release

qemu-arm64:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Setup
run: |
sudo apt-get update -y
Expand All @@ -58,7 +58,7 @@ jobs:
qemu-riscv64:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Setup
run: |
sudo apt-get update -y
Expand All @@ -75,21 +75,21 @@ jobs:
windows-x64:
runs-on: windows-2025
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Setup
shell: pwsh
# https://github.com/ScoopInstaller/Install#for-admin
run: |
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
scoop install mingw
scoop install llvm
- name: Build
shell: pwsh
run: cargo test --features=asm --release

misc:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
# https://github.com/EmbarkStudios/cargo-deny-action
- uses: EmbarkStudios/cargo-deny-action@v2
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ derive_more = { version = "1", features = ["full"] }

[build-dependencies]
cc = "1.0"
clang-finder = "0.1"

[dev-dependencies]
argparse = "0.2"
Expand Down
91 changes: 40 additions & 51 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,50 @@
// have to keep features always on, and do conditional compilation within the
// source code

fn main() {
use std::env;
use std::env;

let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default();
fn main() {
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 target = env::var("TARGET").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";
let is_riscv64 = target_arch == "riscv64";
let x64_asm = is_x86_64 && (is_windows || is_unix);
let aarch64_asm = is_aarch64 && is_unix;
// toolchain on sp1 has empty target_family
let riscv64_asm = is_riscv64 && (is_unix || target_family.is_empty());
let can_enable_asm = x64_asm || aarch64_asm || riscv64_asm;

if cfg!(feature = "asm") && (!can_enable_asm) {
panic!(
"Asm feature is not available for target {} on {}!",
target_arch, target_family
);
let support_asm = vec!["aarch64", "riscv64", "x86_64"].contains(&target_arch.as_str());
if !support_asm {
if cfg!(feature = "asm") {
panic!("Asm is not available for {}!", target_arch);
}
return;
}
let request_asm = cfg!(feature = "asm") || cfg!(feature = "detect-asm");
if !request_asm {
return;
}

if cfg!(any(feature = "asm", feature = "detect-asm")) && can_enable_asm {
println!("cargo:rerun-if-changed=src/machine/asm/execute_x64.S");
println!("cargo:rerun-if-changed=src/machine/asm/execute_aarch64.S");
println!("cargo:rerun-if-changed=src/machine/asm/execute_riscv64.S");
println!("cargo:rerun-if-changed=src/machine/asm/cdefinitions_generated.h");

let mut build = cc::Build::new();

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");
} else if riscv64_asm {
if target.contains("zkvm") || target.contains("succinct") {
build.compiler("riscv64-linux-gnu-gcc");
}
build.file("src/machine/asm/execute_riscv64.S");
println!("cargo:rustc-cfg=has_asm");
println!("cargo:rerun-if-changed=src/machine/asm/execute_x64.S");
println!("cargo:rerun-if-changed=src/machine/asm/execute_aarch64.S");
println!("cargo:rerun-if-changed=src/machine/asm/execute_riscv64.S");
println!("cargo:rerun-if-changed=src/machine/asm/cdefinitions_generated.h");

match target_arch.as_str() {
"aarch64" => {
cc::Build::new()
.compiler(clang_finder::find())
.include("src/machine/asm")
.file("src/machine/asm/execute_aarch64.S")
.compile("asm");
}

build.include("src/machine/asm").compile("asm");

println!("cargo:rustc-cfg=has_asm")
"riscv64" => {
cc::Build::new()
.compiler(clang_finder::find())
Copy link
Copy Markdown
Contributor

@eval-exec eval-exec Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure do we really need to hardcode clang and ignore CC env var here?
cc-rs allow cargo usage like: CC=clang cargo build .....

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, perhaps we don't need to specify compiler.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, if we do this, we will always need to set the CC environment variable when compiling on Windows, see https://github.com/nervosnetwork/ckb-vm/actions/runs/24328961143/job/71030179557?pr=512

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we do it the old way: not specifying a compiler on Unix, but specifying a compiler on Windows?

Copy link
Copy Markdown
Contributor

@eval-exec eval-exec Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about create .cargo/Cargo.toml, config CC=clang in [env]?
https://doc.rust-lang.org/cargo/reference/config.html#env

Or should we do it the old way: not specifying a compiler on Unix, but specifying a compiler on Windows?

Both are fine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good idea. On Windows, clang is simply called clang, but on Unix, clang is usually named clang-19, clang-20, clang-21, and so on. This is why I initially introduced the clang-finder package.

Copy link
Copy Markdown
Contributor

@eval-exec eval-exec Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc-rs support: <var>_<target> - for example:

  • CC_x86_64_pc_windows_msvc
  • CC_x86_64_unknown_linux_gnu

https://docs.rs/cc/latest/cc/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ckb-vm have min/max version requirements for clang?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no restrictions on clang versions.

.include("src/machine/asm")
.file("src/machine/asm/execute_riscv64.S")
.compile("asm");
}
"x86_64" => {
cc::Build::new()
.compiler(clang_finder::find())
.include("src/machine/asm")
.file("src/machine/asm/execute_x64.S")
.compile("asm");
}
_ => {}
}
}
Loading