| author | |
| committer | |
| log | 38edef35bfcba5789ea50adc7c76dec504079812 |
| tree | 66d7f7279a005a36c201cadd474b66035f5c1a44 |
| parent | 74ed7c1f0998e9dd89aa3f3480fff845afd6b422 |
72 files changed, 485 insertions(+), 392 deletions(-)
build.zig+1| ... | @@ -489,6 +489,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -489,6 +489,7 @@ pub fn build(b: *Builder) !void { |
| 489 | 489 | ||
| 490 | toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); | 490 | toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); |
| 491 | toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes, skip_non_native, enable_macos_sdk, target)); | 491 | toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes, skip_non_native, enable_macos_sdk, target)); |
| 492 | toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk)); | ||
| 492 | toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); | 493 | toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); |
| 493 | toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes)); | 494 | toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes)); |
| 494 | toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); | 495 | toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); |
lib/std/build/RunStep.zig+1| ... | @@ -149,6 +149,7 @@ fn make(step: *Step) !void { | ... | @@ -149,6 +149,7 @@ fn make(step: *Step) !void { |
| 149 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; | 149 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; |
| 150 | 150 | ||
| 151 | var argv_list = ArrayList([]const u8).init(self.builder.allocator); | 151 | var argv_list = ArrayList([]const u8).init(self.builder.allocator); |
| 152 | |||
| 152 | for (self.argv.items) |arg| { | 153 | for (self.argv.items) |arg| { |
| 153 | switch (arg) { | 154 | switch (arg) { |
| 154 | .bytes => |bytes| try argv_list.append(bytes), | 155 | .bytes => |bytes| try argv_list.append(bytes), |
test/link.zig created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const tests = @import("tests.zig"); | ||
| 4 | |||
| 5 | pub fn addCases(cases: *tests.StandaloneContext) void { | ||
| 6 | cases.addBuildFile("test/link/bss/build.zig", .{ | ||
| 7 | .build_modes = false, // we only guarantee zerofill for undefined in Debug | ||
| 8 | }); | ||
| 9 | |||
| 10 | cases.addBuildFile("test/link/dylib/build.zig", .{ | ||
| 11 | .build_modes = true, | ||
| 12 | }); | ||
| 13 | |||
| 14 | cases.addBuildFile("test/link/common_symbols/build.zig", .{ | ||
| 15 | .build_modes = true, | ||
| 16 | }); | ||
| 17 | |||
| 18 | cases.addBuildFile("test/link/common_symbols_alignment/build.zig", .{ | ||
| 19 | .build_modes = true, | ||
| 20 | }); | ||
| 21 | |||
| 22 | cases.addBuildFile("test/link/interdependent_static_c_libs/build.zig", .{ | ||
| 23 | .build_modes = true, | ||
| 24 | }); | ||
| 25 | |||
| 26 | cases.addBuildFile("test/link/static_lib_as_system_lib/build.zig", .{ | ||
| 27 | .build_modes = true, | ||
| 28 | }); | ||
| 29 | |||
| 30 | cases.addBuildFile("test/link/tls/build.zig", .{ | ||
| 31 | .build_modes = true, | ||
| 32 | }); | ||
| 33 | |||
| 34 | if (builtin.os.tag == .macos) { | ||
| 35 | cases.addBuildFile("test/link/frameworks/build.zig", .{ | ||
| 36 | .build_modes = true, | ||
| 37 | .requires_macos_sdk = true, | ||
| 38 | }); | ||
| 39 | |||
| 40 | // Try to build and run an Objective-C executable. | ||
| 41 | cases.addBuildFile("test/link/objc/build.zig", .{ | ||
| 42 | .build_modes = true, | ||
| 43 | .requires_macos_sdk = true, | ||
| 44 | }); | ||
| 45 | |||
| 46 | // Try to build and run an Objective-C++ executable. | ||
| 47 | cases.addBuildFile("test/link/objcpp/build.zig", .{ | ||
| 48 | .build_modes = true, | ||
| 49 | .requires_macos_sdk = true, | ||
| 50 | }); | ||
| 51 | } | ||
| 52 | } | ||
test/link/bss/build.zig created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | const test_step = b.step("test", "Test"); | ||
| 6 | |||
| 7 | const exe = b.addExecutable("bss", "main.zig"); | ||
| 8 | b.default_step.dependOn(&exe.step); | ||
| 9 | exe.setBuildMode(mode); | ||
| 10 | |||
| 11 | const run = exe.run(); | ||
| 12 | run.expectStdOutEqual("0, 1, 0\n"); | ||
| 13 | test_step.dependOn(&run.step); | ||
| 14 | } | ||
test/link/bss/main.zig created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | // Stress test zerofill layout | ||
| 4 | var buffer: [0x1000000]u64 = undefined; | ||
| 5 | |||
| 6 | pub fn main() anyerror!void { | ||
| 7 | buffer[0x10] = 1; | ||
| 8 | try std.io.getStdOut().writer().print("{d}, {d}, {d}\n", .{ | ||
| 9 | buffer[0], | ||
| 10 | buffer[0x10], | ||
| 11 | buffer[0x1000000 - 1], | ||
| 12 | }); | ||
| 13 | } | ||
test/link/common_symbols/a.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | int i; | ||
| 2 | int j; | ||
| 3 | |||
| 4 | int add_to_i_and_j(int x) { | ||
| 5 | return x + i + j; | ||
| 6 | } | ||
test/link/common_symbols/b.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | long i; | ||
| 2 | int j = 2; | ||
| 3 | int k; | ||
| 4 | |||
| 5 | void incr_i() { | ||
| 6 | i++; | ||
| 7 | } | ||
test/link/common_symbols/build.zig created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib_a = b.addStaticLibrary("a", null); | ||
| 7 | lib_a.addCSourceFiles(&.{ "c.c", "a.c", "b.c" }, &.{"-fcommon"}); | ||
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | |||
| 10 | const test_exe = b.addTest("main.zig"); | ||
| 11 | test_exe.setBuildMode(mode); | ||
| 12 | test_exe.linkLibrary(lib_a); | ||
| 13 | |||
| 14 | const test_step = b.step("test", "Test it"); | ||
| 15 | test_step.dependOn(&test_exe.step); | ||
| 16 | } | ||
test/link/common_symbols/c.c created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | extern int k; | ||
| 2 | |||
| 3 | int common_defined_externally() { | ||
| 4 | return k; | ||
| 5 | } | ||
test/link/common_symbols/main.zig created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | extern fn common_defined_externally() c_int; | ||
| 5 | extern fn incr_i() void; | ||
| 6 | extern fn add_to_i_and_j(x: c_int) c_int; | ||
| 7 | |||
| 8 | test "undef shadows common symbol: issue #9937" { | ||
| 9 | try expect(common_defined_externally() == 0); | ||
| 10 | } | ||
| 11 | |||
| 12 | test "import C common symbols" { | ||
| 13 | incr_i(); | ||
| 14 | const res = add_to_i_and_j(2); | ||
| 15 | try expect(res == 5); | ||
| 16 | } | ||
test/link/common_symbols_alignment/a.c created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | int foo; | ||
| 2 | __attribute__((aligned(4096))) int bar; | ||
test/link/common_symbols_alignment/build.zig created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib_a = b.addStaticLibrary("a", null); | ||
| 7 | lib_a.addCSourceFiles(&.{"a.c"}, &.{"-fcommon"}); | ||
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | |||
| 10 | const test_exe = b.addTest("main.zig"); | ||
| 11 | test_exe.setBuildMode(mode); | ||
| 12 | test_exe.linkLibrary(lib_a); | ||
| 13 | |||
| 14 | const test_step = b.step("test", "Test it"); | ||
| 15 | test_step.dependOn(&test_exe.step); | ||
| 16 | } | ||
test/link/common_symbols_alignment/main.zig created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | extern var foo: i32; | ||
| 4 | extern var bar: i32; | ||
| 5 | |||
| 6 | test { | ||
| 7 | try std.testing.expect(@ptrToInt(&foo) % 4 == 0); | ||
| 8 | try std.testing.expect(@ptrToInt(&bar) % 4096 == 0); | ||
| 9 | } | ||
test/link/dylib/a.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | |||
| 3 | char world[] = "world"; | ||
| 4 | |||
| 5 | char* hello() { | ||
| 6 | return "Hello"; | ||
| 7 | } | ||
test/link/dylib/build.zig created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | |||
| 4 | pub fn build(b: *Builder) void { | ||
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test"); | ||
| 8 | |||
| 9 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | ||
| 10 | dylib.setBuildMode(mode); | ||
| 11 | dylib.addCSourceFile("a.c", &.{}); | ||
| 12 | dylib.linkLibC(); | ||
| 13 | dylib.install(); | ||
| 14 | |||
| 15 | const exe = b.addExecutable("main", null); | ||
| 16 | exe.setBuildMode(mode); | ||
| 17 | exe.addCSourceFile("main.c", &.{}); | ||
| 18 | exe.linkSystemLibrary("a"); | ||
| 19 | exe.linkLibC(); | ||
| 20 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib/")); | ||
| 21 | exe.addRPath(b.pathFromRoot("zig-out/lib")); | ||
| 22 | |||
| 23 | const run = exe.run(); | ||
| 24 | run.cwd = b.pathFromRoot("."); | ||
| 25 | run.expectStdOutEqual("Hello world"); | ||
| 26 | |||
| 27 | test_step.dependOn(b.getInstallStep()); | ||
| 28 | test_step.dependOn(&run.step); | ||
| 29 | } | ||
test/link/dylib/main.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | |||
| 3 | char* hello(); | ||
| 4 | extern char world[]; | ||
| 5 | |||
| 6 | int main() { | ||
| 7 | printf("%s %s", hello(), world); | ||
| 8 | return 0; | ||
| 9 | } | ||
test/link/frameworks/build.zig created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | |||
| 4 | pub fn build(b: *Builder) void { | ||
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test the program"); | ||
| 8 | |||
| 9 | const exe = b.addExecutable("test", null); | ||
| 10 | b.default_step.dependOn(&exe.step); | ||
| 11 | exe.addCSourceFile("main.c", &[0][]const u8{}); | ||
| 12 | exe.setBuildMode(mode); | ||
| 13 | exe.linkLibC(); | ||
| 14 | // TODO when we figure out how to ship framework stubs for cross-compilation, | ||
| 15 | // populate paths to the sysroot here. | ||
| 16 | exe.linkFramework("Cocoa"); | ||
| 17 | |||
| 18 | const run_cmd = exe.run(); | ||
| 19 | test_step.dependOn(&run_cmd.step); | ||
| 20 | } | ||
test/link/frameworks/main.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <assert.h> | ||
| 2 | #include <objc/runtime.h> | ||
| 3 | |||
| 4 | int main() { | ||
| 5 | assert(objc_getClass("NSObject") > 0); | ||
| 6 | assert(objc_getClass("NSApplication") > 0); | ||
| 7 | } | ||
test/link/interdependent_static_c_libs/a.c created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | #include "a.h" | ||
| 2 | int32_t add(int32_t a, int32_t b) { | ||
| 3 | return a + b; | ||
| 4 | } | ||
test/link/interdependent_static_c_libs/a.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | int32_t add(int32_t a, int32_t b); | ||
test/link/interdependent_static_c_libs/b.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "a.h" | ||
| 2 | #include "b.h" | ||
| 3 | |||
| 4 | int32_t sub(int32_t a, int32_t b) { | ||
| 5 | return add(a, -1 * b); | ||
| 6 | } | ||
test/link/interdependent_static_c_libs/b.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | int32_t sub(int32_t a, int32_t b); | ||
test/link/interdependent_static_c_libs/build.zig created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib_a = b.addStaticLibrary("a", null); | ||
| 7 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); | ||
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | lib_a.addIncludePath("."); | ||
| 10 | |||
| 11 | const lib_b = b.addStaticLibrary("b", null); | ||
| 12 | lib_b.addCSourceFile("b.c", &[_][]const u8{}); | ||
| 13 | lib_b.setBuildMode(mode); | ||
| 14 | lib_b.addIncludePath("."); | ||
| 15 | |||
| 16 | const test_exe = b.addTest("main.zig"); | ||
| 17 | test_exe.setBuildMode(mode); | ||
| 18 | test_exe.linkLibrary(lib_a); | ||
| 19 | test_exe.linkLibrary(lib_b); | ||
| 20 | test_exe.addIncludePath("."); | ||
| 21 | |||
| 22 | const test_step = b.step("test", "Test it"); | ||
| 23 | test_step.dependOn(&test_exe.step); | ||
| 24 | } | ||
test/link/interdependent_static_c_libs/main.zig created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const c = @cImport(@cInclude("b.h")); | ||
| 4 | |||
| 5 | test "import C sub" { | ||
| 6 | const result = c.sub(2, 1); | ||
| 7 | try expect(result == 1); | ||
| 8 | } | ||
test/link/objc/Foo.h created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #import <Foundation/Foundation.h> | ||
| 2 | |||
| 3 | @interface Foo : NSObject | ||
| 4 | |||
| 5 | - (NSString *)name; | ||
| 6 | |||
| 7 | @end | ||
test/link/objc/Foo.m created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | |||
| 3 | @implementation Foo | ||
| 4 | |||
| 5 | - (NSString *)name | ||
| 6 | { | ||
| 7 | NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; | ||
| 8 | return str; | ||
| 9 | } | ||
| 10 | |||
| 11 | @end | ||
test/link/objc/build.zig created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | |||
| 4 | pub fn build(b: *Builder) void { | ||
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test the program"); | ||
| 8 | |||
| 9 | const exe = b.addExecutable("test", null); | ||
| 10 | b.default_step.dependOn(&exe.step); | ||
| 11 | exe.addIncludePath("."); | ||
| 12 | exe.addCSourceFile("Foo.m", &[0][]const u8{}); | ||
| 13 | exe.addCSourceFile("test.m", &[0][]const u8{}); | ||
| 14 | exe.setBuildMode(mode); | ||
| 15 | exe.linkLibC(); | ||
| 16 | // TODO when we figure out how to ship framework stubs for cross-compilation, | ||
| 17 | // populate paths to the sysroot here. | ||
| 18 | exe.linkFramework("Foundation"); | ||
| 19 | |||
| 20 | const run_cmd = exe.run(); | ||
| 21 | test_step.dependOn(&run_cmd.step); | ||
| 22 | } | ||
test/link/objc/test.m created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | #import <assert.h> | ||
| 3 | |||
| 4 | int main(int argc, char *argv[]) | ||
| 5 | { | ||
| 6 | @autoreleasepool { | ||
| 7 | Foo *foo = [[Foo alloc] init]; | ||
| 8 | NSString *result = [foo name]; | ||
| 9 | assert([result isEqualToString:@"Zig"]); | ||
| 10 | return 0; | ||
| 11 | } | ||
| 12 | } | ||
test/link/objcpp/Foo.h created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #import <Foundation/Foundation.h> | ||
| 2 | |||
| 3 | @interface Foo : NSObject | ||
| 4 | |||
| 5 | - (NSString *)name; | ||
| 6 | |||
| 7 | @end | ||
test/link/objcpp/Foo.mm created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | |||
| 3 | @implementation Foo | ||
| 4 | |||
| 5 | - (NSString *)name | ||
| 6 | { | ||
| 7 | NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; | ||
| 8 | return str; | ||
| 9 | } | ||
| 10 | |||
| 11 | @end | ||
test/link/objcpp/build.zig created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | |||
| 4 | pub fn build(b: *Builder) void { | ||
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const test_step = b.step("test", "Test the program"); | ||
| 8 | |||
| 9 | const exe = b.addExecutable("test", null); | ||
| 10 | b.default_step.dependOn(&exe.step); | ||
| 11 | exe.addIncludePath("."); | ||
| 12 | exe.addCSourceFile("Foo.mm", &[0][]const u8{}); | ||
| 13 | exe.addCSourceFile("test.mm", &[0][]const u8{}); | ||
| 14 | exe.setBuildMode(mode); | ||
| 15 | exe.linkLibCpp(); | ||
| 16 | // TODO when we figure out how to ship framework stubs for cross-compilation, | ||
| 17 | // populate paths to the sysroot here. | ||
| 18 | exe.linkFramework("Foundation"); | ||
| 19 | |||
| 20 | const run_cmd = exe.run(); | ||
| 21 | run_cmd.expectStdOutEqual("Hello from C++ and Zig"); | ||
| 22 | |||
| 23 | test_step.dependOn(&run_cmd.step); | ||
| 24 | } | ||
test/link/objcpp/test.mm created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | #import <assert.h> | ||
| 3 | #include <iostream> | ||
| 4 | |||
| 5 | int main(int argc, char *argv[]) | ||
| 6 | { | ||
| 7 | @autoreleasepool { | ||
| 8 | Foo *foo = [[Foo alloc] init]; | ||
| 9 | NSString *result = [foo name]; | ||
| 10 | std::cout << "Hello from C++ and " << [result UTF8String]; | ||
| 11 | assert([result isEqualToString:@"Zig"]); | ||
| 12 | return 0; | ||
| 13 | } | ||
| 14 | } | ||
test/link/static_lib_as_system_lib/a.c created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | #include "a.h" | ||
| 2 | int32_t add(int32_t a, int32_t b) { | ||
| 3 | return a + b; | ||
| 4 | } | ||
test/link/static_lib_as_system_lib/a.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | int32_t add(int32_t a, int32_t b); | ||
test/link/static_lib_as_system_lib/build.zig created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | |||
| 4 | pub fn build(b: *Builder) void { | ||
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const lib_a = b.addStaticLibrary("a", null); | ||
| 8 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); | ||
| 9 | lib_a.setBuildMode(mode); | ||
| 10 | lib_a.addIncludePath("."); | ||
| 11 | lib_a.install(); | ||
| 12 | |||
| 13 | const test_exe = b.addTest("main.zig"); | ||
| 14 | test_exe.setBuildMode(mode); | ||
| 15 | test_exe.linkSystemLibrary("a"); // force linking liba.a as -la | ||
| 16 | test_exe.addSystemIncludePath("."); | ||
| 17 | const search_path = std.fs.path.join(b.allocator, &[_][]const u8{ b.install_path, "lib" }) catch unreachable; | ||
| 18 | test_exe.addLibraryPath(search_path); | ||
| 19 | |||
| 20 | const test_step = b.step("test", "Test it"); | ||
| 21 | test_step.dependOn(b.getInstallStep()); | ||
| 22 | test_step.dependOn(&test_exe.step); | ||
| 23 | } | ||
test/link/static_lib_as_system_lib/main.zig created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const c = @cImport(@cInclude("a.h")); | ||
| 4 | |||
| 5 | test "import C add" { | ||
| 6 | const result = c.add(2, 1); | ||
| 7 | try expect(result == 3); | ||
| 8 | } | ||
test/link/tls/a.c created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | _Thread_local int a; | ||
| 2 | |||
| 3 | int getA() { | ||
| 4 | return a; | ||
| 5 | } | ||
test/link/tls/build.zig created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | ||
| 7 | lib.setBuildMode(mode); | ||
| 8 | lib.addCSourceFile("a.c", &.{}); | ||
| 9 | lib.linkLibC(); | ||
| 10 | |||
| 11 | const test_exe = b.addTest("main.zig"); | ||
| 12 | test_exe.setBuildMode(mode); | ||
| 13 | test_exe.linkLibrary(lib); | ||
| 14 | test_exe.linkLibC(); | ||
| 15 | |||
| 16 | const test_step = b.step("test", "Test it"); | ||
| 17 | test_step.dependOn(&test_exe.step); | ||
| 18 | } | ||
test/link/tls/main.zig created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | extern threadlocal var a: i32; | ||
| 4 | extern fn getA() i32; | ||
| 5 | |||
| 6 | fn getA2() i32 { | ||
| 7 | return a; | ||
| 8 | } | ||
| 9 | |||
| 10 | test { | ||
| 11 | a = 2; | ||
| 12 | try std.testing.expect(getA() == 2); | ||
| 13 | try std.testing.expect(2 == getA2()); | ||
| 14 | try std.testing.expect(getA() == getA2()); | ||
| 15 | } | ||
test/standalone.zig+4-33| ... | @@ -13,31 +13,12 @@ pub fn addCases(cases: *tests.StandaloneContext) void { | ... | @@ -13,31 +13,12 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 13 | cases.addBuildFile("test/standalone/main_pkg_path/build.zig", .{}); | 13 | cases.addBuildFile("test/standalone/main_pkg_path/build.zig", .{}); |
| 14 | cases.addBuildFile("test/standalone/shared_library/build.zig", .{}); | 14 | cases.addBuildFile("test/standalone/shared_library/build.zig", .{}); |
| 15 | cases.addBuildFile("test/standalone/mix_o_files/build.zig", .{}); | 15 | cases.addBuildFile("test/standalone/mix_o_files/build.zig", .{}); |
| 16 | if (builtin.os.tag == .macos) { | 16 | cases.addBuildFile("test/standalone/mix_c_files/build.zig", .{ |
| 17 | // Zig's macOS linker does not yet support LTO for LLVM IR files: | 17 | .build_modes = true, |
| 18 | // https://github.com/ziglang/zig/issues/8680 | 18 | .cross_targets = true, |
| 19 | cases.addBuildFile("test/standalone/mix_c_files/build.zig", .{ | 19 | }); |
| 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 | } | ||
| 29 | cases.addBuildFile("test/standalone/global_linkage/build.zig", .{}); | 20 | cases.addBuildFile("test/standalone/global_linkage/build.zig", .{}); |
| 30 | cases.addBuildFile("test/standalone/static_c_lib/build.zig", .{}); | 21 | cases.addBuildFile("test/standalone/static_c_lib/build.zig", .{}); |
| 31 | cases.addBuildFile("test/standalone/link_interdependent_static_c_libs/build.zig", .{}); | ||
| 32 | cases.addBuildFile("test/standalone/link_static_lib_as_system_lib/build.zig", .{}); | ||
| 33 | cases.addBuildFile("test/standalone/link_common_symbols/build.zig", .{}); | ||
| 34 | cases.addBuildFile("test/standalone/link_frameworks/build.zig", .{ | ||
| 35 | .requires_macos_sdk = true, | ||
| 36 | }); | ||
| 37 | cases.addBuildFile("test/standalone/link_common_symbols_alignment/build.zig", .{}); | ||
| 38 | if (builtin.os.tag == .macos) { | ||
| 39 | cases.addBuildFile("test/standalone/link_import_tls_dylib/build.zig", .{}); | ||
| 40 | } | ||
| 41 | cases.addBuildFile("test/standalone/issue_339/build.zig", .{}); | 22 | cases.addBuildFile("test/standalone/issue_339/build.zig", .{}); |
| 42 | cases.addBuildFile("test/standalone/issue_8550/build.zig", .{}); | 23 | cases.addBuildFile("test/standalone/issue_8550/build.zig", .{}); |
| 43 | cases.addBuildFile("test/standalone/issue_794/build.zig", .{}); | 24 | cases.addBuildFile("test/standalone/issue_794/build.zig", .{}); |
| ... | @@ -69,16 +50,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void { | ... | @@ -69,16 +50,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 69 | if (builtin.os.tag == .linux) { | 50 | if (builtin.os.tag == .linux) { |
| 70 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); | 51 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); |
| 71 | } | 52 | } |
| 72 | // Try to build and run an Objective-C executable. | ||
| 73 | cases.addBuildFile("test/standalone/objc/build.zig", .{ | ||
| 74 | .build_modes = true, | ||
| 75 | .requires_macos_sdk = true, | ||
| 76 | }); | ||
| 77 | // Try to build and run an Objective-C++ executable. | ||
| 78 | cases.addBuildFile("test/standalone/objcpp/build.zig", .{ | ||
| 79 | .build_modes = true, | ||
| 80 | .requires_macos_sdk = true, | ||
| 81 | }); | ||
| 82 | 53 | ||
| 83 | // Ensure the development tools are buildable. | 54 | // Ensure the development tools are buildable. |
| 84 | cases.add("tools/gen_spirv_spec.zig"); | 55 | cases.add("tools/gen_spirv_spec.zig"); |
test/standalone/link_common_symbols/a.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | int i; | ||
| 2 | int j; | ||
| 3 | |||
| 4 | int add_to_i_and_j(int x) { | ||
| 5 | return x + i + j; | ||
| 6 | } | ||
test/standalone/link_common_symbols/b.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | long i; | ||
| 2 | int j = 2; | ||
| 3 | int k; | ||
| 4 | |||
| 5 | void incr_i() { | ||
| 6 | i++; | ||
| 7 | } | ||
test/standalone/link_common_symbols/build.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib_a = b.addStaticLibrary("a", null); | ||
| 7 | lib_a.addCSourceFiles(&.{ "c.c", "a.c", "b.c" }, &.{"-fcommon"}); | ||
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | |||
| 10 | const test_exe = b.addTest("main.zig"); | ||
| 11 | test_exe.setBuildMode(mode); | ||
| 12 | test_exe.linkLibrary(lib_a); | ||
| 13 | |||
| 14 | const test_step = b.step("test", "Test it"); | ||
| 15 | test_step.dependOn(&test_exe.step); | ||
| 16 | } | ||
test/standalone/link_common_symbols/c.c deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | extern int k; | ||
| 2 | |||
| 3 | int common_defined_externally() { | ||
| 4 | return k; | ||
| 5 | } | ||
test/standalone/link_common_symbols/main.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | extern fn common_defined_externally() c_int; | ||
| 5 | extern fn incr_i() void; | ||
| 6 | extern fn add_to_i_and_j(x: c_int) c_int; | ||
| 7 | |||
| 8 | test "undef shadows common symbol: issue #9937" { | ||
| 9 | try expect(common_defined_externally() == 0); | ||
| 10 | } | ||
| 11 | |||
| 12 | test "import C common symbols" { | ||
| 13 | incr_i(); | ||
| 14 | const res = add_to_i_and_j(2); | ||
| 15 | try expect(res == 5); | ||
| 16 | } | ||
test/standalone/link_common_symbols_alignment/a.c deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | int foo; | ||
| 2 | __attribute__((aligned(4096))) int bar; | ||
test/standalone/link_common_symbols_alignment/build.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib_a = b.addStaticLibrary("a", null); | ||
| 7 | lib_a.addCSourceFiles(&.{"a.c"}, &.{"-fcommon"}); | ||
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | |||
| 10 | const test_exe = b.addTest("main.zig"); | ||
| 11 | test_exe.setBuildMode(mode); | ||
| 12 | test_exe.linkLibrary(lib_a); | ||
| 13 | |||
| 14 | const test_step = b.step("test", "Test it"); | ||
| 15 | test_step.dependOn(&test_exe.step); | ||
| 16 | } | ||
test/standalone/link_common_symbols_alignment/main.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | extern var foo: i32; | ||
| 4 | extern var bar: i32; | ||
| 5 | |||
| 6 | test { | ||
| 7 | try std.testing.expect(@ptrToInt(&foo) % 4 == 0); | ||
| 8 | try std.testing.expect(@ptrToInt(&bar) % 4096 == 0); | ||
| 9 | } | ||
test/standalone/link_frameworks/build.zig deleted-34| ... | @@ -1,34 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | const CrossTarget = std.zig.CrossTarget; | ||
| 4 | |||
| 5 | fn isRunnableTarget(t: CrossTarget) bool { | ||
| 6 | // TODO I think we might be able to run this on Linux via Darling. | ||
| 7 | // Add a check for that here, and return true if Darling is available. | ||
| 8 | if (t.isNative() and t.getOsTag() == .macos) | ||
| 9 | return true | ||
| 10 | else | ||
| 11 | return false; | ||
| 12 | } | ||
| 13 | |||
| 14 | pub fn build(b: *Builder) void { | ||
| 15 | const mode = b.standardReleaseOptions(); | ||
| 16 | const target = b.standardTargetOptions(.{}); | ||
| 17 | |||
| 18 | const test_step = b.step("test", "Test the program"); | ||
| 19 | |||
| 20 | const exe = b.addExecutable("test", null); | ||
| 21 | b.default_step.dependOn(&exe.step); | ||
| 22 | exe.addCSourceFile("main.c", &[0][]const u8{}); | ||
| 23 | exe.setBuildMode(mode); | ||
| 24 | exe.setTarget(target); | ||
| 25 | exe.linkLibC(); | ||
| 26 | // TODO when we figure out how to ship framework stubs for cross-compilation, | ||
| 27 | // populate paths to the sysroot here. | ||
| 28 | exe.linkFramework("Cocoa"); | ||
| 29 | |||
| 30 | if (isRunnableTarget(target)) { | ||
| 31 | const run_cmd = exe.run(); | ||
| 32 | test_step.dependOn(&run_cmd.step); | ||
| 33 | } | ||
| 34 | } | ||
test/standalone/link_frameworks/main.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include <assert.h> | ||
| 2 | #include <objc/runtime.h> | ||
| 3 | |||
| 4 | int main() { | ||
| 5 | assert(objc_getClass("NSObject") > 0); | ||
| 6 | assert(objc_getClass("NSApplication") > 0); | ||
| 7 | } | ||
test/standalone/link_import_tls_dylib/a.c deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | _Thread_local int a; | ||
test/standalone/link_import_tls_dylib/build.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | ||
| 7 | lib.setBuildMode(mode); | ||
| 8 | lib.addCSourceFile("a.c", &.{}); | ||
| 9 | |||
| 10 | const test_exe = b.addTest("main.zig"); | ||
| 11 | test_exe.setBuildMode(mode); | ||
| 12 | test_exe.linkLibrary(lib); | ||
| 13 | |||
| 14 | const test_step = b.step("test", "Test it"); | ||
| 15 | test_step.dependOn(&test_exe.step); | ||
| 16 | } | ||
test/standalone/link_import_tls_dylib/main.zig deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | extern threadlocal var a: i32; | ||
| 4 | |||
| 5 | test { | ||
| 6 | try std.testing.expect(a == 0); | ||
| 7 | } | ||
test/standalone/link_interdependent_static_c_libs/a.c deleted-4| ... | @@ -1,4 +0,0 @@ | ||
| 1 | #include "a.h" | ||
| 2 | int32_t add(int32_t a, int32_t b) { | ||
| 3 | return a + b; | ||
| 4 | } | ||
test/standalone/link_interdependent_static_c_libs/a.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | int32_t add(int32_t a, int32_t b); | ||
test/standalone/link_interdependent_static_c_libs/b.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include "a.h" | ||
| 2 | #include "b.h" | ||
| 3 | |||
| 4 | int32_t sub(int32_t a, int32_t b) { | ||
| 5 | return add(a, -1 * b); | ||
| 6 | } | ||
test/standalone/link_interdependent_static_c_libs/b.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | int32_t sub(int32_t a, int32_t b); | ||
test/standalone/link_interdependent_static_c_libs/build.zig deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | const Builder = @import("std").build.Builder; | ||
| 2 | |||
| 3 | pub fn build(b: *Builder) void { | ||
| 4 | const mode = b.standardReleaseOptions(); | ||
| 5 | |||
| 6 | const lib_a = b.addStaticLibrary("a", null); | ||
| 7 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); | ||
| 8 | lib_a.setBuildMode(mode); | ||
| 9 | lib_a.addIncludePath("."); | ||
| 10 | |||
| 11 | const lib_b = b.addStaticLibrary("b", null); | ||
| 12 | lib_b.addCSourceFile("b.c", &[_][]const u8{}); | ||
| 13 | lib_b.setBuildMode(mode); | ||
| 14 | lib_b.addIncludePath("."); | ||
| 15 | |||
| 16 | const test_exe = b.addTest("main.zig"); | ||
| 17 | test_exe.setBuildMode(mode); | ||
| 18 | test_exe.linkLibrary(lib_a); | ||
| 19 | test_exe.linkLibrary(lib_b); | ||
| 20 | test_exe.addIncludePath("."); | ||
| 21 | |||
| 22 | const test_step = b.step("test", "Test it"); | ||
| 23 | test_step.dependOn(&test_exe.step); | ||
| 24 | } | ||
test/standalone/link_interdependent_static_c_libs/main.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const c = @cImport(@cInclude("b.h")); | ||
| 4 | |||
| 5 | test "import C sub" { | ||
| 6 | const result = c.sub(2, 1); | ||
| 7 | try expect(result == 1); | ||
| 8 | } | ||
test/standalone/link_static_lib_as_system_lib/a.c deleted-4| ... | @@ -1,4 +0,0 @@ | ||
| 1 | #include "a.h" | ||
| 2 | int32_t add(int32_t a, int32_t b) { | ||
| 3 | return a + b; | ||
| 4 | } | ||
test/standalone/link_static_lib_as_system_lib/a.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | int32_t add(int32_t a, int32_t b); | ||
test/standalone/link_static_lib_as_system_lib/build.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | |||
| 4 | pub fn build(b: *Builder) void { | ||
| 5 | const mode = b.standardReleaseOptions(); | ||
| 6 | |||
| 7 | const lib_a = b.addStaticLibrary("a", null); | ||
| 8 | lib_a.addCSourceFile("a.c", &[_][]const u8{}); | ||
| 9 | lib_a.setBuildMode(mode); | ||
| 10 | lib_a.addIncludePath("."); | ||
| 11 | lib_a.install(); | ||
| 12 | |||
| 13 | const test_exe = b.addTest("main.zig"); | ||
| 14 | test_exe.setBuildMode(mode); | ||
| 15 | test_exe.linkSystemLibrary("a"); // force linking liba.a as -la | ||
| 16 | test_exe.addSystemIncludePath("."); | ||
| 17 | const search_path = std.fs.path.join(b.allocator, &[_][]const u8{ b.install_path, "lib" }) catch unreachable; | ||
| 18 | test_exe.addLibraryPath(search_path); | ||
| 19 | |||
| 20 | const test_step = b.step("test", "Test it"); | ||
| 21 | test_step.dependOn(b.getInstallStep()); | ||
| 22 | test_step.dependOn(&test_exe.step); | ||
| 23 | } | ||
test/standalone/link_static_lib_as_system_lib/main.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const c = @cImport(@cInclude("a.h")); | ||
| 4 | |||
| 5 | test "import C add" { | ||
| 6 | const result = c.add(2, 1); | ||
| 7 | try expect(result == 3); | ||
| 8 | } | ||
test/standalone/objc/Foo.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #import <Foundation/Foundation.h> | ||
| 2 | |||
| 3 | @interface Foo : NSObject | ||
| 4 | |||
| 5 | - (NSString *)name; | ||
| 6 | |||
| 7 | @end | ||
test/standalone/objc/Foo.m deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | |||
| 3 | @implementation Foo | ||
| 4 | |||
| 5 | - (NSString *)name | ||
| 6 | { | ||
| 7 | NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; | ||
| 8 | return str; | ||
| 9 | } | ||
| 10 | |||
| 11 | @end | ||
test/standalone/objc/build.zig deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | const CrossTarget = std.zig.CrossTarget; | ||
| 4 | |||
| 5 | fn isRunnableTarget(t: CrossTarget) bool { | ||
| 6 | // TODO I think we might be able to run this on Linux via Darling. | ||
| 7 | // Add a check for that here, and return true if Darling is available. | ||
| 8 | if (t.isNative() and t.getOsTag() == .macos) | ||
| 9 | return true | ||
| 10 | else | ||
| 11 | return false; | ||
| 12 | } | ||
| 13 | |||
| 14 | pub fn build(b: *Builder) void { | ||
| 15 | const mode = b.standardReleaseOptions(); | ||
| 16 | const target = b.standardTargetOptions(.{}); | ||
| 17 | |||
| 18 | const test_step = b.step("test", "Test the program"); | ||
| 19 | |||
| 20 | const exe = b.addExecutable("test", null); | ||
| 21 | b.default_step.dependOn(&exe.step); | ||
| 22 | exe.addIncludePath("."); | ||
| 23 | exe.addCSourceFile("Foo.m", &[0][]const u8{}); | ||
| 24 | exe.addCSourceFile("test.m", &[0][]const u8{}); | ||
| 25 | exe.setBuildMode(mode); | ||
| 26 | exe.setTarget(target); | ||
| 27 | exe.linkLibC(); | ||
| 28 | // TODO when we figure out how to ship framework stubs for cross-compilation, | ||
| 29 | // populate paths to the sysroot here. | ||
| 30 | exe.linkFramework("Foundation"); | ||
| 31 | |||
| 32 | if (isRunnableTarget(target)) { | ||
| 33 | const run_cmd = exe.run(); | ||
| 34 | test_step.dependOn(&run_cmd.step); | ||
| 35 | } | ||
| 36 | } | ||
test/standalone/objc/test.m deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | #import <assert.h> | ||
| 3 | |||
| 4 | int main(int argc, char *argv[]) | ||
| 5 | { | ||
| 6 | @autoreleasepool { | ||
| 7 | Foo *foo = [[Foo alloc] init]; | ||
| 8 | NSString *result = [foo name]; | ||
| 9 | assert([result isEqualToString:@"Zig"]); | ||
| 10 | return 0; | ||
| 11 | } | ||
| 12 | } | ||
test/standalone/objcpp/Foo.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #import <Foundation/Foundation.h> | ||
| 2 | |||
| 3 | @interface Foo : NSObject | ||
| 4 | |||
| 5 | - (NSString *)name; | ||
| 6 | |||
| 7 | @end | ||
test/standalone/objcpp/Foo.mm deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | |||
| 3 | @implementation Foo | ||
| 4 | |||
| 5 | - (NSString *)name | ||
| 6 | { | ||
| 7 | NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; | ||
| 8 | return str; | ||
| 9 | } | ||
| 10 | |||
| 11 | @end | ||
test/standalone/objcpp/build.zig deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | const CrossTarget = std.zig.CrossTarget; | ||
| 4 | |||
| 5 | fn isRunnableTarget(t: CrossTarget) bool { | ||
| 6 | // TODO I think we might be able to run this on Linux via Darling. | ||
| 7 | // Add a check for that here, and return true if Darling is available. | ||
| 8 | if (t.isNative() and t.getOsTag() == .macos) | ||
| 9 | return true | ||
| 10 | else | ||
| 11 | return false; | ||
| 12 | } | ||
| 13 | |||
| 14 | pub fn build(b: *Builder) void { | ||
| 15 | const mode = b.standardReleaseOptions(); | ||
| 16 | const target = b.standardTargetOptions(.{}); | ||
| 17 | |||
| 18 | const test_step = b.step("test", "Test the program"); | ||
| 19 | |||
| 20 | const exe = b.addExecutable("test", null); | ||
| 21 | b.default_step.dependOn(&exe.step); | ||
| 22 | exe.addIncludePath("."); | ||
| 23 | exe.addCSourceFile("Foo.mm", &[0][]const u8{}); | ||
| 24 | exe.addCSourceFile("test.mm", &[0][]const u8{}); | ||
| 25 | exe.setBuildMode(mode); | ||
| 26 | exe.setTarget(target); | ||
| 27 | exe.linkLibCpp(); | ||
| 28 | // TODO when we figure out how to ship framework stubs for cross-compilation, | ||
| 29 | // populate paths to the sysroot here. | ||
| 30 | exe.linkFramework("Foundation"); | ||
| 31 | |||
| 32 | if (isRunnableTarget(target)) { | ||
| 33 | const run_cmd = exe.run(); | ||
| 34 | test_step.dependOn(&run_cmd.step); | ||
| 35 | } | ||
| 36 | } | ||
test/standalone/objcpp/test.mm deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #import "Foo.h" | ||
| 2 | #import <assert.h> | ||
| 3 | #include <iostream> | ||
| 4 | |||
| 5 | int main(int argc, char *argv[]) | ||
| 6 | { | ||
| 7 | @autoreleasepool { | ||
| 8 | Foo *foo = [[Foo alloc] init]; | ||
| 9 | NSString *result = [foo name]; | ||
| 10 | std::cout << "Hello from C++ and " << [result UTF8String]; | ||
| 11 | assert([result isEqualToString:@"Zig"]); | ||
| 12 | return 0; | ||
| 13 | } | ||
| 14 | } | ||
test/tests.zig+22| ... | @@ -21,6 +21,7 @@ const assemble_and_link = @import("assemble_and_link.zig"); | ... | @@ -21,6 +21,7 @@ const assemble_and_link = @import("assemble_and_link.zig"); |
| 21 | const translate_c = @import("translate_c.zig"); | 21 | const translate_c = @import("translate_c.zig"); |
| 22 | const run_translated_c = @import("run_translated_c.zig"); | 22 | const run_translated_c = @import("run_translated_c.zig"); |
| 23 | const gen_h = @import("gen_h.zig"); | 23 | const gen_h = @import("gen_h.zig"); |
| 24 | const link = @import("link.zig"); | ||
| 24 | 25 | ||
| 25 | // Implementations | 26 | // Implementations |
| 26 | pub const TranslateCContext = @import("src/translate_c.zig").TranslateCContext; | 27 | pub const TranslateCContext = @import("src/translate_c.zig").TranslateCContext; |
| ... | @@ -479,6 +480,27 @@ pub fn addStandaloneTests( | ... | @@ -479,6 +480,27 @@ pub fn addStandaloneTests( |
| 479 | return cases.step; | 480 | return cases.step; |
| 480 | } | 481 | } |
| 481 | 482 | ||
| 483 | pub fn addLinkTests( | ||
| 484 | b: *build.Builder, | ||
| 485 | test_filter: ?[]const u8, | ||
| 486 | modes: []const Mode, | ||
| 487 | enable_macos_sdk: bool, | ||
| 488 | ) *build.Step { | ||
| 489 | const cases = b.allocator.create(StandaloneContext) catch unreachable; | ||
| 490 | cases.* = StandaloneContext{ | ||
| 491 | .b = b, | ||
| 492 | .step = b.step("test-link", "Run the linker tests"), | ||
| 493 | .test_index = 0, | ||
| 494 | .test_filter = test_filter, | ||
| 495 | .modes = modes, | ||
| 496 | .skip_non_native = true, | ||
| 497 | .enable_macos_sdk = enable_macos_sdk, | ||
| 498 | .target = .{}, | ||
| 499 | }; | ||
| 500 | link.addCases(cases); | ||
| 501 | return cases.step; | ||
| 502 | } | ||
| 503 | |||
| 482 | pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { | 504 | pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step { |
| 483 | _ = test_filter; | 505 | _ = test_filter; |
| 484 | _ = modes; | 506 | _ = modes; |