mirror of
https://github.com/ziglang/zig.git
synced 2026-01-09 08:55:36 +00:00
* introduce LazyPath.cwd_relative variant and use it for --zig-lib-dir. closes #12685 * move overrideZigLibDir and setMainPkgPath to options fields set once and then never mutated. * avoid introducing Build/util.zig * use doc comments for deprecation notices so that they show up in generated documentation. * introduce InstallArtifact.Options, accept it as a parameter to addInstallArtifact, and move override_dest_dir into it. Instead of configuring the installation via Compile step, configure the installation via the InstallArtifact step. In retrospect this is obvious. * remove calls to pushInstalledFile in InstallArtifact. See #14943 * rewrite InstallArtifact to not incorrectly observe whether a Compile step has any generated outputs. InstallArtifact is meant to trigger output generation. * fix child process evaluation code handling of `-fno-emit-bin`. * don't store out_h_filename, out_ll_filename, etc., pointlessly. these are all just simple extensions appended to the root name. * make emit_directory optional. It's possible to have nothing outputted, for example, if you're just type-checking. * avoid passing -femit-foo/-fno-emit-foo when it is the default * rename ConfigHeader.getTemplate to getOutput * deprecate addOptionArtifact * update the random number seed of Options step caching. * avoid using `inline for` pointlessly * avoid using `override_Dest_dir` pointlessly * avoid emitting an executable pointlessly in test cases Removes forceBuild and forceEmit. Let's consider these additions separately. Nearly all of the usage sites were suspicious.
66 lines
2.1 KiB
Zig
66 lines
2.1 KiB
Zig
const std = @import("std");
|
|
|
|
pub const requires_symlinks = true;
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const test_step = b.step("test", "Test it");
|
|
b.default_step = test_step;
|
|
|
|
add(b, test_step, .Debug);
|
|
add(b, test_step, .ReleaseFast);
|
|
add(b, test_step, .ReleaseSmall);
|
|
add(b, test_step, .ReleaseSafe);
|
|
}
|
|
|
|
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
|
|
const target: std.zig.CrossTarget = .{ .os_tag = .macos };
|
|
|
|
const dylib = b.addSharedLibrary(.{
|
|
.name = "a",
|
|
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
|
.optimize = optimize,
|
|
.target = target,
|
|
});
|
|
dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
|
|
dylib.linkLibC();
|
|
|
|
const check_dylib = dylib.checkObject();
|
|
check_dylib.checkStart();
|
|
check_dylib.checkExact("cmd ID_DYLIB");
|
|
check_dylib.checkExact("name @rpath/liba.dylib");
|
|
check_dylib.checkExact("timestamp 2");
|
|
check_dylib.checkExact("current version 10000");
|
|
check_dylib.checkExact("compatibility version 10000");
|
|
|
|
test_step.dependOn(&check_dylib.step);
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "main",
|
|
.optimize = optimize,
|
|
.target = target,
|
|
});
|
|
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
|
|
exe.linkSystemLibrary("a");
|
|
exe.addLibraryPath(dylib.getEmittedBinDirectory());
|
|
exe.addRPath(dylib.getEmittedBinDirectory());
|
|
exe.linkLibC();
|
|
|
|
const check_exe = exe.checkObject();
|
|
check_exe.checkStart();
|
|
check_exe.checkExact("cmd LOAD_DYLIB");
|
|
check_exe.checkExact("name @rpath/liba.dylib");
|
|
check_exe.checkExact("timestamp 2");
|
|
check_exe.checkExact("current version 10000");
|
|
check_exe.checkExact("compatibility version 10000");
|
|
|
|
check_exe.checkStart();
|
|
check_exe.checkExact("cmd RPATH");
|
|
check_exe.checkExactPath("path", dylib.getOutputDirectorySource());
|
|
test_step.dependOn(&check_exe.step);
|
|
|
|
const run = b.addRunArtifact(exe);
|
|
run.skip_foreign_checks = true;
|
|
run.expectStdOutEqual("Hello world");
|
|
test_step.dependOn(&run.step);
|
|
}
|