mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
link-tests: test -weak-lx and -weak_framework x
This commit is contained in:
parent
20bd722464
commit
075f5bc5ff
@ -408,6 +408,8 @@ const MachODumper = struct {
|
||||
|
||||
.ID_DYLIB,
|
||||
.LOAD_DYLIB,
|
||||
.LOAD_WEAK_DYLIB,
|
||||
.REEXPORT_DYLIB,
|
||||
=> {
|
||||
const dylib = lc.dylib.inner.dylib;
|
||||
try writer.writeByte('\n');
|
||||
|
||||
@ -45,7 +45,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
|
||||
.requires_macos_sdk = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/macho/needed_l/build.zig", .{
|
||||
cases.addBuildFile("test/link/macho/needed_library/build.zig", .{
|
||||
.build_modes = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/macho/weak_library/build.zig", .{
|
||||
.build_modes = true,
|
||||
});
|
||||
|
||||
@ -54,6 +58,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
|
||||
.requires_macos_sdk = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{
|
||||
.build_modes = true,
|
||||
.requires_macos_sdk = true,
|
||||
});
|
||||
|
||||
// Try to build and run an Objective-C executable.
|
||||
cases.addBuildFile("test/link/macho/objc/build.zig", .{
|
||||
.build_modes = true,
|
||||
|
||||
24
test/link/macho/weak_framework/build.zig
Normal file
24
test/link/macho/weak_framework/build.zig
Normal file
@ -0,0 +1,24 @@
|
||||
const std = @import("std");
|
||||
const Builder = std.build.Builder;
|
||||
const LibExeObjectStep = std.build.LibExeObjStep;
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const test_step = b.step("test", "Test the program");
|
||||
test_step.dependOn(b.getInstallStep());
|
||||
|
||||
const exe = b.addExecutable("test", null);
|
||||
exe.addCSourceFile("main.c", &[0][]const u8{});
|
||||
exe.setBuildMode(mode);
|
||||
exe.linkLibC();
|
||||
exe.linkFrameworkWeak("Cocoa");
|
||||
|
||||
const check = exe.checkObject(.macho);
|
||||
check.checkStart("cmd LOAD_WEAK_DYLIB");
|
||||
check.checkNext("name {*}Cocoa");
|
||||
test_step.dependOn(&check.step);
|
||||
|
||||
const run_cmd = exe.run();
|
||||
test_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
3
test/link/macho/weak_framework/main.c
Normal file
3
test/link/macho/weak_framework/main.c
Normal file
@ -0,0 +1,3 @@
|
||||
int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
9
test/link/macho/weak_library/a.c
Normal file
9
test/link/macho/weak_library/a.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int a = 42;
|
||||
|
||||
const char* asStr() {
|
||||
static char str[3];
|
||||
sprintf(str, "%d", 42);
|
||||
return str;
|
||||
}
|
||||
33
test/link/macho/weak_library/build.zig
Normal file
33
test/link/macho/weak_library/build.zig
Normal file
@ -0,0 +1,33 @@
|
||||
const std = @import("std");
|
||||
const Builder = std.build.Builder;
|
||||
const LibExeObjectStep = std.build.LibExeObjStep;
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const test_step = b.step("test", "Test the program");
|
||||
test_step.dependOn(b.getInstallStep());
|
||||
|
||||
const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
|
||||
dylib.setBuildMode(mode);
|
||||
dylib.addCSourceFile("a.c", &.{});
|
||||
dylib.linkLibC();
|
||||
dylib.install();
|
||||
|
||||
const exe = b.addExecutable("test", null);
|
||||
exe.addCSourceFile("main.c", &[0][]const u8{});
|
||||
exe.setBuildMode(mode);
|
||||
exe.linkLibC();
|
||||
exe.linkSystemLibraryWeak("a");
|
||||
exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));
|
||||
exe.addRPath(b.pathFromRoot("zig-out/lib"));
|
||||
|
||||
const check = exe.checkObject(.macho);
|
||||
check.checkStart("cmd LOAD_WEAK_DYLIB");
|
||||
check.checkNext("name @rpath/liba.dylib");
|
||||
test_step.dependOn(&check.step);
|
||||
|
||||
const run_cmd = exe.run();
|
||||
run_cmd.expectStdOutEqual("42 42");
|
||||
test_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
9
test/link/macho/weak_library/main.c
Normal file
9
test/link/macho/weak_library/main.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern int a;
|
||||
extern const char* asStr();
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
printf("%d %s", a, asStr());
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user