8000 fix: Zig build and tests by roninjin10 · Pull Request #1720 · evmts/tevm-monorepo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Zig build and tests #1720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ runs:
with:
components: rustfmt, clippy

- name: Install cbindgen
run: |
cargo install --locked cbindgen
shell: bash

- name: Install dependencies
run: pnpm install --frozen-lockfile
shell: bash
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ jobs:
- name: Initialize the Nx Cloud distributed CI run and stop agents when the build tasks are done
run: bunx nx-cloud start-ci-run --stop-agents-after=build:app --stop-agents-on-failure=false

- name: Build Zig and WASM
- name: Build Rust Zig and WASM
run: |
cargo build &&
zig build &&
zig build wasm && echo "WASM size: $(ls -lh ./dist/zigevm.wasm | awk '{print $5}')"

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ zig-cache/
TODO.md

**/.claude/settings.local.json

g/
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ members = [

[profile.release]
lto = true
panic = "abort"
11 changes: 11 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ pub fn build(b: *std.Build) void {

// Add dependencies to compiler_test
compiler_test.root_module.addImport("Compiler", compiler_mod);
compiler_test.root_module.addImport("zabi", zabi_dep.module("zabi"));
compiler_test.root_module.addIncludePath(b.path("src/Compilers"));

const run_compiler_test = b.addRunArtifact(compiler_test);

Expand Down Expand Up @@ -385,6 +387,15 @@ pub fn build(b: *std.Build) void {

// Make the compiler test depend on the Rust build
compiler_test.step.dependOn(rust_step);

// Link the Rust library to the compiler test
compiler_test.addObjectFile(b.path("dist/target/release/libfoundry_wrapper.a"));

// Link macOS frameworks if on macOS
if (target.result.os.tag == .macos) {
compiler_test.linkFramework("CoreFoundation");
compiler_test.linkFramework("Security");
}
Comment on lines 389 to +398
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify Rust library path and consider build automation.

The Rust integration setup looks correct, but consider the following:

  1. The hardcoded path "dist/target/rel 9E7A ease/libfoundry_wrapper.a" assumes a specific build location
  2. The macOS framework dependencies are properly conditional

Consider verifying that the Rust build step actually produces the library at the expected path:


🏁 Script executed:

#!/bin/bash
# Verify the Rust static library exists at the expected location
if [ -f "dist/target/release/libfoundry_wrapper.a" ]; then
    echo "✓ Rust library found at expected path"
    ls -la "dist/target/release/libfoundry_wrapper.a"
else
    echo "✗ Rust library not found at dist/target/release/libfoundry_wrapper.a"
    echo "Searching for libfoundry_wrapper.a in the repository:"
    fd "libfoundry_wrapper.a"
fi

Length of output: 343


🏁 Script executed:

#!/bin/bash
# Locate the Rust build step and inspect its output configuration
rg -n "rust_step" -C 5 build.zig

# Search for any references to "foundry_wrapper" to find the actual artifact name or path
rg -n "foundry_wrapper" -C 3

Length of output: 3749


Ensure Rust library output and path alignment
The build is configured to emit the Rust artifact into dist/target/release/libfoundry_wrapper.a via the rust_build step, but we should guard against mismatches between the actual crate output and where it’s being linked:

  • Verify in src/Compilers/Cargo.toml that you’ve declared
    [lib]
    crate-type = ["staticlib"]
    so Cargo produces a .a archive rather than an .rlib.
  • Rather than hard-coding the string "dist/target/release/libfoundry_wrapper.a" in build.zig, pull in the same rust_lib_path you define in rust_build.zig (e.g. export it or return it from addRustIntegration) to avoid drift.
  • Optionally factor out the dist/target directory and crate name into shared constants so both your Rust step and Zig linker invocation stay in sync.
🤖 Prompt for AI Agents
In build.zig around lines 389 to 398, the Rust static library path is hardcoded
as "dist/target/release/libfoundry_wrapper.a", which risks mismatches if the
Rust build output changes. To fix this, verify that Cargo.toml in src/Compilers
declares the library as a staticlib to produce a .a file. Then, refactor
build.zig to avoid hardcoding the path by importing or returning the Rust
library path from the rust_build step or addRustIntegration function, and use
shared constants for the output directory and crate name to keep the Rust build
output and Zig linker input in sync.


const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

Expand Down
1 change: 1 addition & 0 deletions ethereumjs-monorepo
Submodule ethereumjs-monorepo added at ee42ec
1 change: 1 addition & 0 deletions g/compilers
Submodule compilers added at bc42af
246 changes: 7 additions & 239 deletions src/Abi/abi.zig
Original file line number Diff line number Diff line change
@@ -1,243 +1,11 @@
// Placeholder ABI module
// The actual ABI implementation is in g/compilers/src/Abi/
const std = @import("std");

/// State mutability of functions and constructors
pub const StateMutability = enum {
Pure,
View,
NonPayable,
Payable,
pub const AbiError = error{
InvalidInput,
};

/// Represents Solidity internal types
pub const InternalType = union(enum) {
AddressPayable: []const u8,
Contract: []const u8,
Enum: struct {
contract: ?[]const u8,
ty: []const u8,
},
Struct: struct {
contract: ?[]const u8,
ty: []const u8,
},
Other: struct {
contract: ?[]const u8,
ty: []const u8,
},
};

/// ABI parameter for inputs and outputs
pub const Param = struct {
ty: []const u8,
name: []const u8,
components: []Param,
internal_type: ?InternalType,
};

/// ABI event parameter (with indexing)
pub const EventParam = struct {
ty: []const u8,
name: []const u8,
indexed: bool,
components: []Param,
internal_type: ?InternalType,
};

/// Constructor ABI item
pub const Constructor = struct {
inputs: []Param,
state_mutability: StateMutability,
};

/// Function ABI item
pub const Function = struct {
name: []const u8,
inputs: []Param,
outputs: []Param,
state_mutability: StateMutability,
};

/// Event ABI item
pub const Event = struct {
name: []const u8,
inputs: []EventParam,
anonymous: bool,
};

/// Error ABI item
pub const Error = struct {
name: []const u8,
inputs: []Param,
};

/// Fallback ABI item
pub const Fallback = struct {
state_mutability: StateMutability,
};

/// Receive ABI item
pub const Receive = struct {
state_mutability: StateMutability,
};

/// Union of all ABI items
pub const AbiItem = union(enum) {
Constructor: Constructor,
Fallback: Fallback,
Receive: Receive,
Function: Function,
Event: Event,
Error: Error,
};

/// JSON ABI representation
pub const JsonAbi = struct {
constructor: ?Constructor = null,
fallback: ?Fallback = null,
receive: ?Receive = null,
functions: std.StringHashMap([]Function),
events: std.StringHashMap([]Event),
errors: std.StringHashMap([]Error),

/// Initialize an empty ABI
pub fn init(_: *std.mem.Allocator) !JsonAbi {
unreachable;
}

/// Insert a single item into the ABI
pub fn insertItem(_: *JsonAbi, _: AbiItem) void {
unreachable;
}

/// Parse human-readable ABI at compile time
pub fn parseHumanReadable(comptime _: [][]const u8) JsonAbi {
unreachable;
}

/// Parse human-readable ABI at runtime
pub fn parseHumanReadableRuntime(
_: *std.mem.Allocator,
_: [][]const u8,
) !JsonAbi {
unreachable;
}

/// Parse JSON ABI blob
pub fn parseJSON(
_: *std.mem.Allocator,
_: []const u8,
) !JsonAbi {
unreachable;
}

/// Load from reader (e.g., file)
pub fn loadFromReader(
_: *std.mem.Allocator,
_: anytype,
) !JsonAbi {
unreachable;
}

/// Number of items in the ABI
pub fn len(_: *const JsonAbi) usize {
unreachable;
}

/// True if no items
pub fn isEmpty(_: *const JsonAbi) bool {
unreachable;
}

/// Remove duplicate functions, events, errors
pub fn dedup(_: *JsonAbi) void {
unreachable;
}

/// Iterate over items (immutable)
pub fn items(_: *const JsonAbi) Items {
unreachable;
}

/// Consume and iterate over items
pub fn intoItems(_: JsonAbi) IntoItems {
unreachable;
}

/// Render as Solidity interface source
pub fn toSol(
_: *const JsonAbi,
_: *std.mem.Allocator,
_: []const u8,
_: ToSolConfig,
) ![]u8 {
unreachable;
}

/// Render into provided buffer
pub fn toSolRaw(
_: *const JsonAbi,
_: []u8,
_: []const u8,
_: ToSolConfig,
) void {
unreachable;
}
};

/// Iterator type over JsonAbi items
pub const Items = struct {
// fields omitted

pub fn next(self: *Items) ?AbiItem {
unreachable;
}
};

/// Consuming iterator type over JsonAbi items
pub const IntoItems = struct {
// fields omitted

pub fn next(self: *IntoItems) ?AbiItem {
unreachable;
}
};

/// Contract artifact (ABI + bytecodes)
pub const ContractObject = struct {
abi: ?JsonAbi,
bytecode: ?[]u8,
deployed_bytecode: ?[]u8,

/// Initialize empty
pub fn init(allocator: *std.mem.Allocator) !ContractObject {
unreachable;
}

/// Parse from JSON with optional unlinked bytecode
pub fn parseJSON(
s: []const u8,
ignore_unlinked_bytecode: bool,
) !ContractObject {
unreachable;
}
};

/// Configuration for solidity rendering
pub const ToSolConfig = struct {
print_constructors: bool = false,
enums_as_udvt: bool = true,
for_sol_macro: bool = false,
one_contract: bool = false,
};

/// Compute Keccak-256 hash
pub fn keccak256(data: []const u8) [32]u8 {
unreachable; AAC9
}

/// Compute 4-byte selector
pub fn computeSelector(preimage: []const u8) [4]u8 {
unreachable;
}


test {
std.testing.refAllDeclsRecursive(@This());
}
Comment on lines +1 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify that no other modules depend on the removed ABI implementation.

This placeholder module removes all ABI functionality that was previously available. This could break other parts of the codebase that import this module.

Run the following script to check for dependencies on this module:


🏁 Script executed:

#!/bin/bash
# Description: Check for imports of the ABI module that might be broken by this change

# Search for imports of the ABI module
echo "=== Searching for imports of Abi modules ==="
rg -t zig "@import.*Abi" --glob '!src/Abi/*' --glob '!g/*'

# Search for usage of ABI types that were previously exported
echo -e "\n=== Searching for usage of ABI types ==="
rg -t zig "(JsonAbi|AbiItem|Function|Event|Constructor|StateMutability)" --glob '!src/Abi/*' --glob '!g/*'

# Check if any files reference AbiError specifically
echo -e "\n=== Searching for AbiError usage ==="
rg -t zig "AbiError" --glob '!src/Abi/*' --glob '!g/*'

Length of output: 1344


Update broken import in eip712.zig

The only external dependency on src/Abi is in src/Signature/eip712.zig, which still does:

const struct_type = @import("../Abi/struct_type.zig");

Since all ABI logic now lives under g/compilers/src/Abi/, this import will fail. Please update it (for example, point it to g/compilers/src/Abi/struct_type.zig or introduce a re-export).

No other imports of the old src/Abi module or uses of JsonAbi, AbiItem, Function, Event, Constructor, StateMutability, or AbiError were found outside src/Abi.

🤖 Prompt for AI Agents
In src/Abi/abi.zig lines 1 to 11, the placeholder ABI module removes all
previous ABI functionality, which breaks imports in src/Signature/eip712.zig
that reference src/Abi/struct_type.zig. To fix this, update the import in
src/Signature/eip712.zig to point to the new location at
g/compilers/src/Abi/struct_type.zig or create a re-export in src/Abi to forward
the necessary modules from the new location, ensuring the import paths remain
valid and ABI functionality is accessible.

Loading
Loading
0