| author | |
| committer | |
| log | 39c0d8bd2c2bd048da6ea1821c6c46aa60fa2907 |
| tree | 8dd79b588a3b7a20a8589a4fd08a11881a8ff35c |
| parent | 33889e1974137a54d1a88b87f57462de2a7cc145 |
| parent | 08c768ad82280463410eacc5b7f19389cb1ba49b |
| signature |
build: workaround link error with LTO and mingw6 files changed, 104 insertions(+), 8 deletions(-)
src/mingw.zig+6| ... | ... | @@ -92,6 +92,12 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 92 | 92 | "-D_WIN32_WINNT=0x0f00", |
| 93 | 93 | "-D__MSVCRT_VERSION__=0x700", |
| 94 | 94 | }); |
| 95 | if (std.mem.eql(u8, dep, "tlssup.c") and comp.bin_file.options.lto) { | |
| 96 | // LLD will incorrectly drop the `_tls_index` symbol. Here we work | |
| 97 | // around it by not using LTO for this one file. | |
| 98 | // https://github.com/ziglang/zig/issues/8531 | |
| 99 | try args.append("-fno-lto"); | |
| 100 | } | |
| 95 | 101 | c_source_files[i] = .{ |
| 96 | 102 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 97 | 103 | "libc", "mingw", "crt", dep, |
test/standalone.zig+26-4| ... | ... | @@ -13,12 +13,27 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 13 | 13 | cases.addBuildFile("test/standalone/main_pkg_path/build.zig", .{}); |
| 14 | 14 | cases.addBuildFile("test/standalone/shared_library/build.zig", .{}); |
| 15 | 15 | cases.addBuildFile("test/standalone/mix_o_files/build.zig", .{}); |
| 16 | if (builtin.os.tag == .macos) { | |
| 17 | // Zig's macOS linker does not yet support LTO for LLVM IR files: | |
| 18 | // https://github.com/ziglang/zig/issues/8680 | |
| 19 | cases.addBuildFile("test/standalone/mix_c_files/build.zig", .{ | |
| 20 | .build_modes = false, | |
| 21 | .cross_targets = true, | |
| 22 | }); | |
| 23 | } else { | |
| 24 | cases.addBuildFile("test/standalone/mix_c_files/build.zig", .{ | |
| 25 | .build_modes = true, | |
| 26 | .cross_targets = true, | |
| 27 | }); | |
| 28 | } | |
| 16 | 29 | cases.addBuildFile("test/standalone/global_linkage/build.zig", .{}); |
| 17 | 30 | cases.addBuildFile("test/standalone/static_c_lib/build.zig", .{}); |
| 18 | 31 | cases.addBuildFile("test/standalone/link_interdependent_static_c_libs/build.zig", .{}); |
| 19 | 32 | cases.addBuildFile("test/standalone/link_static_lib_as_system_lib/build.zig", .{}); |
| 20 | 33 | cases.addBuildFile("test/standalone/link_common_symbols/build.zig", .{}); |
| 21 | cases.addBuildFile("test/standalone/link_frameworks/build.zig", .{ .requires_macos_sdk = true }); | |
| 34 | cases.addBuildFile("test/standalone/link_frameworks/build.zig", .{ | |
| 35 | .requires_macos_sdk = true, | |
| 36 | }); | |
| 22 | 37 | cases.addBuildFile("test/standalone/issue_339/build.zig", .{}); |
| 23 | 38 | cases.addBuildFile("test/standalone/issue_8550/build.zig", .{}); |
| 24 | 39 | cases.addBuildFile("test/standalone/issue_794/build.zig", .{}); |
| ... | ... | @@ -33,10 +48,14 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 33 | 48 | if (builtin.os.tag != .wasi) { |
| 34 | 49 | cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{}); |
| 35 | 50 | } |
| 36 | if (builtin.cpu.arch == .x86_64) { // TODO add C ABI support for other architectures | |
| 51 | // C ABI compatibility issue: https://github.com/ziglang/zig/issues/1481 | |
| 52 | if (builtin.cpu.arch == .x86_64) { | |
| 37 | 53 | cases.addBuildFile("test/stage1/c_abi/build.zig", .{}); |
| 38 | 54 | } |
| 39 | cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ .build_modes = true, .cross_targets = true }); | |
| 55 | cases.addBuildFile("test/standalone/c_compiler/build.zig", .{ | |
| 56 | .build_modes = true, | |
| 57 | .cross_targets = true, | |
| 58 | }); | |
| 40 | 59 | |
| 41 | 60 | if (builtin.os.tag == .windows) { |
| 42 | 61 | cases.addC("test/standalone/issue_9402/main.zig"); |
| ... | ... | @@ -46,7 +65,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 46 | 65 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); |
| 47 | 66 | } |
| 48 | 67 | // Try to build and run an Objective-C executable. |
| 49 | cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true, .requires_macos_sdk = true }); | |
| 68 | cases.addBuildFile("test/standalone/objc/build.zig", .{ | |
| 69 | .build_modes = true, | |
| 70 | .requires_macos_sdk = true, | |
| 71 | }); | |
| 50 | 72 | |
| 51 | 73 | // Ensure the development tools are buildable. |
| 52 | 74 | cases.add("tools/gen_spirv_spec.zig"); |
test/standalone/c_compiler/build.zig+2-4| ... | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | 3 | const Builder = std.build.Builder; |
| 4 | 4 | const CrossTarget = std.zig.CrossTarget; |
| 5 | 5 | |
| 6 | // TODO integrate this with the std.build executor API | |
| 6 | 7 | fn isRunnableTarget(t: CrossTarget) bool { |
| 7 | 8 | if (t.isNative()) return true; |
| 8 | 9 | |
| ... | ... | @@ -30,12 +31,9 @@ pub fn build(b: *Builder) void { |
| 30 | 31 | exe_cpp.setTarget(target); |
| 31 | 32 | exe_cpp.linkSystemLibrary("c++"); |
| 32 | 33 | |
| 33 | // disable broken LTO links: | |
| 34 | 34 | switch (target.getOsTag()) { |
| 35 | .windows => { | |
| 36 | exe_cpp.want_lto = false; | |
| 37 | }, | |
| 38 | 35 | .macos => { |
| 36 | // https://github.com/ziglang/zig/issues/8680 | |
| 39 | 37 | exe_cpp.want_lto = false; |
| 40 | 38 | exe_c.want_lto = false; |
| 41 | 39 | }, |
test/standalone/mix_c_files/build.zig created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const Builder = std.build.Builder; | |
| 4 | const CrossTarget = std.zig.CrossTarget; | |
| 5 | ||
| 6 | // TODO integrate this with the std.build executor API | |
| 7 | fn isRunnableTarget(t: CrossTarget) bool { | |
| 8 | if (t.isNative()) return true; | |
| 9 | ||
| 10 | return (t.getOsTag() == builtin.os.tag and | |
| 11 | t.getCpuArch() == builtin.cpu.arch); | |
| 12 | } | |
| 13 | ||
| 14 | pub fn build(b: *Builder) void { | |
| 15 | const mode = b.standardReleaseOptions(); | |
| 16 | const target = b.standardTargetOptions(.{}); | |
| 17 | ||
| 18 | const exe = b.addExecutable("test", "main.zig"); | |
| 19 | exe.addCSourceFile("test.c", &[_][]const u8{"-std=c11"}); | |
| 20 | exe.setBuildMode(mode); | |
| 21 | exe.linkLibC(); | |
| 22 | exe.setTarget(target); | |
| 23 | b.default_step.dependOn(&exe.step); | |
| 24 | ||
| 25 | const test_step = b.step("test", "Test the program"); | |
| 26 | if (isRunnableTarget(target)) { | |
| 27 | const run_cmd = exe.run(); | |
| 28 | test_step.dependOn(&run_cmd.step); | |
| 29 | } else { | |
| 30 | test_step.dependOn(&exe.step); | |
| 31 | } | |
| 32 | } |
test/standalone/mix_c_files/main.zig created+30| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | extern fn add_C(x: i32) i32; | |
| 4 | extern fn add_C_zig(x: i32) i32; | |
| 5 | extern threadlocal var C_k: c_int; | |
| 6 | ||
| 7 | export var zig_k: c_int = 1; | |
| 8 | export fn add_zig(x: i32) i32 { | |
| 9 | return x + zig_k + C_k; | |
| 10 | } | |
| 11 | export fn add_may_panic(x: i32) i32 { | |
| 12 | if (x < 0) @panic("negative int"); | |
| 13 | return x + zig_k; | |
| 14 | } | |
| 15 | ||
| 16 | pub fn main() anyerror!void { | |
| 17 | var x: i32 = 0; | |
| 18 | x = add_zig(x); | |
| 19 | x = add_C(x); | |
| 20 | x = add_C_zig(x); | |
| 21 | ||
| 22 | C_k = 200; | |
| 23 | zig_k = 2; | |
| 24 | x = add_zig(x); | |
| 25 | x = add_C(x); | |
| 26 | x = add_C_zig(x); | |
| 27 | ||
| 28 | const u = @intCast(u32, x); | |
| 29 | try std.testing.expect(u / 100 == u % 100); | |
| 30 | } |
test/standalone/mix_c_files/test.c created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | ||
| 2 | extern int zig_k; | |
| 3 | extern int add_may_panic(int); | |
| 4 | ||
| 5 | _Thread_local int C_k = 100; | |
| 6 | int unused(int x) { return x*x; } | |
| 7 | int add_C(int x) { return x+zig_k+C_k; } | |
| 8 | int add_C_zig(int x) { return add_may_panic(x) + C_k; } |