Skip to content

Name clash with LLVM intrinsics #5

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

Closed
junyucao1024 opened this issue Apr 29, 2025 · 4 comments
Closed

Name clash with LLVM intrinsics #5

junyucao1024 opened this issue Apr 29, 2025 · 4 comments
Labels
bug Something isn't working upstream upstream issue

Comments

@junyucao1024
Copy link
Contributor

junyucao1024 commented Apr 29, 2025

Environment

$ zig version --verbose
0.14.0

$ uname -a 
Darwin MacBook-Air 23.6.0 Darwin Kernel Version 23.6.0; root:xnu-10063.141.2~1/RELEASE_ARM64_T8112 arm64

$ /opt/homebrew/opt/llvm/bin/llvm-config --version
20.1.3

Issue

When running tests in src/llvm.zig, it raises error:

Running test: llvm.zig - all LLVM modules
Command failed: /opt/homebrew/bin/zig test --test-filter all LLVM modules ~/.../llvm-zig/src/llvm.zig
llvm intrinsics cannot be defined!
ptr @"llvm.test.all LLVM modules"
LLVM ERROR: Broken module found, compilation aborted!

Possible reasons and mitigations

I found two similar issues in zig-lang upstream, it's not fixed yet.
ziglang/zig#11525
ziglang/zig#2291

It can be mitigated by change the name of llvm.zig to _llvm.zig.

@junyucao1024
Copy link
Contributor Author

Sorry, I realized it's not a real issue since we don't run tests directly on llvm.zig .

@junyucao1024
Copy link
Contributor Author

My bad, it's an issue and my previous comment is wrong. (I ran a test in my personal folder and build.zig does not set tests correctly).

How to reproduce:
cd to llvm-zig/ folder and run zig build test. Then we get the error.

@kassane kassane added bug Something isn't working upstream upstream issue labels Apr 29, 2025
@kassane
Copy link
Owner

kassane commented Apr 29, 2025

It can be mitigated by change the name of llvm.zig to _llvm.zig.

Although not expected, I think we can make it a patch.
Would you like to send another PR? And help me with CI too? enabling the test in CI with clang-tests.

Expected output
zig build test --summary all
all clang modules (0.00ms)

1 of 1 test passed

Slowest 1 test: 
  0.00ms        all clang modules

all LLVM modules (0.00ms)

1 of 1 test passed

Slowest 1 test: 
  0.00ms        all LLVM modules

Build Summary: 5/5 steps succeeded
test success
└─ run llvm-tests success 480us MaxRSS:2M
   └─ zig test llvm-tests Debug native success 1s MaxRSS:239M
      └─ run clang-tests success 472us MaxRSS:2M
         └─ zig test clang-tests Debug native success 1s MaxRSS:238M
patch suggestion
diff --git a/build.zig b/build.zig
index f3ead38..3f608d7 100644
--- a/build.zig
+++ b/build.zig
@@ -6,7 +6,7 @@ pub fn build(b: *std.Build) !void {
 
     // LLVM MODULE
     const llvm_module = b.addModule("llvm", .{
-        .root_source_file = b.path("src/llvm.zig"),
+        .root_source_file = b.path("src/llvm-bindings.zig"),
         .target = target,
         .optimize = optimize,
     });
@@ -44,7 +44,7 @@ pub fn build(b: *std.Build) !void {
         .optimize = optimize,
     });
     switch (target.result.os.tag) {
-        .linux => clang_module.linkSystemLibrary("clang-19", .{}), // Ubuntu
+        .linux => clang_module.linkSystemLibrary("clang", .{}), // Ubuntu
         .macos => {
             clang_module.addLibraryPath(.{
                 .cwd_relative = "/opt/homebrew/opt/llvm/lib",
@@ -114,23 +114,29 @@ const BuildInfo = struct {
 };
 
 fn buildTests(b: *std.Build, target: std.Build.ResolvedTarget) void {
+    const custom_test_runner: std.Build.Step.Compile.TestRunner = .{
+        .path = b.dependency("test_runner", .{}).path("test_runner.zig"),
+        .mode = .simple,
+    };
+
     const llvm_tests = b.addTest(.{
-        .root_source_file = b.path("src/llvm.zig"),
+        .root_source_file = b.path("src/llvm-bindings.zig"),
         .target = target,
         .optimize = .Debug,
         .name = "llvm-tests",
+        .test_runner = custom_test_runner,
     });
     const clang_tests = b.addTest(.{
         .root_source_file = b.path("src/clang.zig"),
         .target = target,
         .optimize = .Debug,
         .name = "clang-tests",
+        .test_runner = custom_test_runner,
     });
     llvm_tests.root_module.addImport("llvm", b.modules.get("llvm").?);
     clang_tests.root_module.addImport("clang", b.modules.get("clang").?);
 
-    // TODO: CI build LLVM tests with clang
-    // llvm_tests.step.dependOn(&clang_tests.step);
+    llvm_tests.step.dependOn(&b.addRunArtifact(clang_tests).step);
     const run_llvm_tests = b.addRunArtifact(llvm_tests);
     const test_llvm_step = b.step("test", "Run LLVM-binding tests");
     test_llvm_step.dependOn(&run_llvm_tests.step);
diff --git a/build.zig.zon b/build.zig.zon
index 6759d76..34cd624 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,6 +1,12 @@
 .{
     .name = .llvm_zig,
     .version = "1.0.0",
+    .dependencies = .{
+        .test_runner = .{
+            .url = "git+https://gist.github.com/karlseguin/c6bea5b35e4e8d26af6f81c22cb5d76b#1f317ebc9cd09bc50fd5591d09c34255e15d1d85",
+            .hash = "N-V-__8AANwlAADW-4Yu_sYSZkL_6wcz13gOf9pkOLCjct-F",
+        },
+    },
     .minimum_zig_version = "0.14.0",
     .fingerprint = 0xbf48c74bc4247821,
     .paths = .{
diff --git a/src/llvm.zig b/src/llvm.zig
deleted file mode 100644
index aefc818..0000000
--- a/src/llvm.zig
+++ /dev/null
@@ -1,48 +0,0 @@
-pub const analysis = @import("analysis.zig");
-pub const blake3 = @import("blake3.zig");
-pub const bitreader = @import("bitreader.zig");
-pub const bitwriter = @import("bitwriter.zig");
-pub const core = @import("core.zig");
-pub const debug = @import("debuginfo.zig");
-pub const disasm = @import("disassembler.zig");
-pub const engine = @import("executionEngine.zig");
-pub const errors = @import("errors.zig");
-pub const error_handling = @import("error_handling.zig");
-pub const initialization = @import("initialization.zig");
-pub const irreader = @import("irreader.zig");
-pub const linker = @import("linker.zig");
-pub const lto = @import("lto.zig");
-pub const jit = @import("lljit.zig");
-pub const orc = @import("orc.zig");
-pub const orcee = @import("orcee.zig");
-pub const remarks = @import("remarks.zig");
-pub const support = @import("support.zig");
-pub const target = @import("target.zig");
-pub const target_machine = @import("target_machine.zig");
-pub const transform = @import("transform.zig");
-pub const types = @import("types.zig");
-
-test "all LLVM modules" {
-    _ = analysis;
-    _ = blake3;
-    _ = bitreader;
-    _ = bitwriter;
-    _ = core;
-    _ = debug;
-    _ = disasm;
-    _ = engine;
-    _ = errors;
-    _ = error_handling;
-    _ = initialization;
-    _ = irreader;
-    _ = linker;
-    _ = lto;
-    _ = jit;
-    _ = orc;
-    _ = orcee;
-    _ = remarks;
-    _ = support;
-    _ = target;
-    _ = target_machine;
-    _ = transform;
-}

@junyucao1024
Copy link
Contributor Author

Done

@kassane kassane closed this as completed Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream upstream issue
Projects
None yet
Development

No branches or pull requests

2 participants