| author | |
| committer | |
| log | 142471fcc46070326526e3976f0150fe734df0b6 |
| tree | 67d4dec7968cf6d6765cd3bc66524721cf0554d2 |
| parent | 579f572cf203eda11da7e4e919fdfc12e15f03e2 |
Introduce the concept of "target query" and "resolved target". A target
query is what the user specifies, with some things left to default. A
resolved target has the default things discovered and populated.
In the future, std.zig.CrossTarget will be rename to std.Target.Query.
Introduces `std.Build.resolveTargetQuery` to get from one to the other.
The concept of `main_mod_path` is gone, no longer supported. You have to
put the root source file at the module root now.
* remove deprecated API
* update build.zig for the breaking API changes in this branch
* move std.Build.Step.Compile.BuildId to std.zig.BuildId
* add more options to std.Build.ExecutableOptions, std.Build.ObjectOptions,
std.Build.SharedLibraryOptions, std.Build.StaticLibraryOptions, and
std.Build.TestOptions.
* remove `std.Build.constructCMacro`. There is no use for this API.
* deprecate `std.Build.Step.Compile.defineCMacro`. Instead,
`std.Build.Module.addCMacro` is provided.
- remove `std.Build.Step.Compile.defineCMacroRaw`.
* deprecate `std.Build.Step.Compile.linkFrameworkNeeded`
- use `std.Build.Module.linkFramework`
* deprecate `std.Build.Step.Compile.linkFrameworkWeak`
- use `std.Build.Module.linkFramework`
* move more logic into `std.Build.Module`
* allow `target` and `optimize` to be `null` when creating a Module.
Along with other fields, those unspecified options will be inherited
from parent `Module` when inserted into an import table.
* the `target` field of `addExecutable` is now required. pass `b.host`
to get the host target.122 files changed, 1812 insertions(+), 1338 deletions(-)
build.zig+53-39| ... | ... | @@ -39,10 +39,10 @@ pub fn build(b: *std.Build) !void { |
| 39 | 39 | const docgen_exe = b.addExecutable(.{ |
| 40 | 40 | .name = "docgen", |
| 41 | 41 | .root_source_file = .{ .path = "tools/docgen.zig" }, |
| 42 | .target = .{}, | |
| 42 | .target = b.host, | |
| 43 | 43 | .optimize = .Debug, |
| 44 | .single_threaded = single_threaded, | |
| 44 | 45 | }); |
| 45 | docgen_exe.single_threaded = single_threaded; | |
| 46 | 46 | |
| 47 | 47 | const docgen_cmd = b.addRunArtifact(docgen_exe); |
| 48 | 48 | docgen_cmd.addArgs(&.{ "--zig", b.zig_exe }); |
| ... | ... | @@ -89,11 +89,11 @@ pub fn build(b: *std.Build) !void { |
| 89 | 89 | const check_case_exe = b.addExecutable(.{ |
| 90 | 90 | .name = "check-case", |
| 91 | 91 | .root_source_file = .{ .path = "test/src/Cases.zig" }, |
| 92 | .target = b.host, | |
| 92 | 93 | .optimize = optimize, |
| 93 | .main_mod_path = .{ .path = "." }, | |
| 94 | .single_threaded = single_threaded, | |
| 94 | 95 | }); |
| 95 | 96 | check_case_exe.stack_size = stack_size; |
| 96 | check_case_exe.single_threaded = single_threaded; | |
| 97 | 97 | |
| 98 | 98 | const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; |
| 99 | 99 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; |
| ... | ... | @@ -194,14 +194,18 @@ pub fn build(b: *std.Build) !void { |
| 194 | 194 | break :blk 4; |
| 195 | 195 | }; |
| 196 | 196 | |
| 197 | const exe = addCompilerStep(b, optimize, target); | |
| 198 | exe.strip = strip; | |
| 197 | const exe = addCompilerStep(b, .{ | |
| 198 | .optimize = optimize, | |
| 199 | .target = target, | |
| 200 | .strip = strip, | |
| 201 | .sanitize_thread = sanitize_thread, | |
| 202 | .single_threaded = single_threaded, | |
| 203 | }); | |
| 199 | 204 | exe.pie = pie; |
| 200 | exe.sanitize_thread = sanitize_thread; | |
| 201 | 205 | exe.entitlements = entitlements; |
| 202 | 206 | |
| 203 | 207 | exe.build_id = b.option( |
| 204 | std.Build.Step.Compile.BuildId, | |
| 208 | std.zig.BuildId, | |
| 205 | 209 | "build-id", |
| 206 | 210 | "Request creation of '.note.gnu.build-id' section", |
| 207 | 211 | ); |
| ... | ... | @@ -217,9 +221,7 @@ pub fn build(b: *std.Build) !void { |
| 217 | 221 | |
| 218 | 222 | test_step.dependOn(&exe.step); |
| 219 | 223 | |
| 220 | exe.single_threaded = single_threaded; | |
| 221 | ||
| 222 | if (target.isWindows() and target.getAbi() == .gnu) { | |
| 224 | if (target.target.os.tag == .windows and target.target.abi == .gnu) { | |
| 223 | 225 | // LTO is currently broken on mingw, this can be removed when it's fixed. |
| 224 | 226 | exe.want_lto = false; |
| 225 | 227 | check_case_exe.want_lto = false; |
| ... | ... | @@ -230,7 +232,7 @@ pub fn build(b: *std.Build) !void { |
| 230 | 232 | exe.use_lld = use_llvm; |
| 231 | 233 | |
| 232 | 234 | const exe_options = b.addOptions(); |
| 233 | exe.addOptions("build_options", exe_options); | |
| 235 | exe.root_module.addOptions("build_options", exe_options); | |
| 234 | 236 | |
| 235 | 237 | exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames); |
| 236 | 238 | exe_options.addOption(bool, "skip_non_native", skip_non_native); |
| ... | ... | @@ -345,7 +347,7 @@ pub fn build(b: *std.Build) !void { |
| 345 | 347 | try addStaticLlvmOptionsToExe(exe); |
| 346 | 348 | try addStaticLlvmOptionsToExe(check_case_exe); |
| 347 | 349 | } |
| 348 | if (target.isWindows()) { | |
| 350 | if (target.target.os.tag == .windows) { | |
| 349 | 351 | inline for (.{ exe, check_case_exe }) |artifact| { |
| 350 | 352 | artifact.linkSystemLibrary("version"); |
| 351 | 353 | artifact.linkSystemLibrary("uuid"); |
| ... | ... | @@ -369,7 +371,7 @@ pub fn build(b: *std.Build) !void { |
| 369 | 371 | ); |
| 370 | 372 | |
| 371 | 373 | // On mingw, we need to opt into windows 7+ to get some features required by tracy. |
| 372 | const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu) | |
| 374 | const tracy_c_flags: []const []const u8 = if (target.target.os.tag == .windows and target.target.abi == .gnu) | |
| 373 | 375 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } |
| 374 | 376 | else |
| 375 | 377 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; |
| ... | ... | @@ -377,11 +379,11 @@ pub fn build(b: *std.Build) !void { |
| 377 | 379 | exe.addIncludePath(.{ .cwd_relative = tracy_path }); |
| 378 | 380 | exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); |
| 379 | 381 | if (!enable_llvm) { |
| 380 | exe.linkSystemLibraryName("c++"); | |
| 382 | exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no }); | |
| 381 | 383 | } |
| 382 | 384 | exe.linkLibC(); |
| 383 | 385 | |
| 384 | if (target.isWindows()) { | |
| 386 | if (target.target.os.tag == .windows) { | |
| 385 | 387 | exe.linkSystemLibrary("dbghelp"); |
| 386 | 388 | exe.linkSystemLibrary("ws2_32"); |
| 387 | 389 | } |
| ... | ... | @@ -390,7 +392,7 @@ pub fn build(b: *std.Build) !void { |
| 390 | 392 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); |
| 391 | 393 | |
| 392 | 394 | const test_cases_options = b.addOptions(); |
| 393 | check_case_exe.addOptions("build_options", test_cases_options); | |
| 395 | check_case_exe.root_module.addOptions("build_options", test_cases_options); | |
| 394 | 396 | |
| 395 | 397 | test_cases_options.addOption(bool, "enable_tracy", false); |
| 396 | 398 | test_cases_options.addOption(bool, "enable_logging", enable_logging); |
| ... | ... | @@ -540,16 +542,19 @@ pub fn build(b: *std.Build) !void { |
| 540 | 542 | fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { |
| 541 | 543 | const semver = try std.SemanticVersion.parse(version); |
| 542 | 544 | |
| 543 | var target: std.zig.CrossTarget = .{ | |
| 545 | var target_query: std.zig.CrossTarget = .{ | |
| 544 | 546 | .cpu_arch = .wasm32, |
| 545 | 547 | .os_tag = .wasi, |
| 546 | 548 | }; |
| 547 | target.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory)); | |
| 549 | target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory)); | |
| 548 | 550 | |
| 549 | const exe = addCompilerStep(b, .ReleaseSmall, target); | |
| 551 | const exe = addCompilerStep(b, .{ | |
| 552 | .optimize = .ReleaseSmall, | |
| 553 | .target = b.resolveTargetQuery(target_query), | |
| 554 | }); | |
| 550 | 555 | |
| 551 | 556 | const exe_options = b.addOptions(); |
| 552 | exe.addOptions("build_options", exe_options); | |
| 557 | exe.root_module.addOptions("build_options", exe_options); | |
| 553 | 558 | |
| 554 | 559 | exe_options.addOption(u32, "mem_leak_frames", 0); |
| 555 | 560 | exe_options.addOption(bool, "have_llvm", false); |
| ... | ... | @@ -584,17 +589,24 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { |
| 584 | 589 | update_zig1_step.dependOn(&copy_zig_h.step); |
| 585 | 590 | } |
| 586 | 591 | |
| 587 | fn addCompilerStep( | |
| 588 | b: *std.Build, | |
| 592 | const AddCompilerStepOptions = struct { | |
| 589 | 593 | optimize: std.builtin.OptimizeMode, |
| 590 | target: std.zig.CrossTarget, | |
| 591 | ) *std.Build.Step.Compile { | |
| 594 | target: std.Build.ResolvedTarget, | |
| 595 | strip: ?bool = null, | |
| 596 | sanitize_thread: ?bool = null, | |
| 597 | single_threaded: ?bool = null, | |
| 598 | }; | |
| 599 | ||
| 600 | fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { | |
| 592 | 601 | const exe = b.addExecutable(.{ |
| 593 | 602 | .name = "zig", |
| 594 | 603 | .root_source_file = .{ .path = "src/main.zig" }, |
| 595 | .target = target, | |
| 596 | .optimize = optimize, | |
| 604 | .target = options.target, | |
| 605 | .optimize = options.optimize, | |
| 597 | 606 | .max_rss = 7_000_000_000, |
| 607 | .strip = options.strip, | |
| 608 | .sanitize_thread = options.sanitize_thread, | |
| 609 | .single_threaded = options.single_threaded, | |
| 598 | 610 | }); |
| 599 | 611 | exe.stack_size = stack_size; |
| 600 | 612 | |
| ... | ... | @@ -602,15 +614,15 @@ fn addCompilerStep( |
| 602 | 614 | aro_options.addOption([]const u8, "version_str", "aro-zig"); |
| 603 | 615 | const aro_options_module = aro_options.createModule(); |
| 604 | 616 | const aro_backend = b.createModule(.{ |
| 605 | .source_file = .{ .path = "deps/aro/backend.zig" }, | |
| 606 | .dependencies = &.{.{ | |
| 617 | .root_source_file = .{ .path = "deps/aro/backend.zig" }, | |
| 618 | .imports = &.{.{ | |
| 607 | 619 | .name = "build_options", |
| 608 | 620 | .module = aro_options_module, |
| 609 | 621 | }}, |
| 610 | 622 | }); |
| 611 | 623 | const aro_module = b.createModule(.{ |
| 612 | .source_file = .{ .path = "deps/aro/aro.zig" }, | |
| 613 | .dependencies = &.{ | |
| 624 | .root_source_file = .{ .path = "deps/aro/aro.zig" }, | |
| 625 | .imports = &.{ | |
| 614 | 626 | .{ |
| 615 | 627 | .name = "build_options", |
| 616 | 628 | .module = aro_options_module, |
| ... | ... | @@ -625,7 +637,7 @@ fn addCompilerStep( |
| 625 | 637 | }, |
| 626 | 638 | }); |
| 627 | 639 | |
| 628 | exe.addModule("aro", aro_module); | |
| 640 | exe.root_module.addImport("aro", aro_module); | |
| 629 | 641 | return exe; |
| 630 | 642 | } |
| 631 | 643 | |
| ... | ... | @@ -649,7 +661,7 @@ fn addCmakeCfgOptionsToExe( |
| 649 | 661 | exe: *std.Build.Step.Compile, |
| 650 | 662 | use_zig_libcxx: bool, |
| 651 | 663 | ) !void { |
| 652 | if (exe.target.isDarwin()) { | |
| 664 | if (exe.rootModuleTarget().isDarwin()) { | |
| 653 | 665 | // useful for package maintainers |
| 654 | 666 | exe.headerpad_max_install_names = true; |
| 655 | 667 | } |
| ... | ... | @@ -677,8 +689,8 @@ fn addCmakeCfgOptionsToExe( |
| 677 | 689 | // against system-provided LLVM, Clang, LLD. |
| 678 | 690 | const need_cpp_includes = true; |
| 679 | 691 | const static = cfg.llvm_linkage == .static; |
| 680 | const lib_suffix = if (static) exe.target.staticLibSuffix()[1..] else exe.target.dynamicLibSuffix()[1..]; | |
| 681 | switch (exe.target.getOsTag()) { | |
| 692 | const lib_suffix = if (static) exe.rootModuleTarget().staticLibSuffix()[1..] else exe.rootModuleTarget().dynamicLibSuffix()[1..]; | |
| 693 | switch (exe.rootModuleTarget().os.tag) { | |
| 682 | 694 | .linux => { |
| 683 | 695 | // First we try to link against the detected libcxx name. If that doesn't work, we fall |
| 684 | 696 | // back to -lc++ and cross our fingers. |
| ... | ... | @@ -694,7 +706,7 @@ fn addCmakeCfgOptionsToExe( |
| 694 | 706 | exe.linkLibCpp(); |
| 695 | 707 | }, |
| 696 | 708 | .windows => { |
| 697 | if (exe.target.getAbi() != .msvc) exe.linkLibCpp(); | |
| 709 | if (exe.rootModuleTarget().abi != .msvc) exe.linkLibCpp(); | |
| 698 | 710 | }, |
| 699 | 711 | .freebsd => { |
| 700 | 712 | if (static) { |
| ... | ... | @@ -756,12 +768,12 @@ fn addStaticLlvmOptionsToExe(exe: *std.Build.Step.Compile) !void { |
| 756 | 768 | exe.linkSystemLibrary("z"); |
| 757 | 769 | exe.linkSystemLibrary("zstd"); |
| 758 | 770 | |
| 759 | if (exe.target.getOs().tag != .windows or exe.target.getAbi() != .msvc) { | |
| 771 | if (exe.rootModuleTarget().os.tag != .windows or exe.rootModuleTarget().abi != .msvc) { | |
| 760 | 772 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. |
| 761 | 773 | exe.linkSystemLibrary("c++"); |
| 762 | 774 | } |
| 763 | 775 | |
| 764 | if (exe.target.getOs().tag == .windows) { | |
| 776 | if (exe.rootModuleTarget().os.tag == .windows) { | |
| 765 | 777 | exe.linkSystemLibrary("version"); |
| 766 | 778 | exe.linkSystemLibrary("uuid"); |
| 767 | 779 | exe.linkSystemLibrary("ole32"); |
| ... | ... | @@ -810,7 +822,9 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void { |
| 810 | 822 | while (it.next()) |lib| { |
| 811 | 823 | if (mem.startsWith(u8, lib, "-l")) { |
| 812 | 824 | exe.linkSystemLibrary(lib["-l".len..]); |
| 813 | } else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) { | |
| 825 | } else if (exe.rootModuleTarget().os.tag == .windows and | |
| 826 | mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) | |
| 827 | { | |
| 814 | 828 | exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]); |
| 815 | 829 | } else { |
| 816 | 830 | exe.addObjectFile(.{ .cwd_relative = lib }); |
deps/aro/build/GenerateDef.zig+2-2| ... | ... | @@ -21,7 +21,7 @@ pub const Options = struct { |
| 21 | 21 | pub const Kind = enum { dafsa, named }; |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | pub fn create(owner: *std.Build, options: Options) std.Build.ModuleDependency { | |
| 24 | pub fn create(owner: *std.Build, options: Options) std.Build.Module.Import { | |
| 25 | 25 | const self = owner.allocator.create(GenerateDef) catch @panic("OOM"); |
| 26 | 26 | const path = owner.pathJoin(&.{ options.src_prefix, options.name }); |
| 27 | 27 | |
| ... | ... | @@ -39,7 +39,7 @@ pub fn create(owner: *std.Build, options: Options) std.Build.ModuleDependency { |
| 39 | 39 | .generated_file = .{ .step = &self.step }, |
| 40 | 40 | }; |
| 41 | 41 | const module = self.step.owner.createModule(.{ |
| 42 | .source_file = .{ .generated = &self.generated_file }, | |
| 42 | .root_source_file = .{ .generated = &self.generated_file }, | |
| 43 | 43 | }); |
| 44 | 44 | return .{ |
| 45 | 45 | .module = module, |
lib/build_runner.zig+6-1| ... | ... | @@ -46,7 +46,12 @@ pub fn main() !void { |
| 46 | 46 | return error.InvalidArgs; |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); | |
| 49 | const detected = try std.zig.system.NativeTargetInfo.detect(.{}); | |
| 50 | const host: std.Build.ResolvedTarget = .{ | |
| 51 | .query = .{}, | |
| 52 | .target = detected.target, | |
| 53 | .dynamic_linker = detected.dynamic_linker, | |
| 54 | }; | |
| 50 | 55 | |
| 51 | 56 | const build_root_directory: std.Build.Cache.Directory = .{ |
| 52 | 57 | .path = build_root, |
lib/std/Build.zig+129-48| ... | ... | @@ -14,20 +14,11 @@ const process = std.process; |
| 14 | 14 | const EnvMap = std.process.EnvMap; |
| 15 | 15 | const fmt_lib = std.fmt; |
| 16 | 16 | const File = std.fs.File; |
| 17 | const CrossTarget = std.zig.CrossTarget; | |
| 18 | const NativeTargetInfo = std.zig.system.NativeTargetInfo; | |
| 17 | const TargetQuery = std.zig.CrossTarget; | |
| 19 | 18 | const Sha256 = std.crypto.hash.sha2.Sha256; |
| 20 | 19 | const Build = @This(); |
| 21 | 20 | |
| 22 | 21 | pub const Cache = @import("Build/Cache.zig"); |
| 23 | ||
| 24 | /// deprecated: use `Step.Compile`. | |
| 25 | pub const LibExeObjStep = Step.Compile; | |
| 26 | /// deprecated: use `Build`. | |
| 27 | pub const Builder = Build; | |
| 28 | /// deprecated: use `Step.InstallDir.Options` | |
| 29 | pub const InstallDirectoryOptions = Step.InstallDir.Options; | |
| 30 | ||
| 31 | 22 | pub const Step = @import("Build/Step.zig"); |
| 32 | 23 | pub const Module = @import("Build/Module.zig"); |
| 33 | 24 | |
| ... | ... | @@ -94,7 +85,7 @@ enable_wine: bool = false, |
| 94 | 85 | glibc_runtimes_dir: ?[]const u8 = null, |
| 95 | 86 | |
| 96 | 87 | /// Information about the native target. Computed before build() is invoked. |
| 97 | host: NativeTargetInfo, | |
| 88 | host: ResolvedTarget, | |
| 98 | 89 | |
| 99 | 90 | dep_prefix: []const u8 = "", |
| 100 | 91 | |
| ... | ... | @@ -220,7 +211,7 @@ pub fn create( |
| 220 | 211 | build_root: Cache.Directory, |
| 221 | 212 | cache_root: Cache.Directory, |
| 222 | 213 | global_cache_root: Cache.Directory, |
| 223 | host: NativeTargetInfo, | |
| 214 | host: ResolvedTarget, | |
| 224 | 215 | cache: *Cache, |
| 225 | 216 | available_deps: AvailableDeps, |
| 226 | 217 | ) !*Build { |
| ... | ... | @@ -384,7 +375,7 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption |
| 384 | 375 | const v = @field(args, field.name); |
| 385 | 376 | const T = @TypeOf(v); |
| 386 | 377 | switch (T) { |
| 387 | CrossTarget => { | |
| 378 | TargetQuery => { | |
| 388 | 379 | user_input_options.put(field.name, .{ |
| 389 | 380 | .name = field.name, |
| 390 | 381 | .value = .{ .scalar = v.zigTriple(allocator) catch @panic("OOM") }, |
| ... | ... | @@ -593,14 +584,22 @@ pub fn addOptions(self: *Build) *Step.Options { |
| 593 | 584 | |
| 594 | 585 | pub const ExecutableOptions = struct { |
| 595 | 586 | name: []const u8, |
| 587 | /// If you want the executable to run on the same computer as the one | |
| 588 | /// building the package, pass the `host` field of the package's `Build` | |
| 589 | /// instance. | |
| 590 | target: ResolvedTarget, | |
| 596 | 591 | root_source_file: ?LazyPath = null, |
| 597 | 592 | version: ?std.SemanticVersion = null, |
| 598 | target: CrossTarget = .{}, | |
| 599 | 593 | optimize: std.builtin.OptimizeMode = .Debug, |
| 600 | 594 | linkage: ?Step.Compile.Linkage = null, |
| 601 | 595 | max_rss: usize = 0, |
| 602 | 596 | link_libc: ?bool = null, |
| 603 | 597 | single_threaded: ?bool = null, |
| 598 | pic: ?bool = null, | |
| 599 | strip: ?bool = null, | |
| 600 | unwind_tables: ?bool = null, | |
| 601 | omit_frame_pointer: ?bool = null, | |
| 602 | sanitize_thread: ?bool = null, | |
| 604 | 603 | use_llvm: ?bool = null, |
| 605 | 604 | use_lld: ?bool = null, |
| 606 | 605 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -621,6 +620,11 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 621 | 620 | .optimize = options.optimize, |
| 622 | 621 | .link_libc = options.link_libc, |
| 623 | 622 | .single_threaded = options.single_threaded, |
| 623 | .pic = options.pic, | |
| 624 | .strip = options.strip, | |
| 625 | .unwind_tables = options.unwind_tables, | |
| 626 | .omit_frame_pointer = options.omit_frame_pointer, | |
| 627 | .sanitize_thread = options.sanitize_thread, | |
| 624 | 628 | }, |
| 625 | 629 | .version = options.version, |
| 626 | 630 | .kind = .exe, |
| ... | ... | @@ -636,11 +640,18 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 636 | 640 | pub const ObjectOptions = struct { |
| 637 | 641 | name: []const u8, |
| 638 | 642 | root_source_file: ?LazyPath = null, |
| 639 | target: CrossTarget, | |
| 643 | /// To choose the same computer as the one building the package, pass the | |
| 644 | /// `host` field of the package's `Build` instance. | |
| 645 | target: ResolvedTarget, | |
| 640 | 646 | optimize: std.builtin.OptimizeMode, |
| 641 | 647 | max_rss: usize = 0, |
| 642 | 648 | link_libc: ?bool = null, |
| 643 | 649 | single_threaded: ?bool = null, |
| 650 | pic: ?bool = null, | |
| 651 | strip: ?bool = null, | |
| 652 | unwind_tables: ?bool = null, | |
| 653 | omit_frame_pointer: ?bool = null, | |
| 654 | sanitize_thread: ?bool = null, | |
| 644 | 655 | use_llvm: ?bool = null, |
| 645 | 656 | use_lld: ?bool = null, |
| 646 | 657 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -655,6 +666,11 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 655 | 666 | .optimize = options.optimize, |
| 656 | 667 | .link_libc = options.link_libc, |
| 657 | 668 | .single_threaded = options.single_threaded, |
| 669 | .pic = options.pic, | |
| 670 | .strip = options.strip, | |
| 671 | .unwind_tables = options.unwind_tables, | |
| 672 | .omit_frame_pointer = options.omit_frame_pointer, | |
| 673 | .sanitize_thread = options.sanitize_thread, | |
| 658 | 674 | }, |
| 659 | 675 | .kind = .obj, |
| 660 | 676 | .max_rss = options.max_rss, |
| ... | ... | @@ -666,13 +682,20 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 666 | 682 | |
| 667 | 683 | pub const SharedLibraryOptions = struct { |
| 668 | 684 | name: []const u8, |
| 685 | /// To choose the same computer as the one building the package, pass the | |
| 686 | /// `host` field of the package's `Build` instance. | |
| 687 | target: ResolvedTarget, | |
| 688 | optimize: std.builtin.OptimizeMode, | |
| 669 | 689 | root_source_file: ?LazyPath = null, |
| 670 | 690 | version: ?std.SemanticVersion = null, |
| 671 | target: CrossTarget, | |
| 672 | optimize: std.builtin.OptimizeMode, | |
| 673 | 691 | max_rss: usize = 0, |
| 674 | 692 | link_libc: ?bool = null, |
| 675 | 693 | single_threaded: ?bool = null, |
| 694 | pic: ?bool = null, | |
| 695 | strip: ?bool = null, | |
| 696 | unwind_tables: ?bool = null, | |
| 697 | omit_frame_pointer: ?bool = null, | |
| 698 | sanitize_thread: ?bool = null, | |
| 676 | 699 | use_llvm: ?bool = null, |
| 677 | 700 | use_lld: ?bool = null, |
| 678 | 701 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -693,6 +716,11 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 693 | 716 | .root_source_file = options.root_source_file, |
| 694 | 717 | .link_libc = options.link_libc, |
| 695 | 718 | .single_threaded = options.single_threaded, |
| 719 | .pic = options.pic, | |
| 720 | .strip = options.strip, | |
| 721 | .unwind_tables = options.unwind_tables, | |
| 722 | .omit_frame_pointer = options.omit_frame_pointer, | |
| 723 | .sanitize_thread = options.sanitize_thread, | |
| 696 | 724 | }, |
| 697 | 725 | .kind = .lib, |
| 698 | 726 | .linkage = .dynamic, |
| ... | ... | @@ -708,12 +736,19 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 708 | 736 | pub const StaticLibraryOptions = struct { |
| 709 | 737 | name: []const u8, |
| 710 | 738 | root_source_file: ?LazyPath = null, |
| 711 | target: CrossTarget, | |
| 739 | /// To choose the same computer as the one building the package, pass the | |
| 740 | /// `host` field of the package's `Build` instance. | |
| 741 | target: ResolvedTarget, | |
| 712 | 742 | optimize: std.builtin.OptimizeMode, |
| 713 | 743 | version: ?std.SemanticVersion = null, |
| 714 | 744 | max_rss: usize = 0, |
| 715 | 745 | link_libc: ?bool = null, |
| 716 | 746 | single_threaded: ?bool = null, |
| 747 | pic: ?bool = null, | |
| 748 | strip: ?bool = null, | |
| 749 | unwind_tables: ?bool = null, | |
| 750 | omit_frame_pointer: ?bool = null, | |
| 751 | sanitize_thread: ?bool = null, | |
| 717 | 752 | use_llvm: ?bool = null, |
| 718 | 753 | use_lld: ?bool = null, |
| 719 | 754 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -728,6 +763,11 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 728 | 763 | .root_source_file = options.root_source_file, |
| 729 | 764 | .link_libc = options.link_libc, |
| 730 | 765 | .single_threaded = options.single_threaded, |
| 766 | .pic = options.pic, | |
| 767 | .strip = options.strip, | |
| 768 | .unwind_tables = options.unwind_tables, | |
| 769 | .omit_frame_pointer = options.omit_frame_pointer, | |
| 770 | .sanitize_thread = options.sanitize_thread, | |
| 731 | 771 | }, |
| 732 | 772 | .kind = .lib, |
| 733 | 773 | .linkage = .static, |
| ... | ... | @@ -742,7 +782,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 742 | 782 | pub const TestOptions = struct { |
| 743 | 783 | name: []const u8 = "test", |
| 744 | 784 | root_source_file: LazyPath, |
| 745 | target: CrossTarget = .{}, | |
| 785 | target: ?ResolvedTarget = null, | |
| 746 | 786 | optimize: std.builtin.OptimizeMode = .Debug, |
| 747 | 787 | version: ?std.SemanticVersion = null, |
| 748 | 788 | max_rss: usize = 0, |
| ... | ... | @@ -750,6 +790,11 @@ pub const TestOptions = struct { |
| 750 | 790 | test_runner: ?[]const u8 = null, |
| 751 | 791 | link_libc: ?bool = null, |
| 752 | 792 | single_threaded: ?bool = null, |
| 793 | pic: ?bool = null, | |
| 794 | strip: ?bool = null, | |
| 795 | unwind_tables: ?bool = null, | |
| 796 | omit_frame_pointer: ?bool = null, | |
| 797 | sanitize_thread: ?bool = null, | |
| 753 | 798 | use_llvm: ?bool = null, |
| 754 | 799 | use_lld: ?bool = null, |
| 755 | 800 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -761,10 +806,15 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 761 | 806 | .kind = .@"test", |
| 762 | 807 | .root_module = .{ |
| 763 | 808 | .root_source_file = options.root_source_file, |
| 764 | .target = options.target, | |
| 809 | .target = options.target orelse b.host, | |
| 765 | 810 | .optimize = options.optimize, |
| 766 | 811 | .link_libc = options.link_libc, |
| 767 | 812 | .single_threaded = options.single_threaded, |
| 813 | .pic = options.pic, | |
| 814 | .strip = options.strip, | |
| 815 | .unwind_tables = options.unwind_tables, | |
| 816 | .omit_frame_pointer = options.omit_frame_pointer, | |
| 817 | .sanitize_thread = options.sanitize_thread, | |
| 768 | 818 | }, |
| 769 | 819 | .max_rss = options.max_rss, |
| 770 | 820 | .filter = options.filter, |
| ... | ... | @@ -778,7 +828,9 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 778 | 828 | pub const AssemblyOptions = struct { |
| 779 | 829 | name: []const u8, |
| 780 | 830 | source_file: LazyPath, |
| 781 | target: CrossTarget, | |
| 831 | /// To choose the same computer as the one building the package, pass the | |
| 832 | /// `host` field of the package's `Build` instance. | |
| 833 | target: ResolvedTarget, | |
| 782 | 834 | optimize: std.builtin.OptimizeMode, |
| 783 | 835 | max_rss: usize = 0, |
| 784 | 836 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -1061,7 +1113,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1061 | 1113 | return null; |
| 1062 | 1114 | }, |
| 1063 | 1115 | .scalar => |s| { |
| 1064 | if (Step.Compile.BuildId.parse(s)) |build_id| { | |
| 1116 | if (std.zig.BuildId.parse(s)) |build_id| { | |
| 1065 | 1117 | return build_id; |
| 1066 | 1118 | } else |err| { |
| 1067 | 1119 | log.err("unable to parse option '-D{s}': {s}", .{ name, @errorName(err) }); |
| ... | ... | @@ -1126,13 +1178,20 @@ pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptio |
| 1126 | 1178 | } |
| 1127 | 1179 | |
| 1128 | 1180 | pub const StandardTargetOptionsArgs = struct { |
| 1129 | whitelist: ?[]const CrossTarget = null, | |
| 1181 | whitelist: ?[]const TargetQuery = null, | |
| 1130 | 1182 | |
| 1131 | default_target: CrossTarget = CrossTarget{}, | |
| 1183 | default_target: TargetQuery = .{}, | |
| 1132 | 1184 | }; |
| 1133 | 1185 | |
| 1186 | /// Exposes standard `zig build` options for choosing a target and additionally | |
| 1187 | /// resolves the target query. | |
| 1188 | pub fn standardTargetOptions(b: *Build, args: StandardTargetOptionsArgs) ResolvedTarget { | |
| 1189 | const query = b.standardTargetOptionsQueryOnly(args); | |
| 1190 | return b.resolveTargetQuery(query); | |
| 1191 | } | |
| 1192 | ||
| 1134 | 1193 | /// Exposes standard `zig build` options for choosing a target. |
| 1135 | pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) CrossTarget { | |
| 1194 | pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsArgs) TargetQuery { | |
| 1136 | 1195 | const maybe_triple = self.option( |
| 1137 | 1196 | []const u8, |
| 1138 | 1197 | "target", |
| ... | ... | @@ -1146,8 +1205,8 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros |
| 1146 | 1205 | |
| 1147 | 1206 | const triple = maybe_triple orelse "native"; |
| 1148 | 1207 | |
| 1149 | var diags: CrossTarget.ParseOptions.Diagnostics = .{}; | |
| 1150 | const selected_target = CrossTarget.parse(.{ | |
| 1208 | var diags: TargetQuery.ParseOptions.Diagnostics = .{}; | |
| 1209 | const selected_target = TargetQuery.parse(.{ | |
| 1151 | 1210 | .arch_os_abi = triple, |
| 1152 | 1211 | .cpu_features = mcpu, |
| 1153 | 1212 | .diagnostics = &diags, |
| ... | ... | @@ -1203,7 +1262,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros |
| 1203 | 1262 | // Make sure it's a match of one of the list. |
| 1204 | 1263 | var mismatch_triple = true; |
| 1205 | 1264 | var mismatch_cpu_features = true; |
| 1206 | var whitelist_item = CrossTarget{}; | |
| 1265 | var whitelist_item: TargetQuery = .{}; | |
| 1207 | 1266 | for (list) |t| { |
| 1208 | 1267 | mismatch_cpu_features = true; |
| 1209 | 1268 | mismatch_triple = true; |
| ... | ... | @@ -1340,7 +1399,7 @@ pub fn addUserInputFlag(self: *Build, name_raw: []const u8) !bool { |
| 1340 | 1399 | |
| 1341 | 1400 | fn typeToEnum(comptime T: type) TypeId { |
| 1342 | 1401 | return switch (T) { |
| 1343 | Step.Compile.BuildId => .build_id, | |
| 1402 | std.zig.BuildId => .build_id, | |
| 1344 | 1403 | else => return switch (@typeInfo(T)) { |
| 1345 | 1404 | .Int => .int, |
| 1346 | 1405 | .Float => .float, |
| ... | ... | @@ -1408,7 +1467,7 @@ pub fn installFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8 |
| 1408 | 1467 | self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .prefix, dest_rel_path).step); |
| 1409 | 1468 | } |
| 1410 | 1469 | |
| 1411 | pub fn installDirectory(self: *Build, options: InstallDirectoryOptions) void { | |
| 1470 | pub fn installDirectory(self: *Build, options: Step.InstallDir.Options) void { | |
| 1412 | 1471 | self.getInstallStep().dependOn(&self.addInstallDirectory(options).step); |
| 1413 | 1472 | } |
| 1414 | 1473 | |
| ... | ... | @@ -1454,7 +1513,7 @@ pub fn addInstallFileWithDir( |
| 1454 | 1513 | return Step.InstallFile.create(self, source.dupe(self), install_dir, dest_rel_path); |
| 1455 | 1514 | } |
| 1456 | 1515 | |
| 1457 | pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step.InstallDir { | |
| 1516 | pub fn addInstallDirectory(self: *Build, options: Step.InstallDir.Options) *Step.InstallDir { | |
| 1458 | 1517 | return Step.InstallDir.create(self, options); |
| 1459 | 1518 | } |
| 1460 | 1519 | |
| ... | ... | @@ -1511,7 +1570,7 @@ pub fn fmt(self: *Build, comptime format: []const u8, args: anytype) []u8 { |
| 1511 | 1570 | |
| 1512 | 1571 | pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 { |
| 1513 | 1572 | // TODO report error for ambiguous situations |
| 1514 | const exe_extension = @as(CrossTarget, .{}).exeFileExt(); | |
| 1573 | const exe_extension = @as(TargetQuery, .{}).exeFileExt(); | |
| 1515 | 1574 | for (self.search_prefixes.items) |search_prefix| { |
| 1516 | 1575 | for (names) |name| { |
| 1517 | 1576 | if (fs.path.isAbsolute(name)) { |
| ... | ... | @@ -1957,22 +2016,6 @@ pub fn dumpBadGetPathHelp( |
| 1957 | 2016 | tty_config.setColor(w, .reset) catch {}; |
| 1958 | 2017 | } |
| 1959 | 2018 | |
| 1960 | /// Allocates a new string for assigning a value to a named macro. | |
| 1961 | /// If the value is omitted, it is set to 1. | |
| 1962 | /// `name` and `value` need not live longer than the function call. | |
| 1963 | pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u8) []const u8 { | |
| 1964 | var macro = allocator.alloc( | |
| 1965 | u8, | |
| 1966 | name.len + if (value) |value_slice| value_slice.len + 1 else 0, | |
| 1967 | ) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable; | |
| 1968 | @memcpy(macro[0..name.len], name); | |
| 1969 | if (value) |value_slice| { | |
| 1970 | macro[name.len] = '='; | |
| 1971 | @memcpy(macro[name.len + 1 ..][0..value_slice.len], value_slice); | |
| 1972 | } | |
| 1973 | return macro; | |
| 1974 | } | |
| 1975 | ||
| 1976 | 2019 | pub const InstallDir = union(enum) { |
| 1977 | 2020 | prefix: void, |
| 1978 | 2021 | lib: void, |
| ... | ... | @@ -2062,6 +2105,44 @@ pub fn hex64(x: u64) [16]u8 { |
| 2062 | 2105 | return result; |
| 2063 | 2106 | } |
| 2064 | 2107 | |
| 2108 | /// A pair of target query and fully resolved target. | |
| 2109 | /// This type is generally required by build system API that need to be given a | |
| 2110 | /// target. The query is kept because the Zig toolchain needs to know which parts | |
| 2111 | /// of the target are "native". This can apply to the CPU, the OS, or even the ABI. | |
| 2112 | pub const ResolvedTarget = struct { | |
| 2113 | query: TargetQuery, | |
| 2114 | target: std.Target, | |
| 2115 | dynamic_linker: std.Target.DynamicLinker, | |
| 2116 | ||
| 2117 | pub fn toNativeTargetInfo(self: ResolvedTarget) std.zig.system.NativeTargetInfo { | |
| 2118 | return .{ | |
| 2119 | .target = self.target, | |
| 2120 | .dynamic_linker = self.dynamic_linker, | |
| 2121 | }; | |
| 2122 | } | |
| 2123 | }; | |
| 2124 | ||
| 2125 | /// Converts a target query into a fully resolved target that can be passed to | |
| 2126 | /// various parts of the API. | |
| 2127 | pub fn resolveTargetQuery(b: *Build, query: TargetQuery) ResolvedTarget { | |
| 2128 | // This context will likely be required in the future when the target is | |
| 2129 | // resolved via a WASI API or via the build protocol. | |
| 2130 | _ = b; | |
| 2131 | ||
| 2132 | const result = std.zig.system.NativeTargetInfo.detect(query) catch | |
| 2133 | @panic("unable to resolve target query"); | |
| 2134 | ||
| 2135 | return .{ | |
| 2136 | .query = query, | |
| 2137 | .target = result.target, | |
| 2138 | .dynamic_linker = result.dynamic_linker, | |
| 2139 | }; | |
| 2140 | } | |
| 2141 | ||
| 2142 | pub fn wantSharedLibSymLinks(target: std.Target) bool { | |
| 2143 | return target.os.tag != .windows; | |
| 2144 | } | |
| 2145 | ||
| 2065 | 2146 | test { |
| 2066 | 2147 | _ = Cache; |
| 2067 | 2148 | _ = Step; |
lib/std/Build/Cache.zig+1-1| ... | ... | @@ -270,7 +270,7 @@ pub const HashHelper = struct { |
| 270 | 270 | .none => {}, |
| 271 | 271 | } |
| 272 | 272 | }, |
| 273 | std.Build.Step.Compile.BuildId => switch (x) { | |
| 273 | std.zig.BuildId => switch (x) { | |
| 274 | 274 | .none, .fast, .uuid, .sha1, .md5 => hh.add(std.meta.activeTag(x)), |
| 275 | 275 | .hexstring => |hex_string| hh.addBytes(hex_string.toSlice()), |
| 276 | 276 | }, |
lib/std/Build/Module.zig+239-108| ... | ... | @@ -3,27 +3,24 @@ owner: *std.Build, |
| 3 | 3 | /// Tracks the set of steps that depend on this `Module`. This ensures that |
| 4 | 4 | /// when making this `Module` depend on other `Module` objects and `Step` |
| 5 | 5 | /// objects, respective `Step` dependencies can be added. |
| 6 | depending_steps: std.AutoArrayHashMapUnmanaged(*std.Build.Step.Compile, void), | |
| 7 | /// This could either be a generated file, in which case the module | |
| 8 | /// contains exactly one file, or it could be a path to the root source | |
| 9 | /// file of directory of files which constitute the module. | |
| 10 | /// If `null`, it means this module is made up of only `link_objects`. | |
| 6 | depending_steps: std.AutoArrayHashMapUnmanaged(*Step.Compile, void), | |
| 11 | 7 | root_source_file: ?LazyPath, |
| 12 | 8 | /// The modules that are mapped into this module's import table. |
| 13 | import_table: std.StringArrayHashMap(*Module), | |
| 9 | /// Use `addImport` rather than modifying this field directly in order to | |
| 10 | /// maintain step dependency edges. | |
| 11 | import_table: std.StringArrayHashMapUnmanaged(*Module), | |
| 14 | 12 | |
| 15 | target: std.zig.CrossTarget, | |
| 16 | target_info: NativeTargetInfo, | |
| 17 | optimize: std.builtin.OptimizeMode, | |
| 13 | target: ?std.Build.ResolvedTarget = null, | |
| 14 | optimize: ?std.builtin.OptimizeMode = null, | |
| 18 | 15 | dwarf_format: ?std.dwarf.Format, |
| 19 | 16 | |
| 20 | c_macros: std.ArrayList([]const u8), | |
| 21 | include_dirs: std.ArrayList(IncludeDir), | |
| 22 | lib_paths: std.ArrayList(LazyPath), | |
| 23 | rpaths: std.ArrayList(LazyPath), | |
| 24 | frameworks: std.StringArrayHashMapUnmanaged(FrameworkLinkInfo), | |
| 17 | c_macros: std.ArrayListUnmanaged([]const u8), | |
| 18 | include_dirs: std.ArrayListUnmanaged(IncludeDir), | |
| 19 | lib_paths: std.ArrayListUnmanaged(LazyPath), | |
| 20 | rpaths: std.ArrayListUnmanaged(RPath), | |
| 21 | frameworks: std.StringArrayHashMapUnmanaged(LinkFrameworkOptions), | |
| 25 | 22 | c_std: std.Build.CStd, |
| 26 | link_objects: std.ArrayList(LinkObject), | |
| 23 | link_objects: std.ArrayListUnmanaged(LinkObject), | |
| 27 | 24 | |
| 28 | 25 | strip: ?bool, |
| 29 | 26 | unwind_tables: ?bool, |
| ... | ... | @@ -53,9 +50,14 @@ link_libcpp: ?bool, |
| 53 | 50 | /// Symbols to be exported when compiling to WebAssembly. |
| 54 | 51 | export_symbol_names: []const []const u8 = &.{}, |
| 55 | 52 | |
| 53 | pub const RPath = union(enum) { | |
| 54 | lazy_path: LazyPath, | |
| 55 | special: []const u8, | |
| 56 | }; | |
| 57 | ||
| 56 | 58 | pub const LinkObject = union(enum) { |
| 57 | 59 | static_path: LazyPath, |
| 58 | other_step: *std.Build.Step.Compile, | |
| 60 | other_step: *Step.Compile, | |
| 59 | 61 | system_lib: SystemLib, |
| 60 | 62 | assembly_file: LazyPath, |
| 61 | 63 | c_source_file: *CSourceFile, |
| ... | ... | @@ -133,21 +135,32 @@ pub const IncludeDir = union(enum) { |
| 133 | 135 | path_after: LazyPath, |
| 134 | 136 | framework_path: LazyPath, |
| 135 | 137 | framework_path_system: LazyPath, |
| 136 | other_step: *std.Build.Step.Compile, | |
| 137 | config_header_step: *std.Build.Step.ConfigHeader, | |
| 138 | other_step: *Step.Compile, | |
| 139 | config_header_step: *Step.ConfigHeader, | |
| 138 | 140 | }; |
| 139 | 141 | |
| 140 | pub const FrameworkLinkInfo = struct { | |
| 142 | pub const LinkFrameworkOptions = struct { | |
| 141 | 143 | needed: bool = false, |
| 142 | 144 | weak: bool = false, |
| 143 | 145 | }; |
| 144 | 146 | |
| 147 | /// Unspecified options here will be inherited from parent `Module` when | |
| 148 | /// inserted into an import table. | |
| 145 | 149 | pub const CreateOptions = struct { |
| 146 | target: std.zig.CrossTarget, | |
| 147 | target_info: ?NativeTargetInfo = null, | |
| 148 | optimize: std.builtin.OptimizeMode, | |
| 150 | /// This could either be a generated file, in which case the module | |
| 151 | /// contains exactly one file, or it could be a path to the root source | |
| 152 | /// file of directory of files which constitute the module. | |
| 153 | /// If `null`, it means this module is made up of only `link_objects`. | |
| 149 | 154 | root_source_file: ?LazyPath = null, |
| 150 | import_table: []const Import = &.{}, | |
| 155 | ||
| 156 | /// The table of other modules that this module can access via `@import`. | |
| 157 | /// Imports are allowed to be cyclical, so this table can be added to after | |
| 158 | /// the `Module` is created via `addImport`. | |
| 159 | imports: []const Import = &.{}, | |
| 160 | ||
| 161 | target: ?std.Build.ResolvedTarget = null, | |
| 162 | optimize: ?std.builtin.OptimizeMode = null, | |
| 163 | ||
| 151 | 164 | link_libc: ?bool = null, |
| 152 | 165 | link_libcpp: ?bool = null, |
| 153 | 166 | single_threaded: ?bool = null, |
| ... | ... | @@ -173,26 +186,26 @@ pub const Import = struct { |
| 173 | 186 | module: *Module, |
| 174 | 187 | }; |
| 175 | 188 | |
| 176 | pub fn init(owner: *std.Build, options: CreateOptions, compile: ?*std.Build.Step.Compile) Module { | |
| 177 | var m: Module = .{ | |
| 189 | pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*Step.Compile) void { | |
| 190 | const allocator = owner.allocator; | |
| 191 | ||
| 192 | m.* = .{ | |
| 178 | 193 | .owner = owner, |
| 179 | 194 | .depending_steps = .{}, |
| 180 | 195 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, |
| 181 | .import_table = std.StringArrayHashMap(*Module).init(owner.allocator), | |
| 196 | .import_table = .{}, | |
| 182 | 197 | .target = options.target, |
| 183 | .target_info = options.target_info orelse | |
| 184 | NativeTargetInfo.detect(options.target) catch @panic("unhandled error"), | |
| 185 | 198 | .optimize = options.optimize, |
| 186 | 199 | .link_libc = options.link_libc, |
| 187 | 200 | .link_libcpp = options.link_libcpp, |
| 188 | 201 | .dwarf_format = options.dwarf_format, |
| 189 | .c_macros = std.ArrayList([]const u8).init(owner.allocator), | |
| 190 | .include_dirs = std.ArrayList(IncludeDir).init(owner.allocator), | |
| 191 | .lib_paths = std.ArrayList(LazyPath).init(owner.allocator), | |
| 192 | .rpaths = std.ArrayList(LazyPath).init(owner.allocator), | |
| 202 | .c_macros = .{}, | |
| 203 | .include_dirs = .{}, | |
| 204 | .lib_paths = .{}, | |
| 205 | .rpaths = .{}, | |
| 193 | 206 | .frameworks = .{}, |
| 194 | 207 | .c_std = options.c_std, |
| 195 | .link_objects = std.ArrayList(LinkObject).init(owner.allocator), | |
| 208 | .link_objects = .{}, | |
| 196 | 209 | .strip = options.strip, |
| 197 | 210 | .unwind_tables = options.unwind_tables, |
| 198 | 211 | .single_threaded = options.single_threaded, |
| ... | ... | @@ -208,31 +221,30 @@ pub fn init(owner: *std.Build, options: CreateOptions, compile: ?*std.Build.Step |
| 208 | 221 | .export_symbol_names = &.{}, |
| 209 | 222 | }; |
| 210 | 223 | |
| 211 | if (compile) |c| { | |
| 212 | m.depending_steps.put(owner.allocator, c, {}) catch @panic("OOM"); | |
| 224 | m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM"); | |
| 225 | for (options.imports) |dep| { | |
| 226 | m.import_table.putAssumeCapacity(dep.name, dep.module); | |
| 213 | 227 | } |
| 214 | 228 | |
| 215 | m.import_table.ensureUnusedCapacity(options.import_table.len) catch @panic("OOM"); | |
| 216 | for (options.import_table) |dep| { | |
| 217 | m.import_table.putAssumeCapacity(dep.name, dep.module); | |
| 229 | if (compile) |c| { | |
| 230 | m.depending_steps.put(allocator, c, {}) catch @panic("OOM"); | |
| 218 | 231 | } |
| 219 | 232 | |
| 233 | // This logic accesses `depending_steps` which was just modified above. | |
| 220 | 234 | var it = m.iterateDependencies(null); |
| 221 | while (it.next()) |item| addShallowDependencies(&m, item.module); | |
| 222 | ||
| 223 | return m; | |
| 235 | while (it.next()) |item| addShallowDependencies(m, item.module); | |
| 224 | 236 | } |
| 225 | 237 | |
| 226 | 238 | pub fn create(owner: *std.Build, options: CreateOptions) *Module { |
| 227 | 239 | const m = owner.allocator.create(Module) catch @panic("OOM"); |
| 228 | m.* = init(owner, options, null); | |
| 240 | m.init(owner, options, null); | |
| 229 | 241 | return m; |
| 230 | 242 | } |
| 231 | 243 | |
| 232 | 244 | /// Adds an existing module to be used with `@import`. |
| 233 | 245 | pub fn addImport(m: *Module, name: []const u8, module: *Module) void { |
| 234 | 246 | const b = m.owner; |
| 235 | m.import_table.put(b.dupe(name), module) catch @panic("OOM"); | |
| 247 | m.import_table.put(b.allocator, b.dupe(name), module) catch @panic("OOM"); | |
| 236 | 248 | |
| 237 | 249 | var it = module.iterateDependencies(null); |
| 238 | 250 | while (it.next()) |item| addShallowDependencies(m, item.module); |
| ... | ... | @@ -244,7 +256,10 @@ pub fn addImport(m: *Module, name: []const u8, module: *Module) void { |
| 244 | 256 | fn addShallowDependencies(m: *Module, dependee: *Module) void { |
| 245 | 257 | if (dependee.root_source_file) |lazy_path| addLazyPathDependencies(m, dependee, lazy_path); |
| 246 | 258 | for (dependee.lib_paths.items) |lib_path| addLazyPathDependencies(m, dependee, lib_path); |
| 247 | for (dependee.rpaths.items) |rpath| addLazyPathDependencies(m, dependee, rpath); | |
| 259 | for (dependee.rpaths.items) |rpath| switch (rpath) { | |
| 260 | .lazy_path => |lp| addLazyPathDependencies(m, dependee, lp), | |
| 261 | .special => {}, | |
| 262 | }; | |
| 248 | 263 | |
| 249 | 264 | for (dependee.link_objects.items) |link_object| switch (link_object) { |
| 250 | 265 | .other_step => |compile| addStepDependencies(m, dependee, &compile.step), |
| ... | ... | @@ -277,7 +292,7 @@ fn addLazyPathDependenciesOnly(m: *Module, lazy_path: LazyPath) void { |
| 277 | 292 | } |
| 278 | 293 | } |
| 279 | 294 | |
| 280 | fn addStepDependencies(m: *Module, module: *Module, dependee: *std.Build.Step) void { | |
| 295 | fn addStepDependencies(m: *Module, module: *Module, dependee: *Step) void { | |
| 281 | 296 | addStepDependenciesOnly(m, dependee); |
| 282 | 297 | if (m != module) { |
| 283 | 298 | for (m.depending_steps.keys()) |compile| { |
| ... | ... | @@ -286,20 +301,19 @@ fn addStepDependencies(m: *Module, module: *Module, dependee: *std.Build.Step) v |
| 286 | 301 | } |
| 287 | 302 | } |
| 288 | 303 | |
| 289 | fn addStepDependenciesOnly(m: *Module, dependee: *std.Build.Step) void { | |
| 304 | fn addStepDependenciesOnly(m: *Module, dependee: *Step) void { | |
| 290 | 305 | for (m.depending_steps.keys()) |compile| { |
| 291 | 306 | compile.step.dependOn(dependee); |
| 292 | 307 | } |
| 293 | 308 | } |
| 294 | 309 | |
| 295 | 310 | /// Creates a new module and adds it to be used with `@import`. |
| 296 | pub fn addAnonymousImport(m: *Module, name: []const u8, options: std.Build.CreateModuleOptions) void { | |
| 297 | const b = m.step.owner; | |
| 298 | const module = b.createModule(options); | |
| 311 | pub fn addAnonymousImport(m: *Module, name: []const u8, options: CreateOptions) void { | |
| 312 | const module = create(m.owner, options); | |
| 299 | 313 | return addImport(m, name, module); |
| 300 | 314 | } |
| 301 | 315 | |
| 302 | pub fn addOptions(m: *Module, module_name: []const u8, options: *std.Build.Step.Options) void { | |
| 316 | pub fn addOptions(m: *Module, module_name: []const u8, options: *Step.Options) void { | |
| 303 | 317 | addImport(m, module_name, options.createModule()); |
| 304 | 318 | } |
| 305 | 319 | |
| ... | ... | @@ -311,14 +325,14 @@ pub const DependencyIterator = struct { |
| 311 | 325 | pub const Key = struct { |
| 312 | 326 | /// The compilation that contains the `Module`. Note that a `Module` might be |
| 313 | 327 | /// used by more than one compilation. |
| 314 | compile: ?*std.Build.Step.Compile, | |
| 328 | compile: ?*Step.Compile, | |
| 315 | 329 | module: *Module, |
| 316 | 330 | }; |
| 317 | 331 | |
| 318 | 332 | pub const Item = struct { |
| 319 | 333 | /// The compilation that contains the `Module`. Note that a `Module` might be |
| 320 | 334 | /// used by more than one compilation. |
| 321 | compile: ?*std.Build.Step.Compile, | |
| 335 | compile: ?*Step.Compile, | |
| 322 | 336 | module: *Module, |
| 323 | 337 | name: []const u8, |
| 324 | 338 | }; |
| ... | ... | @@ -368,7 +382,7 @@ pub const DependencyIterator = struct { |
| 368 | 382 | |
| 369 | 383 | pub fn iterateDependencies( |
| 370 | 384 | m: *Module, |
| 371 | chase_steps: ?*std.Build.Step.Compile, | |
| 385 | chase_steps: ?*Step.Compile, | |
| 372 | 386 | ) DependencyIterator { |
| 373 | 387 | var it: DependencyIterator = .{ |
| 374 | 388 | .allocator = m.owner.allocator, |
| ... | ... | @@ -397,16 +411,18 @@ pub fn linkSystemLibrary( |
| 397 | 411 | options: LinkSystemLibraryOptions, |
| 398 | 412 | ) void { |
| 399 | 413 | const b = m.owner; |
| 400 | if (m.target_info.target.is_libc_lib_name(name)) { | |
| 414 | ||
| 415 | const target = m.requireKnownTarget(); | |
| 416 | if (target.is_libc_lib_name(name)) { | |
| 401 | 417 | m.link_libc = true; |
| 402 | 418 | return; |
| 403 | 419 | } |
| 404 | if (m.target_info.target.is_libcpp_lib_name(name)) { | |
| 420 | if (target.is_libcpp_lib_name(name)) { | |
| 405 | 421 | m.link_libcpp = true; |
| 406 | 422 | return; |
| 407 | 423 | } |
| 408 | 424 | |
| 409 | m.link_objects.append(.{ | |
| 425 | m.link_objects.append(b.allocator, .{ | |
| 410 | 426 | .system_lib = .{ |
| 411 | 427 | .name = b.dupe(name), |
| 412 | 428 | .needed = options.needed, |
| ... | ... | @@ -418,6 +434,11 @@ pub fn linkSystemLibrary( |
| 418 | 434 | }) catch @panic("OOM"); |
| 419 | 435 | } |
| 420 | 436 | |
| 437 | pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions) void { | |
| 438 | const b = m.owner; | |
| 439 | m.frameworks.put(b.allocator, b.dupe(name), options) catch @panic("OOM"); | |
| 440 | } | |
| 441 | ||
| 421 | 442 | pub const AddCSourceFilesOptions = struct { |
| 422 | 443 | /// When provided, `files` are relative to `dependency` rather than the |
| 423 | 444 | /// package that owns the `Compile` step. |
| ... | ... | @@ -428,19 +449,23 @@ pub const AddCSourceFilesOptions = struct { |
| 428 | 449 | |
| 429 | 450 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 430 | 451 | pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { |
| 431 | const c_source_files = m.owner.allocator.create(CSourceFiles) catch @panic("OOM"); | |
| 452 | const b = m.owner; | |
| 453 | const allocator = b.allocator; | |
| 454 | const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM"); | |
| 432 | 455 | c_source_files.* = .{ |
| 433 | 456 | .dependency = options.dependency, |
| 434 | .files = m.owner.dupeStrings(options.files), | |
| 435 | .flags = m.owner.dupeStrings(options.flags), | |
| 457 | .files = b.dupeStrings(options.files), | |
| 458 | .flags = b.dupeStrings(options.flags), | |
| 436 | 459 | }; |
| 437 | m.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM"); | |
| 460 | m.link_objects.append(allocator, .{ .c_source_files = c_source_files }) catch @panic("OOM"); | |
| 438 | 461 | } |
| 439 | 462 | |
| 440 | 463 | pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| 441 | const c_source_file = m.owner.allocator.create(CSourceFile) catch @panic("OOM"); | |
| 442 | c_source_file.* = source.dupe(m.owner); | |
| 443 | m.link_objects.append(.{ .c_source_file = c_source_file }) catch @panic("OOM"); | |
| 464 | const b = m.owner; | |
| 465 | const allocator = b.allocator; | |
| 466 | const c_source_file = allocator.create(CSourceFile) catch @panic("OOM"); | |
| 467 | c_source_file.* = source.dupe(b); | |
| 468 | m.link_objects.append(allocator, .{ .c_source_file = c_source_file }) catch @panic("OOM"); | |
| 444 | 469 | addLazyPathDependenciesOnly(m, source.file); |
| 445 | 470 | } |
| 446 | 471 | |
| ... | ... | @@ -448,30 +473,122 @@ pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| 448 | 473 | /// Can be called regardless of target. The .rc file will be ignored |
| 449 | 474 | /// if the target object format does not support embedded resources. |
| 450 | 475 | pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void { |
| 476 | const b = m.owner; | |
| 477 | const allocator = b.allocator; | |
| 478 | const target = m.requireKnownTarget(); | |
| 451 | 479 | // Only the PE/COFF format has a Resource Table, so for any other target |
| 452 | 480 | // the resource file is ignored. |
| 453 | if (m.target_info.target.ofmt != .coff) return; | |
| 481 | if (target.ofmt != .coff) return; | |
| 454 | 482 | |
| 455 | const rc_source_file = m.owner.allocator.create(RcSourceFile) catch @panic("OOM"); | |
| 456 | rc_source_file.* = source.dupe(m.owner); | |
| 457 | m.link_objects.append(.{ .win32_resource_file = rc_source_file }) catch @panic("OOM"); | |
| 483 | const rc_source_file = allocator.create(RcSourceFile) catch @panic("OOM"); | |
| 484 | rc_source_file.* = source.dupe(b); | |
| 485 | m.link_objects.append(allocator, .{ .win32_resource_file = rc_source_file }) catch @panic("OOM"); | |
| 458 | 486 | addLazyPathDependenciesOnly(m, source.file); |
| 459 | 487 | } |
| 460 | 488 | |
| 461 | 489 | pub fn addAssemblyFile(m: *Module, source: LazyPath) void { |
| 462 | m.link_objects.append(.{ .assembly_file = source.dupe(m.owner) }) catch @panic("OOM"); | |
| 490 | const b = m.owner; | |
| 491 | m.link_objects.append(b.allocator, .{ .assembly_file = source.dupe(b) }) catch @panic("OOM"); | |
| 463 | 492 | addLazyPathDependenciesOnly(m, source); |
| 464 | 493 | } |
| 465 | 494 | |
| 466 | pub fn addObjectFile(m: *Module, source: LazyPath) void { | |
| 467 | m.link_objects.append(.{ .static_path = source.dupe(m.owner) }) catch @panic("OOM"); | |
| 468 | addLazyPathDependencies(m, source); | |
| 495 | pub fn addObjectFile(m: *Module, object: LazyPath) void { | |
| 496 | const b = m.owner; | |
| 497 | m.link_objects.append(b.allocator, .{ .static_path = object.dupe(b) }) catch @panic("OOM"); | |
| 498 | addLazyPathDependenciesOnly(m, object); | |
| 499 | } | |
| 500 | ||
| 501 | pub fn addObject(m: *Module, object: *Step.Compile) void { | |
| 502 | assert(object.kind == .obj); | |
| 503 | m.linkLibraryOrObject(object); | |
| 504 | } | |
| 505 | ||
| 506 | pub fn linkLibrary(m: *Module, library: *Step.Compile) void { | |
| 507 | assert(library.kind == .lib); | |
| 508 | m.linkLibraryOrObject(library); | |
| 509 | } | |
| 510 | ||
| 511 | pub fn addAfterIncludePath(m: *Module, lazy_path: LazyPath) void { | |
| 512 | const b = m.owner; | |
| 513 | m.include_dirs.append(b.allocator, .{ .path_after = lazy_path.dupe(b) }) catch @panic("OOM"); | |
| 514 | addLazyPathDependenciesOnly(m, lazy_path); | |
| 515 | } | |
| 516 | ||
| 517 | pub fn addSystemIncludePath(m: *Module, lazy_path: LazyPath) void { | |
| 518 | const b = m.owner; | |
| 519 | m.include_dirs.append(b.allocator, .{ .path_system = lazy_path.dupe(b) }) catch @panic("OOM"); | |
| 520 | addLazyPathDependenciesOnly(m, lazy_path); | |
| 521 | } | |
| 522 | ||
| 523 | pub fn addIncludePath(m: *Module, lazy_path: LazyPath) void { | |
| 524 | const b = m.owner; | |
| 525 | m.include_dirs.append(b.allocator, .{ .path = lazy_path.dupe(b) }) catch @panic("OOM"); | |
| 526 | addLazyPathDependenciesOnly(m, lazy_path); | |
| 527 | } | |
| 528 | ||
| 529 | pub fn addConfigHeader(m: *Module, config_header: *Step.ConfigHeader) void { | |
| 530 | const allocator = m.owner.allocator; | |
| 531 | m.include_dirs.append(allocator, .{ .config_header_step = config_header }) catch @panic("OOM"); | |
| 532 | addStepDependenciesOnly(m, &config_header.step); | |
| 533 | } | |
| 534 | ||
| 535 | pub fn addSystemFrameworkPath(m: *Module, directory_path: LazyPath) void { | |
| 536 | const b = m.owner; | |
| 537 | m.include_dirs.append(b.allocator, .{ .framework_path_system = directory_path.dupe(b) }) catch | |
| 538 | @panic("OOM"); | |
| 539 | addLazyPathDependenciesOnly(m, directory_path); | |
| 540 | } | |
| 541 | ||
| 542 | pub fn addFrameworkPath(m: *Module, directory_path: LazyPath) void { | |
| 543 | const b = m.owner; | |
| 544 | m.include_dirs.append(b.allocator, .{ .framework_path = directory_path.dupe(b) }) catch | |
| 545 | @panic("OOM"); | |
| 546 | addLazyPathDependenciesOnly(m, directory_path); | |
| 547 | } | |
| 548 | ||
| 549 | pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { | |
| 550 | const b = m.owner; | |
| 551 | m.lib_paths.append(b.allocator, directory_path.dupe(b)) catch @panic("OOM"); | |
| 552 | addLazyPathDependenciesOnly(m, directory_path); | |
| 553 | } | |
| 554 | ||
| 555 | pub fn addRPath(m: *Module, directory_path: LazyPath) void { | |
| 556 | const b = m.owner; | |
| 557 | switch (directory_path) { | |
| 558 | .path, .cwd_relative => |path| { | |
| 559 | // TODO: remove this check after people upgrade and stop expecting it to work | |
| 560 | if (std.mem.startsWith(u8, path, "@executable_path") or | |
| 561 | std.mem.startsWith(u8, path, "@loader_path")) | |
| 562 | { | |
| 563 | @panic("this function is for adding directory paths. It does not support special rpaths. use addRPathSpecial for that."); | |
| 564 | } | |
| 565 | }, | |
| 566 | else => {}, | |
| 567 | } | |
| 568 | m.rpaths.append(b.allocator, .{ .lazy_path = directory_path.dupe(b) }) catch @panic("OOM"); | |
| 569 | addLazyPathDependenciesOnly(m, directory_path); | |
| 570 | } | |
| 571 | ||
| 572 | pub fn addRPathSpecial(m: *Module, bytes: []const u8) void { | |
| 573 | const b = m.owner; | |
| 574 | m.rpaths.append(b.allocator, .{ .special = b.dupe(bytes) }) catch @panic("OOM"); | |
| 575 | } | |
| 576 | ||
| 577 | /// Equvialent to the following C code, applied to all C source files owned by | |
| 578 | /// this `Module`: | |
| 579 | /// ```c | |
| 580 | /// #define name value | |
| 581 | /// ``` | |
| 582 | /// `name` and `value` need not live longer than the function call. | |
| 583 | pub fn addCMacro(m: *Module, name: []const u8, value: []const u8) void { | |
| 584 | const b = m.owner; | |
| 585 | m.c_macros.append(b.allocator, b.fmt("-D{s}={s}", .{ name, value })) catch @panic("OOM"); | |
| 469 | 586 | } |
| 470 | 587 | |
| 471 | 588 | pub fn appendZigProcessFlags( |
| 472 | 589 | m: *Module, |
| 473 | 590 | zig_args: *std.ArrayList([]const u8), |
| 474 | asking_step: ?*std.Build.Step, | |
| 591 | asking_step: ?*Step, | |
| 475 | 592 | ) !void { |
| 476 | 593 | const b = m.owner; |
| 477 | 594 | |
| ... | ... | @@ -495,27 +612,30 @@ pub fn appendZigProcessFlags( |
| 495 | 612 | } |
| 496 | 613 | |
| 497 | 614 | try zig_args.ensureUnusedCapacity(1); |
| 498 | switch (m.optimize) { | |
| 499 | .Debug => {}, // Skip since it's the default. | |
| 615 | if (m.optimize) |optimize| switch (optimize) { | |
| 616 | .Debug => zig_args.appendAssumeCapacity("-ODebug"), | |
| 500 | 617 | .ReleaseSmall => zig_args.appendAssumeCapacity("-OReleaseSmall"), |
| 501 | 618 | .ReleaseFast => zig_args.appendAssumeCapacity("-OReleaseFast"), |
| 502 | 619 | .ReleaseSafe => zig_args.appendAssumeCapacity("-OReleaseSafe"), |
| 503 | } | |
| 620 | }; | |
| 504 | 621 | |
| 505 | 622 | if (m.code_model != .default) { |
| 506 | 623 | try zig_args.append("-mcmodel"); |
| 507 | 624 | try zig_args.append(@tagName(m.code_model)); |
| 508 | 625 | } |
| 509 | 626 | |
| 510 | if (!m.target.isNative()) { | |
| 511 | try zig_args.appendSlice(&.{ | |
| 512 | "-target", try m.target.zigTriple(b.allocator), | |
| 513 | "-mcpu", try std.Build.serializeCpu(b.allocator, m.target.getCpu()), | |
| 514 | }); | |
| 515 | ||
| 516 | if (m.target.dynamic_linker.get()) |dynamic_linker| { | |
| 517 | try zig_args.append("--dynamic-linker"); | |
| 518 | try zig_args.append(dynamic_linker); | |
| 627 | if (m.target) |target| { | |
| 628 | // Communicate the query via CLI since it's more compact. | |
| 629 | if (!target.query.isNative()) { | |
| 630 | try zig_args.appendSlice(&.{ | |
| 631 | "-target", try target.query.zigTriple(b.allocator), | |
| 632 | "-mcpu", try std.Build.serializeCpu(b.allocator, target.query.getCpu()), | |
| 633 | }); | |
| 634 | ||
| 635 | if (target.query.dynamic_linker.get()) |dynamic_linker| { | |
| 636 | try zig_args.append("--dynamic-linker"); | |
| 637 | try zig_args.append(dynamic_linker); | |
| 638 | } | |
| 519 | 639 | } |
| 520 | 640 | } |
| 521 | 641 | |
| ... | ... | @@ -565,10 +685,7 @@ pub fn appendZigProcessFlags( |
| 565 | 685 | } |
| 566 | 686 | } |
| 567 | 687 | |
| 568 | for (m.c_macros.items) |c_macro| { | |
| 569 | try zig_args.append("-D"); | |
| 570 | try zig_args.append(c_macro); | |
| 571 | } | |
| 688 | try zig_args.appendSlice(m.c_macros.items); | |
| 572 | 689 | |
| 573 | 690 | try zig_args.ensureUnusedCapacity(2 * m.lib_paths.items.len); |
| 574 | 691 | for (m.lib_paths.items) |lib_path| { |
| ... | ... | @@ -577,26 +694,16 @@ pub fn appendZigProcessFlags( |
| 577 | 694 | } |
| 578 | 695 | |
| 579 | 696 | try zig_args.ensureUnusedCapacity(2 * m.rpaths.items.len); |
| 580 | for (m.rpaths.items) |rpath| { | |
| 581 | zig_args.appendAssumeCapacity("-rpath"); | |
| 582 | ||
| 583 | if (m.target_info.target.isDarwin()) switch (rpath) { | |
| 584 | .path, .cwd_relative => |path| { | |
| 585 | // On Darwin, we should not try to expand special runtime paths such as | |
| 586 | // * @executable_path | |
| 587 | // * @loader_path | |
| 588 | if (std.mem.startsWith(u8, path, "@executable_path") or | |
| 589 | std.mem.startsWith(u8, path, "@loader_path")) | |
| 590 | { | |
| 591 | zig_args.appendAssumeCapacity(path); | |
| 592 | continue; | |
| 593 | } | |
| 594 | }, | |
| 595 | .generated, .dependency => {}, | |
| 596 | }; | |
| 597 | ||
| 598 | zig_args.appendAssumeCapacity(rpath.getPath2(b, asking_step)); | |
| 599 | } | |
| 697 | for (m.rpaths.items) |rpath| switch (rpath) { | |
| 698 | .lazy_path => |lp| { | |
| 699 | zig_args.appendAssumeCapacity("-rpath"); | |
| 700 | zig_args.appendAssumeCapacity(lp.getPath2(b, asking_step)); | |
| 701 | }, | |
| 702 | .special => |bytes| { | |
| 703 | zig_args.appendAssumeCapacity("-rpath"); | |
| 704 | zig_args.appendAssumeCapacity(bytes); | |
| 705 | }, | |
| 706 | }; | |
| 600 | 707 | } |
| 601 | 708 | |
| 602 | 709 | fn addFlag( |
| ... | ... | @@ -609,8 +716,32 @@ fn addFlag( |
| 609 | 716 | return args.append(if (cond) then_name else else_name); |
| 610 | 717 | } |
| 611 | 718 | |
| 719 | fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { | |
| 720 | const allocator = m.owner.allocator; | |
| 721 | _ = other.getEmittedBin(); // Indicate there is a dependency on the outputted binary. | |
| 722 | addStepDependenciesOnly(m, &other.step); | |
| 723 | ||
| 724 | if (other.rootModuleTarget().os.tag == .windows and other.isDynamicLibrary()) { | |
| 725 | _ = other.getEmittedImplib(); // Indicate dependency on the outputted implib. | |
| 726 | } | |
| 727 | ||
| 728 | m.link_objects.append(allocator, .{ .other_step = other }) catch @panic("OOM"); | |
| 729 | m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM"); | |
| 730 | ||
| 731 | for (other.installed_headers.items) |install_step| { | |
| 732 | addStepDependenciesOnly(m, install_step); | |
| 733 | } | |
| 734 | } | |
| 735 | ||
| 736 | fn requireKnownTarget(m: *Module) std.Target { | |
| 737 | const resolved_target = m.target orelse | |
| 738 | @panic("this API requires the Module to be created with a known 'target' field"); | |
| 739 | return resolved_target.target; | |
| 740 | } | |
| 741 | ||
| 612 | 742 | const Module = @This(); |
| 613 | 743 | const std = @import("std"); |
| 614 | 744 | const assert = std.debug.assert; |
| 615 | 745 | const LazyPath = std.Build.LazyPath; |
| 616 | 746 | const NativeTargetInfo = std.zig.system.NativeTargetInfo; |
| 747 | const Step = std.Build.Step; |
lib/std/Build/Step/CheckObject.zig+26-22| ... | ... | @@ -44,11 +44,11 @@ pub fn create( |
| 44 | 44 | |
| 45 | 45 | const SearchPhrase = struct { |
| 46 | 46 | string: []const u8, |
| 47 | file_source: ?std.Build.LazyPath = null, | |
| 47 | lazy_path: ?std.Build.LazyPath = null, | |
| 48 | 48 | |
| 49 | 49 | fn resolve(phrase: SearchPhrase, b: *std.Build, step: *Step) []const u8 { |
| 50 | const file_source = phrase.file_source orelse return phrase.string; | |
| 51 | return b.fmt("{s} {s}", .{ phrase.string, file_source.getPath2(b, step) }); | |
| 50 | const lazy_path = phrase.lazy_path orelse return phrase.string; | |
| 51 | return b.fmt("{s} {s}", .{ phrase.string, lazy_path.getPath2(b, step) }); | |
| 52 | 52 | } |
| 53 | 53 | }; |
| 54 | 54 | |
| ... | ... | @@ -321,14 +321,14 @@ pub fn checkExact(self: *CheckObject, phrase: []const u8) void { |
| 321 | 321 | |
| 322 | 322 | /// Like `checkExact()` but takes an additional argument `LazyPath` which will be |
| 323 | 323 | /// resolved to a full search query in `make()`. |
| 324 | pub fn checkExactPath(self: *CheckObject, phrase: []const u8, file_source: std.Build.LazyPath) void { | |
| 325 | self.checkExactInner(phrase, file_source); | |
| 324 | pub fn checkExactPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { | |
| 325 | self.checkExactInner(phrase, lazy_path); | |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | fn checkExactInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.LazyPath) void { | |
| 328 | fn checkExactInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | |
| 329 | 329 | assert(self.checks.items.len > 0); |
| 330 | 330 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 331 | last.exact(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | |
| 331 | last.exact(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /// Adds a fuzzy match phrase to the latest created Check. |
| ... | ... | @@ -336,16 +336,20 @@ pub fn checkContains(self: *CheckObject, phrase: []const u8) void { |
| 336 | 336 | self.checkContainsInner(phrase, null); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | /// Like `checkContains()` but takes an additional argument `FileSource` which will be | |
| 339 | /// Like `checkContains()` but takes an additional argument `lazy_path` which will be | |
| 340 | 340 | /// resolved to a full search query in `make()`. |
| 341 | pub fn checkContainsPath(self: *CheckObject, phrase: []const u8, file_source: std.Build.LazyPath) void { | |
| 342 | self.checkContainsInner(phrase, file_source); | |
| 341 | pub fn checkContainsPath( | |
| 342 | self: *CheckObject, | |
| 343 | phrase: []const u8, | |
| 344 | lazy_path: std.Build.LazyPath, | |
| 345 | ) void { | |
| 346 | self.checkContainsInner(phrase, lazy_path); | |
| 343 | 347 | } |
| 344 | 348 | |
| 345 | fn checkContainsInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.FileSource) void { | |
| 349 | fn checkContainsInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | |
| 346 | 350 | assert(self.checks.items.len > 0); |
| 347 | 351 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 348 | last.contains(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | |
| 352 | last.contains(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | |
| 349 | 353 | } |
| 350 | 354 | |
| 351 | 355 | /// Adds an exact match phrase with variable extractor to the latest created Check. |
| ... | ... | @@ -353,16 +357,16 @@ pub fn checkExtract(self: *CheckObject, phrase: []const u8) void { |
| 353 | 357 | self.checkExtractInner(phrase, null); |
| 354 | 358 | } |
| 355 | 359 | |
| 356 | /// Like `checkExtract()` but takes an additional argument `FileSource` which will be | |
| 360 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be | |
| 357 | 361 | /// resolved to a full search query in `make()`. |
| 358 | pub fn checkExtractFileSource(self: *CheckObject, phrase: []const u8, file_source: std.Build.FileSource) void { | |
| 359 | self.checkExtractInner(phrase, file_source); | |
| 362 | pub fn checkExtractLazyPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { | |
| 363 | self.checkExtractInner(phrase, lazy_path); | |
| 360 | 364 | } |
| 361 | 365 | |
| 362 | fn checkExtractInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.FileSource) void { | |
| 366 | fn checkExtractInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | |
| 363 | 367 | assert(self.checks.items.len > 0); |
| 364 | 368 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 365 | last.extract(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | |
| 369 | last.extract(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | |
| 366 | 370 | } |
| 367 | 371 | |
| 368 | 372 | /// Adds another searched phrase to the latest created Check |
| ... | ... | @@ -371,16 +375,16 @@ pub fn checkNotPresent(self: *CheckObject, phrase: []const u8) void { |
| 371 | 375 | self.checkNotPresentInner(phrase, null); |
| 372 | 376 | } |
| 373 | 377 | |
| 374 | /// Like `checkExtract()` but takes an additional argument `FileSource` which will be | |
| 378 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be | |
| 375 | 379 | /// resolved to a full search query in `make()`. |
| 376 | pub fn checkNotPresentFileSource(self: *CheckObject, phrase: []const u8, file_source: std.Build.FileSource) void { | |
| 377 | self.checkNotPresentInner(phrase, file_source); | |
| 380 | pub fn checkNotPresentLazyPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { | |
| 381 | self.checkNotPresentInner(phrase, lazy_path); | |
| 378 | 382 | } |
| 379 | 383 | |
| 380 | fn checkNotPresentInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.FileSource) void { | |
| 384 | fn checkNotPresentInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { | |
| 381 | 385 | assert(self.checks.items.len > 0); |
| 382 | 386 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 383 | last.notPresent(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | |
| 387 | last.notPresent(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); | |
| 384 | 388 | } |
| 385 | 389 | |
| 386 | 390 | /// Creates a new check checking in the file headers (section, program headers, etc.). |
lib/std/Build/Step/Compile.zig+81-203| ... | ... | @@ -88,7 +88,7 @@ each_lib_rpath: ?bool = null, |
| 88 | 88 | /// As an example, the bloaty project refuses to work unless its inputs have |
| 89 | 89 | /// build ids, in order to prevent accidental mismatches. |
| 90 | 90 | /// The default is to not include this section because it slows down linking. |
| 91 | build_id: ?BuildId = null, | |
| 91 | build_id: ?std.zig.BuildId = null, | |
| 92 | 92 | |
| 93 | 93 | /// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF |
| 94 | 94 | /// file. |
| ... | ... | @@ -200,7 +200,7 @@ pub const ExpectedCompileErrors = union(enum) { |
| 200 | 200 | exact: []const []const u8, |
| 201 | 201 | }; |
| 202 | 202 | |
| 203 | const Entry = union(enum) { | |
| 203 | pub const Entry = union(enum) { | |
| 204 | 204 | /// Let the compiler decide whether to make an entry point and what to name |
| 205 | 205 | /// it. |
| 206 | 206 | default, |
| ... | ... | @@ -232,82 +232,6 @@ pub const Options = struct { |
| 232 | 232 | win32_manifest: ?LazyPath = null, |
| 233 | 233 | }; |
| 234 | 234 | |
| 235 | pub const BuildId = union(enum) { | |
| 236 | none, | |
| 237 | fast, | |
| 238 | uuid, | |
| 239 | sha1, | |
| 240 | md5, | |
| 241 | hexstring: HexString, | |
| 242 | ||
| 243 | pub fn eql(a: BuildId, b: BuildId) bool { | |
| 244 | const a_tag = std.meta.activeTag(a); | |
| 245 | const b_tag = std.meta.activeTag(b); | |
| 246 | if (a_tag != b_tag) return false; | |
| 247 | return switch (a) { | |
| 248 | .none, .fast, .uuid, .sha1, .md5 => true, | |
| 249 | .hexstring => |a_hexstring| mem.eql(u8, a_hexstring.toSlice(), b.hexstring.toSlice()), | |
| 250 | }; | |
| 251 | } | |
| 252 | ||
| 253 | pub const HexString = struct { | |
| 254 | bytes: [32]u8, | |
| 255 | len: u8, | |
| 256 | ||
| 257 | /// Result is byte values, *not* hex-encoded. | |
| 258 | pub fn toSlice(hs: *const HexString) []const u8 { | |
| 259 | return hs.bytes[0..hs.len]; | |
| 260 | } | |
| 261 | }; | |
| 262 | ||
| 263 | /// Input is byte values, *not* hex-encoded. | |
| 264 | /// Asserts `bytes` fits inside `HexString` | |
| 265 | pub fn initHexString(bytes: []const u8) BuildId { | |
| 266 | var result: BuildId = .{ .hexstring = .{ | |
| 267 | .bytes = undefined, | |
| 268 | .len = @as(u8, @intCast(bytes.len)), | |
| 269 | } }; | |
| 270 | @memcpy(result.hexstring.bytes[0..bytes.len], bytes); | |
| 271 | return result; | |
| 272 | } | |
| 273 | ||
| 274 | /// Converts UTF-8 text to a `BuildId`. | |
| 275 | pub fn parse(text: []const u8) !BuildId { | |
| 276 | if (mem.eql(u8, text, "none")) { | |
| 277 | return .none; | |
| 278 | } else if (mem.eql(u8, text, "fast")) { | |
| 279 | return .fast; | |
| 280 | } else if (mem.eql(u8, text, "uuid")) { | |
| 281 | return .uuid; | |
| 282 | } else if (mem.eql(u8, text, "sha1") or mem.eql(u8, text, "tree")) { | |
| 283 | return .sha1; | |
| 284 | } else if (mem.eql(u8, text, "md5")) { | |
| 285 | return .md5; | |
| 286 | } else if (mem.startsWith(u8, text, "0x")) { | |
| 287 | var result: BuildId = .{ .hexstring = undefined }; | |
| 288 | const slice = try std.fmt.hexToBytes(&result.hexstring.bytes, text[2..]); | |
| 289 | result.hexstring.len = @as(u8, @intCast(slice.len)); | |
| 290 | return result; | |
| 291 | } | |
| 292 | return error.InvalidBuildIdStyle; | |
| 293 | } | |
| 294 | ||
| 295 | test parse { | |
| 296 | try std.testing.expectEqual(BuildId.md5, try parse("md5")); | |
| 297 | try std.testing.expectEqual(BuildId.none, try parse("none")); | |
| 298 | try std.testing.expectEqual(BuildId.fast, try parse("fast")); | |
| 299 | try std.testing.expectEqual(BuildId.uuid, try parse("uuid")); | |
| 300 | try std.testing.expectEqual(BuildId.sha1, try parse("sha1")); | |
| 301 | try std.testing.expectEqual(BuildId.sha1, try parse("tree")); | |
| 302 | ||
| 303 | try std.testing.expect(BuildId.initHexString("").eql(try parse("0x"))); | |
| 304 | try std.testing.expect(BuildId.initHexString("\x12\x34\x56").eql(try parse("0x123456"))); | |
| 305 | try std.testing.expectError(error.InvalidLength, parse("0x12-34")); | |
| 306 | try std.testing.expectError(error.InvalidCharacter, parse("0xfoobbb")); | |
| 307 | try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx")); | |
| 308 | } | |
| 309 | }; | |
| 310 | ||
| 311 | 235 | pub const Kind = enum { |
| 312 | 236 | exe, |
| 313 | 237 | lib, |
| ... | ... | @@ -329,6 +253,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 329 | 253 | else |
| 330 | 254 | owner.fmt("{s} ", .{name}); |
| 331 | 255 | |
| 256 | const target = options.root_module.target.?.target; | |
| 257 | ||
| 332 | 258 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ |
| 333 | 259 | switch (options.kind) { |
| 334 | 260 | .exe => "zig build-exe", |
| ... | ... | @@ -337,16 +263,13 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 337 | 263 | .@"test" => "zig test", |
| 338 | 264 | }, |
| 339 | 265 | name_adjusted, |
| 340 | @tagName(options.root_module.optimize), | |
| 341 | options.root_module.target.zigTriple(owner.allocator) catch @panic("OOM"), | |
| 266 | @tagName(options.root_module.optimize orelse .Debug), | |
| 267 | target.zigTriple(owner.allocator) catch @panic("OOM"), | |
| 342 | 268 | }); |
| 343 | 269 | |
| 344 | const target_info = NativeTargetInfo.detect(options.root_module.target) catch | |
| 345 | @panic("unhandled error"); | |
| 346 | ||
| 347 | 270 | const out_filename = std.zig.binNameAlloc(owner.allocator, .{ |
| 348 | 271 | .root_name = name, |
| 349 | .target = target_info.target, | |
| 272 | .target = target, | |
| 350 | 273 | .output_mode = switch (options.kind) { |
| 351 | 274 | .lib => .Lib, |
| 352 | 275 | .obj => .Obj, |
| ... | ... | @@ -361,7 +284,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 361 | 284 | |
| 362 | 285 | const self = owner.allocator.create(Compile) catch @panic("OOM"); |
| 363 | 286 | self.* = .{ |
| 364 | .root_module = Module.init(owner, options.root_module, self), | |
| 287 | .root_module = undefined, | |
| 365 | 288 | .verbose_link = false, |
| 366 | 289 | .verbose_cc = false, |
| 367 | 290 | .linkage = options.linkage, |
| ... | ... | @@ -403,6 +326,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 403 | 326 | .use_lld = options.use_lld, |
| 404 | 327 | }; |
| 405 | 328 | |
| 329 | self.root_module.init(owner, options.root_module, self); | |
| 330 | ||
| 406 | 331 | if (options.zig_lib_dir) |lp| { |
| 407 | 332 | self.zig_lib_dir = lp.dupe(self.step.owner); |
| 408 | 333 | lp.addStepDependencies(&self.step); |
| ... | ... | @@ -410,7 +335,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 410 | 335 | |
| 411 | 336 | // Only the PE/COFF format has a Resource Table which is where the manifest |
| 412 | 337 | // gets embedded, so for any other target the manifest file is just ignored. |
| 413 | if (target_info.target.ofmt == .coff) { | |
| 338 | if (target.ofmt == .coff) { | |
| 414 | 339 | if (options.win32_manifest) |lp| { |
| 415 | 340 | self.win32_manifest = lp.dupe(self.step.owner); |
| 416 | 341 | lp.addStepDependencies(&self.step); |
| ... | ... | @@ -421,14 +346,14 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 421 | 346 | if (self.linkage != null and self.linkage.? == .static) { |
| 422 | 347 | self.out_lib_filename = self.out_filename; |
| 423 | 348 | } else if (self.version) |version| { |
| 424 | if (target_info.target.isDarwin()) { | |
| 349 | if (target.isDarwin()) { | |
| 425 | 350 | self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{ |
| 426 | 351 | self.name, |
| 427 | 352 | version.major, |
| 428 | 353 | }); |
| 429 | 354 | self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name}); |
| 430 | 355 | self.out_lib_filename = self.out_filename; |
| 431 | } else if (target_info.target.os.tag == .windows) { | |
| 356 | } else if (target.os.tag == .windows) { | |
| 432 | 357 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 433 | 358 | } else { |
| 434 | 359 | self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major }); |
| ... | ... | @@ -436,9 +361,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 436 | 361 | self.out_lib_filename = self.out_filename; |
| 437 | 362 | } |
| 438 | 363 | } else { |
| 439 | if (target_info.target.isDarwin()) { | |
| 364 | if (target.isDarwin()) { | |
| 440 | 365 | self.out_lib_filename = self.out_filename; |
| 441 | } else if (target_info.target.os.tag == .windows) { | |
| 366 | } else if (target.os.tag == .windows) { | |
| 442 | 367 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 443 | 368 | } else { |
| 444 | 369 | self.out_lib_filename = self.out_filename; |
| ... | ... | @@ -545,7 +470,7 @@ pub const run = @compileError("deprecated; use std.Build.addRunArtifact"); |
| 545 | 470 | pub const install = @compileError("deprecated; use std.Build.installArtifact"); |
| 546 | 471 | |
| 547 | 472 | pub fn checkObject(self: *Compile) *Step.CheckObject { |
| 548 | return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.target_info.target.ofmt); | |
| 473 | return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.rootModuleTarget().ofmt); | |
| 549 | 474 | } |
| 550 | 475 | |
| 551 | 476 | /// deprecated: use `setLinkerScript` |
| ... | ... | @@ -562,25 +487,6 @@ pub fn forceUndefinedSymbol(self: *Compile, symbol_name: []const u8) void { |
| 562 | 487 | self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM"); |
| 563 | 488 | } |
| 564 | 489 | |
| 565 | pub fn linkFramework(self: *Compile, framework_name: []const u8) void { | |
| 566 | const b = self.step.owner; | |
| 567 | self.frameworks.put(b.dupe(framework_name), .{}) catch @panic("OOM"); | |
| 568 | } | |
| 569 | ||
| 570 | pub fn linkFrameworkNeeded(self: *Compile, framework_name: []const u8) void { | |
| 571 | const b = self.step.owner; | |
| 572 | self.frameworks.put(b.dupe(framework_name), .{ | |
| 573 | .needed = true, | |
| 574 | }) catch @panic("OOM"); | |
| 575 | } | |
| 576 | ||
| 577 | pub fn linkFrameworkWeak(self: *Compile, framework_name: []const u8) void { | |
| 578 | const b = self.step.owner; | |
| 579 | self.frameworks.put(b.dupe(framework_name), .{ | |
| 580 | .weak = true, | |
| 581 | }) catch @panic("OOM"); | |
| 582 | } | |
| 583 | ||
| 584 | 490 | /// Returns whether the library, executable, or object depends on a particular system library. |
| 585 | 491 | pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { |
| 586 | 492 | var is_linking_libc = false; |
| ... | ... | @@ -598,22 +504,17 @@ pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { |
| 598 | 504 | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; |
| 599 | 505 | } |
| 600 | 506 | |
| 601 | if (self.root_module.target_info.target.is_libc_lib_name(name)) { | |
| 507 | if (self.rootModuleTarget().is_libc_lib_name(name)) { | |
| 602 | 508 | return is_linking_libc; |
| 603 | 509 | } |
| 604 | 510 | |
| 605 | if (self.root_module.target_info.target.is_libcpp_lib_name(name)) { | |
| 511 | if (self.rootModuleTarget().is_libcpp_lib_name(name)) { | |
| 606 | 512 | return is_linking_libcpp; |
| 607 | 513 | } |
| 608 | 514 | |
| 609 | 515 | return false; |
| 610 | 516 | } |
| 611 | 517 | |
| 612 | pub fn linkLibrary(self: *Compile, lib: *Compile) void { | |
| 613 | assert(lib.kind == .lib); | |
| 614 | self.linkLibraryOrObject(lib); | |
| 615 | } | |
| 616 | ||
| 617 | 518 | pub fn isDynamicLibrary(self: *const Compile) bool { |
| 618 | 519 | return self.kind == .lib and self.linkage == Linkage.dynamic; |
| 619 | 520 | } |
| ... | ... | @@ -623,16 +524,24 @@ pub fn isStaticLibrary(self: *const Compile) bool { |
| 623 | 524 | } |
| 624 | 525 | |
| 625 | 526 | pub fn producesPdbFile(self: *Compile) bool { |
| 527 | const target = self.rootModuleTarget(); | |
| 626 | 528 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? |
| 627 | 529 | // TODO: just share this logic with the compiler, silly! |
| 628 | if (!self.target.isWindows() and !self.target.isUefi()) return false; | |
| 629 | if (self.target.getObjectFormat() == .c) return false; | |
| 630 | if (self.strip == true or (self.strip == null and self.optimize == .ReleaseSmall)) return false; | |
| 530 | switch (target.os.tag) { | |
| 531 | .windows, .uefi => {}, | |
| 532 | else => return false, | |
| 533 | } | |
| 534 | if (target.ofmt == .c) return false; | |
| 535 | if (self.root_module.strip == true or | |
| 536 | (self.root_module.strip == null and self.root_module.optimize == .ReleaseSmall)) | |
| 537 | { | |
| 538 | return false; | |
| 539 | } | |
| 631 | 540 | return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test"; |
| 632 | 541 | } |
| 633 | 542 | |
| 634 | 543 | pub fn producesImplib(self: *Compile) bool { |
| 635 | return self.isDynamicLibrary() and self.root_module.target_info.target.os.tag == .windows; | |
| 544 | return self.isDynamicLibrary() and self.rootModuleTarget().os.tag == .windows; | |
| 636 | 545 | } |
| 637 | 546 | |
| 638 | 547 | pub fn linkLibC(self: *Compile) void { |
| ... | ... | @@ -643,18 +552,9 @@ pub fn linkLibCpp(self: *Compile) void { |
| 643 | 552 | self.root_module.link_libcpp = true; |
| 644 | 553 | } |
| 645 | 554 | |
| 646 | /// If the value is omitted, it is set to 1. | |
| 647 | /// `name` and `value` need not live longer than the function call. | |
| 648 | pub fn defineCMacro(self: *Compile, name: []const u8, value: ?[]const u8) void { | |
| 649 | const b = self.step.owner; | |
| 650 | const macro = std.Build.constructCMacro(b.allocator, name, value); | |
| 651 | self.c_macros.append(macro) catch @panic("OOM"); | |
| 652 | } | |
| 653 | ||
| 654 | /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. | |
| 655 | pub fn defineCMacroRaw(self: *Compile, name_and_value: []const u8) void { | |
| 656 | const b = self.step.owner; | |
| 657 | self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM"); | |
| 555 | /// Deprecated. Use `c.root_module.addCMacro`. | |
| 556 | pub fn defineCMacro(c: *Compile, name: []const u8, value: ?[]const u8) void { | |
| 557 | c.root_module.addCMacro(name, value orelse "1"); | |
| 658 | 558 | } |
| 659 | 559 | |
| 660 | 560 | /// Run pkg-config for the given library name and parse the output, returning the arguments |
| ... | ... | @@ -765,6 +665,20 @@ pub fn linkSystemLibrary2( |
| 765 | 665 | return self.root_module.linkSystemLibrary(name, options); |
| 766 | 666 | } |
| 767 | 667 | |
| 668 | pub fn linkFramework(c: *Compile, name: []const u8) void { | |
| 669 | c.root_module.linkFramework(name, .{}); | |
| 670 | } | |
| 671 | ||
| 672 | /// Deprecated. Use `c.root_module.linkFramework`. | |
| 673 | pub fn linkFrameworkNeeded(c: *Compile, name: []const u8) void { | |
| 674 | c.root_module.linkFramework(name, .{ .needed = true }); | |
| 675 | } | |
| 676 | ||
| 677 | /// Deprecated. Use `c.root_module.linkFramework`. | |
| 678 | pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void { | |
| 679 | c.root_module.linkFramework(name, .{ .weak = true }); | |
| 680 | } | |
| 681 | ||
| 768 | 682 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 769 | 683 | pub fn addCSourceFiles(self: *Compile, options: Module.AddCSourceFilesOptions) void { |
| 770 | 684 | self.root_module.addCSourceFiles(options); |
| ... | ... | @@ -805,27 +719,18 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath |
| 805 | 719 | return .{ .generated = generated_file }; |
| 806 | 720 | } |
| 807 | 721 | |
| 808 | /// deprecated: use `getEmittedBinDirectory` | |
| 809 | pub const getOutputDirectorySource = getEmittedBinDirectory; | |
| 810 | ||
| 811 | 722 | /// Returns the path to the directory that contains the emitted binary file. |
| 812 | 723 | pub fn getEmittedBinDirectory(self: *Compile) LazyPath { |
| 813 | 724 | _ = self.getEmittedBin(); |
| 814 | 725 | return self.getEmittedFileGeneric(&self.emit_directory); |
| 815 | 726 | } |
| 816 | 727 | |
| 817 | /// deprecated: use `getEmittedBin` | |
| 818 | pub const getOutputSource = getEmittedBin; | |
| 819 | ||
| 820 | 728 | /// Returns the path to the generated executable, library or object file. |
| 821 | 729 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. |
| 822 | 730 | pub fn getEmittedBin(self: *Compile) LazyPath { |
| 823 | 731 | return self.getEmittedFileGeneric(&self.generated_bin); |
| 824 | 732 | } |
| 825 | 733 | |
| 826 | /// deprecated: use `getEmittedImplib` | |
| 827 | pub const getOutputLibSource = getEmittedImplib; | |
| 828 | ||
| 829 | 734 | /// Returns the path to the generated import library. |
| 830 | 735 | /// This function can only be called for libraries. |
| 831 | 736 | pub fn getEmittedImplib(self: *Compile) LazyPath { |
| ... | ... | @@ -833,9 +738,6 @@ pub fn getEmittedImplib(self: *Compile) LazyPath { |
| 833 | 738 | return self.getEmittedFileGeneric(&self.generated_implib); |
| 834 | 739 | } |
| 835 | 740 | |
| 836 | /// deprecated: use `getEmittedH` | |
| 837 | pub const getOutputHSource = getEmittedH; | |
| 838 | ||
| 839 | 741 | /// Returns the path to the generated header file. |
| 840 | 742 | /// This function can only be called for libraries or objects. |
| 841 | 743 | pub fn getEmittedH(self: *Compile) LazyPath { |
| ... | ... | @@ -843,9 +745,6 @@ pub fn getEmittedH(self: *Compile) LazyPath { |
| 843 | 745 | return self.getEmittedFileGeneric(&self.generated_h); |
| 844 | 746 | } |
| 845 | 747 | |
| 846 | /// deprecated: use `getEmittedPdb`. | |
| 847 | pub const getOutputPdbSource = getEmittedPdb; | |
| 848 | ||
| 849 | 748 | /// Returns the generated PDB file. |
| 850 | 749 | /// If the compilation does not produce a PDB file, this causes a FileNotFound error |
| 851 | 750 | /// at build time. |
| ... | ... | @@ -882,56 +781,44 @@ pub fn addObjectFile(self: *Compile, source: LazyPath) void { |
| 882 | 781 | self.root_module.addObjectFile(source); |
| 883 | 782 | } |
| 884 | 783 | |
| 885 | pub fn addObject(self: *Compile, obj: *Compile) void { | |
| 886 | assert(obj.kind == .obj); | |
| 887 | self.linkLibraryOrObject(obj); | |
| 784 | pub fn addObject(self: *Compile, object: *Compile) void { | |
| 785 | self.root_module.addObject(object); | |
| 888 | 786 | } |
| 889 | 787 | |
| 890 | pub fn addAfterIncludePath(self: *Compile, path: LazyPath) void { | |
| 891 | const b = self.step.owner; | |
| 892 | self.include_dirs.append(.{ .path_after = path.dupe(b) }) catch @panic("OOM"); | |
| 893 | path.addStepDependencies(&self.step); | |
| 788 | pub fn linkLibrary(self: *Compile, library: *Compile) void { | |
| 789 | self.root_module.linkLibrary(library); | |
| 894 | 790 | } |
| 895 | 791 | |
| 896 | pub fn addSystemIncludePath(self: *Compile, path: LazyPath) void { | |
| 897 | const b = self.step.owner; | |
| 898 | self.include_dirs.append(.{ .path_system = path.dupe(b) }) catch @panic("OOM"); | |
| 899 | path.addStepDependencies(&self.step); | |
| 792 | pub fn addAfterIncludePath(self: *Compile, lazy_path: LazyPath) void { | |
| 793 | self.root_module.addAfterIncludePath(lazy_path); | |
| 900 | 794 | } |
| 901 | 795 | |
| 902 | pub fn addIncludePath(self: *Compile, path: LazyPath) void { | |
| 903 | const b = self.step.owner; | |
| 904 | self.include_dirs.append(.{ .path = path.dupe(b) }) catch @panic("OOM"); | |
| 905 | path.addStepDependencies(&self.step); | |
| 796 | pub fn addSystemIncludePath(self: *Compile, lazy_path: LazyPath) void { | |
| 797 | self.root_module.addSystemIncludePath(lazy_path); | |
| 798 | } | |
| 799 | ||
| 800 | pub fn addIncludePath(self: *Compile, lazy_path: LazyPath) void { | |
| 801 | self.root_module.addIncludePath(lazy_path); | |
| 906 | 802 | } |
| 907 | 803 | |
| 908 | 804 | pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void { |
| 909 | self.step.dependOn(&config_header.step); | |
| 910 | self.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM"); | |
| 805 | self.root_module.addConfigHeader(config_header); | |
| 911 | 806 | } |
| 912 | 807 | |
| 913 | pub fn addLibraryPath(self: *Compile, directory_source: LazyPath) void { | |
| 914 | const b = self.step.owner; | |
| 915 | self.lib_paths.append(directory_source.dupe(b)) catch @panic("OOM"); | |
| 916 | directory_source.addStepDependencies(&self.step); | |
| 808 | pub fn addLibraryPath(self: *Compile, directory_path: LazyPath) void { | |
| 809 | self.root_module.addLibraryPath(directory_path); | |
| 917 | 810 | } |
| 918 | 811 | |
| 919 | pub fn addRPath(self: *Compile, directory_source: LazyPath) void { | |
| 920 | const b = self.step.owner; | |
| 921 | self.rpaths.append(directory_source.dupe(b)) catch @panic("OOM"); | |
| 922 | directory_source.addStepDependencies(&self.step); | |
| 812 | pub fn addRPath(self: *Compile, directory_path: LazyPath) void { | |
| 813 | self.root_module.addRPath(directory_path); | |
| 923 | 814 | } |
| 924 | 815 | |
| 925 | pub fn addSystemFrameworkPath(self: *Compile, directory_source: LazyPath) void { | |
| 926 | const b = self.step.owner; | |
| 927 | self.include_dirs.append(.{ .framework_path_system = directory_source.dupe(b) }) catch @panic("OOM"); | |
| 928 | directory_source.addStepDependencies(&self.step); | |
| 816 | pub fn addSystemFrameworkPath(self: *Compile, directory_path: LazyPath) void { | |
| 817 | self.root_module.addSystemFrameworkPath(directory_path); | |
| 929 | 818 | } |
| 930 | 819 | |
| 931 | pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void { | |
| 932 | const b = self.step.owner; | |
| 933 | self.include_dirs.append(.{ .framework_path = directory_source.dupe(b) }) catch @panic("OOM"); | |
| 934 | directory_source.addStepDependencies(&self.step); | |
| 820 | pub fn addFrameworkPath(self: *Compile, directory_path: LazyPath) void { | |
| 821 | self.root_module.addFrameworkPath(directory_path); | |
| 935 | 822 | } |
| 936 | 823 | |
| 937 | 824 | pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { |
| ... | ... | @@ -944,20 +831,6 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { |
| 944 | 831 | self.exec_cmd_args = duped_args; |
| 945 | 832 | } |
| 946 | 833 | |
| 947 | fn linkLibraryOrObject(self: *Compile, other: *Compile) void { | |
| 948 | other.getEmittedBin().addStepDependencies(&self.step); | |
| 949 | if (other.target.isWindows() and other.isDynamicLibrary()) { | |
| 950 | other.getEmittedImplib().addStepDependencies(&self.step); | |
| 951 | } | |
| 952 | ||
| 953 | self.link_objects.append(.{ .other_step = other }) catch @panic("OOM"); | |
| 954 | self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM"); | |
| 955 | ||
| 956 | for (other.installed_headers.items) |install_step| { | |
| 957 | self.step.dependOn(install_step); | |
| 958 | } | |
| 959 | } | |
| 960 | ||
| 961 | 834 | fn appendModuleArgs(cs: *Compile, zig_args: *ArrayList([]const u8)) !void { |
| 962 | 835 | const b = cs.step.owner; |
| 963 | 836 | // First, traverse the whole dependency graph and give every module a |
| ... | ... | @@ -1014,7 +887,7 @@ fn appendModuleArgs(cs: *Compile, zig_args: *ArrayList([]const u8)) !void { |
| 1014 | 887 | fn constructDepString( |
| 1015 | 888 | allocator: std.mem.Allocator, |
| 1016 | 889 | mod_names: std.AutoArrayHashMapUnmanaged(*Module, []const u8), |
| 1017 | deps: std.StringArrayHashMap(*Module), | |
| 890 | deps: std.StringArrayHashMapUnmanaged(*Module), | |
| 1018 | 891 | ) ![]const u8 { |
| 1019 | 892 | var deps_str = std.ArrayList(u8).init(allocator); |
| 1020 | 893 | var it = deps.iterator(); |
| ... | ... | @@ -1082,7 +955,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1082 | 955 | try addFlag(&zig_args, "llvm", self.use_llvm); |
| 1083 | 956 | try addFlag(&zig_args, "lld", self.use_lld); |
| 1084 | 957 | |
| 1085 | if (self.root_module.target.ofmt) |ofmt| { | |
| 958 | if (self.root_module.target.?.query.ofmt) |ofmt| { | |
| 1086 | 959 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "-ofmt={s}", .{@tagName(ofmt)})); |
| 1087 | 960 | } |
| 1088 | 961 | |
| ... | ... | @@ -1110,7 +983,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1110 | 983 | |
| 1111 | 984 | { |
| 1112 | 985 | var seen_system_libs: std.StringHashMapUnmanaged(void) = .{}; |
| 1113 | var frameworks: std.StringArrayHashMapUnmanaged(Module.FrameworkLinkInfo) = .{}; | |
| 986 | var frameworks: std.StringArrayHashMapUnmanaged(Module.LinkFrameworkOptions) = .{}; | |
| 1114 | 987 | |
| 1115 | 988 | var prev_has_cflags = false; |
| 1116 | 989 | var prev_has_rcflags = false; |
| ... | ... | @@ -1240,7 +1113,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1240 | 1113 | try zig_args.append(full_path_lib); |
| 1241 | 1114 | |
| 1242 | 1115 | if (other.linkage == Linkage.dynamic and |
| 1243 | self.root_module.target_info.target.os.tag != .windows) | |
| 1116 | self.rootModuleTarget().os.tag != .windows) | |
| 1244 | 1117 | { |
| 1245 | 1118 | if (fs.path.dirname(full_path_lib)) |dirname| { |
| 1246 | 1119 | try zig_args.append("-rpath"); |
| ... | ... | @@ -1471,11 +1344,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1471 | 1344 | try zig_args.append(b.fmt("{}", .{version})); |
| 1472 | 1345 | } |
| 1473 | 1346 | |
| 1474 | if (self.root_module.target_info.target.isDarwin()) { | |
| 1347 | if (self.rootModuleTarget().isDarwin()) { | |
| 1475 | 1348 | const install_name = self.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ |
| 1476 | self.root_module.target_info.target.libPrefix(), | |
| 1349 | self.rootModuleTarget().libPrefix(), | |
| 1477 | 1350 | self.name, |
| 1478 | self.root_module.target_info.target.dynamicLibSuffix(), | |
| 1351 | self.rootModuleTarget().dynamicLibSuffix(), | |
| 1479 | 1352 | }); |
| 1480 | 1353 | try zig_args.append("-install_name"); |
| 1481 | 1354 | try zig_args.append(install_name); |
| ... | ... | @@ -1763,7 +1636,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1763 | 1636 | } |
| 1764 | 1637 | |
| 1765 | 1638 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and |
| 1766 | self.version != null and self.root_module.target.wantSharedLibSymLinks()) | |
| 1639 | self.version != null and std.Build.wantSharedLibSymLinks(self.rootModuleTarget())) | |
| 1767 | 1640 | { |
| 1768 | 1641 | try doAtomicSymLinks( |
| 1769 | 1642 | step, |
| ... | ... | @@ -1932,3 +1805,8 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool { |
| 1932 | 1805 | } |
| 1933 | 1806 | return false; |
| 1934 | 1807 | } |
| 1808 | ||
| 1809 | pub fn rootModuleTarget(c: *Compile) std.Target { | |
| 1810 | // The root module is always given a target, so we know this to be non-null. | |
| 1811 | return c.root_module.target.?.target; | |
| 1812 | } |
lib/std/Build/Step/ConfigHeader.zig-6| ... | ... | @@ -15,9 +15,6 @@ pub const Style = union(enum) { |
| 15 | 15 | /// Start with nothing, like blank, and output a nasm .asm file. |
| 16 | 16 | nasm, |
| 17 | 17 | |
| 18 | /// deprecated: use `getPath` | |
| 19 | pub const getFileSource = getPath; | |
| 20 | ||
| 21 | 18 | pub fn getPath(style: Style) ?std.Build.LazyPath { |
| 22 | 19 | switch (style) { |
| 23 | 20 | .autoconf, .cmake => |s| return s, |
| ... | ... | @@ -107,9 +104,6 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { |
| 107 | 104 | return addValuesInner(self, values) catch @panic("OOM"); |
| 108 | 105 | } |
| 109 | 106 | |
| 110 | /// deprecated: use `getOutput` | |
| 111 | pub const getFileSource = getOutput; | |
| 112 | ||
| 113 | 107 | pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { |
| 114 | 108 | return .{ .generated = &self.output_file }; |
| 115 | 109 | } |
lib/std/Build/Step/InstallArtifact.zig+1-1| ... | ... | @@ -94,7 +94,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins |
| 94 | 94 | .dylib_symlinks = if (options.dylib_symlinks orelse (dest_dir != null and |
| 95 | 95 | artifact.isDynamicLibrary() and |
| 96 | 96 | artifact.version != null and |
| 97 | artifact.target.wantSharedLibSymLinks())) .{ | |
| 97 | std.Build.wantSharedLibSymLinks(artifact.rootModuleTarget()))) .{ | |
| 98 | 98 | .major_only_filename = artifact.major_only_filename.?, |
| 99 | 99 | .name_only_filename = artifact.name_only_filename.?, |
| 100 | 100 | } else null, |
lib/std/Build/Step/Options.zig+1-5| ... | ... | @@ -165,9 +165,6 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | /// deprecated: use `addOptionPath` | |
| 169 | pub const addOptionFileSource = addOptionPath; | |
| 170 | ||
| 171 | 168 | /// The value is the path in the cache dir. |
| 172 | 169 | /// Adds a dependency automatically. |
| 173 | 170 | pub fn addOptionPath( |
| ... | ... | @@ -189,8 +186,7 @@ pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compi |
| 189 | 186 | |
| 190 | 187 | pub fn createModule(self: *Options) *std.Build.Module { |
| 191 | 188 | return self.step.owner.createModule(.{ |
| 192 | .source_file = self.getOutput(), | |
| 193 | .dependencies = &.{}, | |
| 189 | .root_source_file = self.getOutput(), | |
| 194 | 190 | }); |
| 195 | 191 | } |
| 196 | 192 |
lib/std/Build/Step/Run.zig+11-16| ... | ... | @@ -197,16 +197,10 @@ pub fn addPrefixedOutputFileArg( |
| 197 | 197 | return .{ .generated = &output.generated_file }; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | /// deprecated: use `addFileArg` | |
| 201 | pub const addFileSourceArg = addFileArg; | |
| 202 | ||
| 203 | 200 | pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void { |
| 204 | 201 | self.addPrefixedFileArg("", lp); |
| 205 | 202 | } |
| 206 | 203 | |
| 207 | // deprecated: use `addPrefixedFileArg` | |
| 208 | pub const addPrefixedFileSourceArg = addPrefixedFileArg; | |
| 209 | ||
| 210 | 204 | pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath) void { |
| 211 | 205 | const b = self.step.owner; |
| 212 | 206 | |
| ... | ... | @@ -488,7 +482,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 488 | 482 | man.hash.addBytes(file_path); |
| 489 | 483 | }, |
| 490 | 484 | .artifact => |artifact| { |
| 491 | if (artifact.root_module.target_info.target.os.tag == .windows) { | |
| 485 | if (artifact.rootModuleTarget().os.tag == .windows) { | |
| 492 | 486 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 493 | 487 | self.addPathForDynLibs(artifact); |
| 494 | 488 | } |
| ... | ... | @@ -682,9 +676,10 @@ fn runCommand( |
| 682 | 676 | else => break :interpret, |
| 683 | 677 | } |
| 684 | 678 | |
| 685 | const need_cross_glibc = exe.root_module.target_info.target.isGnuLibC() and | |
| 679 | const need_cross_glibc = exe.rootModuleTarget().isGnuLibC() and | |
| 686 | 680 | exe.is_linking_libc; |
| 687 | switch (b.host.getExternalExecutor(&exe.root_module.target_info, .{ | |
| 681 | const other_target_info = exe.root_module.target.?.toNativeTargetInfo(); | |
| 682 | switch (b.host.toNativeTargetInfo().getExternalExecutor(&other_target_info, .{ | |
| 688 | 683 | .qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null, |
| 689 | 684 | .link_libc = exe.is_linking_libc, |
| 690 | 685 | })) { |
| ... | ... | @@ -715,9 +710,9 @@ fn runCommand( |
| 715 | 710 | // needs the directory to be called "i686" rather than |
| 716 | 711 | // "x86" which is why we do it manually here. |
| 717 | 712 | const fmt_str = "{s}" ++ fs.path.sep_str ++ "{s}-{s}-{s}"; |
| 718 | const cpu_arch = exe.root_module.target_info.target.cpu.arch; | |
| 719 | const os_tag = exe.root_module.target_info.target.os.tag; | |
| 720 | const abi = exe.root_module.target_info.target.abi; | |
| 713 | const cpu_arch = exe.rootModuleTarget().cpu.arch; | |
| 714 | const os_tag = exe.rootModuleTarget().os.tag; | |
| 715 | const abi = exe.rootModuleTarget().abi; | |
| 721 | 716 | const cpu_arch_name: []const u8 = if (cpu_arch == .x86) |
| 722 | 717 | "i686" |
| 723 | 718 | else |
| ... | ... | @@ -770,7 +765,7 @@ fn runCommand( |
| 770 | 765 | if (allow_skip) return error.MakeSkipped; |
| 771 | 766 | |
| 772 | 767 | const host_name = try b.host.target.zigTriple(b.allocator); |
| 773 | const foreign_name = try exe.root_module.target_info.target.zigTriple(b.allocator); | |
| 768 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); | |
| 774 | 769 | |
| 775 | 770 | return step.fail("the host system ({s}) is unable to execute binaries from the target ({s})", .{ |
| 776 | 771 | host_name, foreign_name, |
| ... | ... | @@ -778,7 +773,7 @@ fn runCommand( |
| 778 | 773 | }, |
| 779 | 774 | } |
| 780 | 775 | |
| 781 | if (exe.root_module.target_info.target.os.tag == .windows) { | |
| 776 | if (exe.rootModuleTarget().os.tag == .windows) { | |
| 782 | 777 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 783 | 778 | self.addPathForDynLibs(exe); |
| 784 | 779 | } |
| ... | ... | @@ -1300,7 +1295,7 @@ fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void { |
| 1300 | 1295 | while (it.next()) |item| { |
| 1301 | 1296 | const other = item.compile.?; |
| 1302 | 1297 | if (item.module == &other.root_module) { |
| 1303 | if (item.module.target_info.target.os.tag == .windows and other.isDynamicLibrary()) { | |
| 1298 | if (item.module.target.?.target.os.tag == .windows and other.isDynamicLibrary()) { | |
| 1304 | 1299 | addPathDir(self, fs.path.dirname(other.getEmittedBin().getPath(b)).?); |
| 1305 | 1300 | addPathForDynLibs(self, other); |
| 1306 | 1301 | } |
| ... | ... | @@ -1321,7 +1316,7 @@ fn failForeign( |
| 1321 | 1316 | |
| 1322 | 1317 | const b = self.step.owner; |
| 1323 | 1318 | const host_name = try b.host.target.zigTriple(b.allocator); |
| 1324 | const foreign_name = try exe.root_module.target_info.target.zigTriple(b.allocator); | |
| 1319 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); | |
| 1325 | 1320 | |
| 1326 | 1321 | return self.step.fail( |
| 1327 | 1322 | \\unable to spawn foreign binary '{s}' ({s}) on host system ({s}) |
lib/std/Build/Step/TranslateC.zig+5-6| ... | ... | @@ -2,7 +2,6 @@ const std = @import("std"); |
| 2 | 2 | const Step = std.Build.Step; |
| 3 | 3 | const fs = std.fs; |
| 4 | 4 | const mem = std.mem; |
| 5 | const CrossTarget = std.zig.CrossTarget; | |
| 6 | 5 | |
| 7 | 6 | const TranslateC = @This(); |
| 8 | 7 | |
| ... | ... | @@ -13,7 +12,7 @@ source: std.Build.LazyPath, |
| 13 | 12 | include_dirs: std.ArrayList([]const u8), |
| 14 | 13 | c_macros: std.ArrayList([]const u8), |
| 15 | 14 | out_basename: []const u8, |
| 16 | target: CrossTarget, | |
| 15 | target: std.Build.ResolvedTarget, | |
| 17 | 16 | optimize: std.builtin.OptimizeMode, |
| 18 | 17 | output_file: std.Build.GeneratedFile, |
| 19 | 18 | link_libc: bool, |
| ... | ... | @@ -21,7 +20,7 @@ use_clang: bool, |
| 21 | 20 | |
| 22 | 21 | pub const Options = struct { |
| 23 | 22 | source_file: std.Build.LazyPath, |
| 24 | target: CrossTarget, | |
| 23 | target: std.Build.ResolvedTarget, | |
| 25 | 24 | optimize: std.builtin.OptimizeMode, |
| 26 | 25 | link_libc: bool = true, |
| 27 | 26 | use_clang: bool = true, |
| ... | ... | @@ -54,7 +53,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC { |
| 54 | 53 | pub const AddExecutableOptions = struct { |
| 55 | 54 | name: ?[]const u8 = null, |
| 56 | 55 | version: ?std.SemanticVersion = null, |
| 57 | target: ?CrossTarget = null, | |
| 56 | target: ?std.Build.ResolvedTarget = null, | |
| 58 | 57 | optimize: ?std.builtin.OptimizeMode = null, |
| 59 | 58 | linkage: ?Step.Compile.Linkage = null, |
| 60 | 59 | }; |
| ... | ... | @@ -139,9 +138,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 139 | 138 | |
| 140 | 139 | try argv_list.append("--listen=-"); |
| 141 | 140 | |
| 142 | if (!self.target.isNative()) { | |
| 141 | if (!self.target.query.isNative()) { | |
| 143 | 142 | try argv_list.append("-target"); |
| 144 | try argv_list.append(try self.target.zigTriple(b.allocator)); | |
| 143 | try argv_list.append(try self.target.query.zigTriple(b.allocator)); | |
| 145 | 144 | } |
| 146 | 145 | |
| 147 | 146 | switch (self.optimize) { |
lib/std/Build/Step/WriteFile.zig-7| ... | ... | @@ -28,9 +28,6 @@ pub const File = struct { |
| 28 | 28 | sub_path: []const u8, |
| 29 | 29 | contents: Contents, |
| 30 | 30 | |
| 31 | /// deprecated: use `getPath` | |
| 32 | pub const getFileSource = getPath; | |
| 33 | ||
| 34 | 31 | pub fn getPath(self: *File) std.Build.LazyPath { |
| 35 | 32 | return .{ .generated = &self.generated_file }; |
| 36 | 33 | } |
| ... | ... | @@ -126,10 +123,6 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) |
| 126 | 123 | }) catch @panic("OOM"); |
| 127 | 124 | } |
| 128 | 125 | |
| 129 | pub const getFileSource = @compileError("Deprecated; use the return value from add()/addCopyFile(), or use files[i].getPath()"); | |
| 130 | ||
| 131 | pub const getDirectorySource = getDirectory; | |
| 132 | ||
| 133 | 126 | /// Returns a `LazyPath` representing the base directory that contains all the |
| 134 | 127 | /// files from this `WriteFile`. |
| 135 | 128 | pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath { |
lib/std/std.zig-3| ... | ... | @@ -194,9 +194,6 @@ pub const zig = @import("zig.zig"); |
| 194 | 194 | |
| 195 | 195 | pub const start = @import("start.zig"); |
| 196 | 196 | |
| 197 | /// deprecated: use `Build`. | |
| 198 | pub const build = Build; | |
| 199 | ||
| 200 | 197 | const root = @import("root"); |
| 201 | 198 | const options_override = if (@hasDecl(root, "std_options")) root.std_options else struct {}; |
| 202 | 199 |
lib/std/zig.zig+77| ... | ... | @@ -203,6 +203,83 @@ pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | pub const BuildId = union(enum) { | |
| 207 | none, | |
| 208 | fast, | |
| 209 | uuid, | |
| 210 | sha1, | |
| 211 | md5, | |
| 212 | hexstring: HexString, | |
| 213 | ||
| 214 | pub fn eql(a: BuildId, b: BuildId) bool { | |
| 215 | const Tag = @TypeOf(BuildId).Union.tag_type.?; | |
| 216 | const a_tag: Tag = a; | |
| 217 | const b_tag: Tag = b; | |
| 218 | if (a_tag != b_tag) return false; | |
| 219 | return switch (a) { | |
| 220 | .none, .fast, .uuid, .sha1, .md5 => true, | |
| 221 | .hexstring => |a_hexstring| std.mem.eql(u8, a_hexstring.toSlice(), b.hexstring.toSlice()), | |
| 222 | }; | |
| 223 | } | |
| 224 | ||
| 225 | pub const HexString = struct { | |
| 226 | bytes: [32]u8, | |
| 227 | len: u8, | |
| 228 | ||
| 229 | /// Result is byte values, *not* hex-encoded. | |
| 230 | pub fn toSlice(hs: *const HexString) []const u8 { | |
| 231 | return hs.bytes[0..hs.len]; | |
| 232 | } | |
| 233 | }; | |
| 234 | ||
| 235 | /// Input is byte values, *not* hex-encoded. | |
| 236 | /// Asserts `bytes` fits inside `HexString` | |
| 237 | pub fn initHexString(bytes: []const u8) BuildId { | |
| 238 | var result: BuildId = .{ .hexstring = .{ | |
| 239 | .bytes = undefined, | |
| 240 | .len = @intCast(bytes.len), | |
| 241 | } }; | |
| 242 | @memcpy(result.hexstring.bytes[0..bytes.len], bytes); | |
| 243 | return result; | |
| 244 | } | |
| 245 | ||
| 246 | /// Converts UTF-8 text to a `BuildId`. | |
| 247 | pub fn parse(text: []const u8) !BuildId { | |
| 248 | if (std.mem.eql(u8, text, "none")) { | |
| 249 | return .none; | |
| 250 | } else if (std.mem.eql(u8, text, "fast")) { | |
| 251 | return .fast; | |
| 252 | } else if (std.mem.eql(u8, text, "uuid")) { | |
| 253 | return .uuid; | |
| 254 | } else if (std.mem.eql(u8, text, "sha1") or std.mem.eql(u8, text, "tree")) { | |
| 255 | return .sha1; | |
| 256 | } else if (std.mem.eql(u8, text, "md5")) { | |
| 257 | return .md5; | |
| 258 | } else if (std.mem.startsWith(u8, text, "0x")) { | |
| 259 | var result: BuildId = .{ .hexstring = undefined }; | |
| 260 | const slice = try std.fmt.hexToBytes(&result.hexstring.bytes, text[2..]); | |
| 261 | result.hexstring.len = @as(u8, @intCast(slice.len)); | |
| 262 | return result; | |
| 263 | } | |
| 264 | return error.InvalidBuildIdStyle; | |
| 265 | } | |
| 266 | ||
| 267 | test parse { | |
| 268 | try std.testing.expectEqual(BuildId.md5, try parse("md5")); | |
| 269 | try std.testing.expectEqual(BuildId.none, try parse("none")); | |
| 270 | try std.testing.expectEqual(BuildId.fast, try parse("fast")); | |
| 271 | try std.testing.expectEqual(BuildId.uuid, try parse("uuid")); | |
| 272 | try std.testing.expectEqual(BuildId.sha1, try parse("sha1")); | |
| 273 | try std.testing.expectEqual(BuildId.sha1, try parse("tree")); | |
| 274 | ||
| 275 | try std.testing.expect(BuildId.initHexString("").eql(try parse("0x"))); | |
| 276 | try std.testing.expect(BuildId.initHexString("\x12\x34\x56").eql(try parse("0x123456"))); | |
| 277 | try std.testing.expectError(error.InvalidLength, parse("0x12-34")); | |
| 278 | try std.testing.expectError(error.InvalidCharacter, parse("0xfoobbb")); | |
| 279 | try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx")); | |
| 280 | } | |
| 281 | }; | |
| 282 | ||
| 206 | 283 | test { |
| 207 | 284 | @import("std").testing.refAllDecls(@This()); |
| 208 | 285 | } |
lib/std/zig/CrossTarget.zig-4| ... | ... | @@ -632,10 +632,6 @@ pub fn linuxTriple(self: CrossTarget, allocator: mem.Allocator) ![]u8 { |
| 632 | 632 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | pub fn wantSharedLibSymLinks(self: CrossTarget) bool { | |
| 636 | return self.getOsTag() != .windows; | |
| 637 | } | |
| 638 | ||
| 639 | 635 | pub fn isGnuLibC(self: CrossTarget) bool { |
| 640 | 636 | return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi()); |
| 641 | 637 | } |
lib/std/zig/system/NativeTargetInfo.zig+2-2| ... | ... | @@ -1008,8 +1008,8 @@ pub const GetExternalExecutorOptions = struct { |
| 1008 | 1008 | link_libc: bool = false, |
| 1009 | 1009 | }; |
| 1010 | 1010 | |
| 1011 | /// Return whether or not the given host target is capable of executing natively executables | |
| 1012 | /// of the other target. | |
| 1011 | /// Return whether or not the given host is capable of running executables of | |
| 1012 | /// the other target. | |
| 1013 | 1013 | pub fn getExternalExecutor( |
| 1014 | 1014 | host: NativeTargetInfo, |
| 1015 | 1015 | candidate: *const NativeTargetInfo, |
src/Compilation.zig+1-2| ... | ... | @@ -30,7 +30,6 @@ const fatal = @import("main.zig").fatal; |
| 30 | 30 | const clangMain = @import("main.zig").clangMain; |
| 31 | 31 | const Module = @import("Module.zig"); |
| 32 | 32 | const InternPool = @import("InternPool.zig"); |
| 33 | const BuildId = std.Build.CompileStep.BuildId; | |
| 34 | 33 | const Cache = std.Build.Cache; |
| 35 | 34 | const c_codegen = @import("codegen/c.zig"); |
| 36 | 35 | const libtsan = @import("libtsan.zig"); |
| ... | ... | @@ -910,7 +909,7 @@ pub const InitOptions = struct { |
| 910 | 909 | linker_print_map: bool = false, |
| 911 | 910 | linker_opt_bisect_limit: i32 = -1, |
| 912 | 911 | each_lib_rpath: ?bool = null, |
| 913 | build_id: ?BuildId = null, | |
| 912 | build_id: ?std.zig.BuildId = null, | |
| 914 | 913 | disable_c_depfile: bool = false, |
| 915 | 914 | linker_z_nodelete: bool = false, |
| 916 | 915 | linker_z_notext: bool = false, |
src/link.zig+1-2| ... | ... | @@ -10,7 +10,6 @@ const wasi_libc = @import("wasi_libc.zig"); |
| 10 | 10 | |
| 11 | 11 | const Air = @import("Air.zig"); |
| 12 | 12 | const Allocator = std.mem.Allocator; |
| 13 | const BuildId = std.Build.CompileStep.BuildId; | |
| 14 | 13 | const Cache = std.Build.Cache; |
| 15 | 14 | const Compilation = @import("Compilation.zig"); |
| 16 | 15 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| ... | ... | @@ -185,7 +184,7 @@ pub const Options = struct { |
| 185 | 184 | error_return_tracing: bool, |
| 186 | 185 | skip_linker_dependencies: bool, |
| 187 | 186 | each_lib_rpath: bool, |
| 188 | build_id: BuildId, | |
| 187 | build_id: std.zig.BuildId, | |
| 189 | 188 | disable_lld_caching: bool, |
| 190 | 189 | is_test: bool, |
| 191 | 190 | hash_style: HashStyle, |
src/main.zig+3-4| ... | ... | @@ -21,7 +21,6 @@ const introspect = @import("introspect.zig"); |
| 21 | 21 | const EnvVar = introspect.EnvVar; |
| 22 | 22 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| 23 | 23 | const wasi_libc = @import("wasi_libc.zig"); |
| 24 | const BuildId = std.Build.CompileStep.BuildId; | |
| 25 | 24 | const Cache = std.Build.Cache; |
| 26 | 25 | const target_util = @import("target.zig"); |
| 27 | 26 | const crash_report = @import("crash_report.zig"); |
| ... | ... | @@ -882,7 +881,7 @@ fn buildOutputType( |
| 882 | 881 | var link_eh_frame_hdr = false; |
| 883 | 882 | var link_emit_relocs = false; |
| 884 | 883 | var each_lib_rpath: ?bool = null; |
| 885 | var build_id: ?BuildId = null; | |
| 884 | var build_id: ?std.zig.BuildId = null; | |
| 886 | 885 | var sysroot: ?[]const u8 = null; |
| 887 | 886 | var libc_paths_file: ?[]const u8 = try EnvVar.ZIG_LIBC.get(arena); |
| 888 | 887 | var machine_code_model: std.builtin.CodeModel = .default; |
| ... | ... | @@ -1551,7 +1550,7 @@ fn buildOutputType( |
| 1551 | 1550 | build_id = .fast; |
| 1552 | 1551 | } else if (mem.startsWith(u8, arg, "--build-id=")) { |
| 1553 | 1552 | const style = arg["--build-id=".len..]; |
| 1554 | build_id = BuildId.parse(style) catch |err| { | |
| 1553 | build_id = std.zig.BuildId.parse(style) catch |err| { | |
| 1555 | 1554 | fatal("unable to parse --build-id style '{s}': {s}", .{ |
| 1556 | 1555 | style, @errorName(err), |
| 1557 | 1556 | }); |
| ... | ... | @@ -1847,7 +1846,7 @@ fn buildOutputType( |
| 1847 | 1846 | const key = linker_arg[0..equals_pos]; |
| 1848 | 1847 | const value = linker_arg[equals_pos + 1 ..]; |
| 1849 | 1848 | if (mem.eql(u8, key, "--build-id")) { |
| 1850 | build_id = BuildId.parse(value) catch |err| { | |
| 1849 | build_id = std.zig.BuildId.parse(value) catch |err| { | |
| 1851 | 1850 | fatal("unable to parse --build-id style '{s}': {s}", .{ |
| 1852 | 1851 | value, @errorName(err), |
| 1853 | 1852 | }); |
test/behavior/eval.zig+10-10| ... | ... | @@ -876,27 +876,27 @@ test "two comptime calls with array default initialized to undefined" { |
| 876 | 876 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 877 | 877 | |
| 878 | 878 | const S = struct { |
| 879 | const CrossTarget = struct { | |
| 880 | dynamic_linker: DynamicLinker = DynamicLinker{}, | |
| 879 | const A = struct { | |
| 880 | c: B = B{}, | |
| 881 | 881 | |
| 882 | pub fn parse() void { | |
| 883 | var result: CrossTarget = .{}; | |
| 884 | result.getCpuArch(); | |
| 882 | pub fn d() void { | |
| 883 | var f: A = .{}; | |
| 884 | f.e(); | |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | pub fn getCpuArch(self: CrossTarget) void { | |
| 888 | _ = self; | |
| 887 | pub fn e(g: A) void { | |
| 888 | _ = g; | |
| 889 | 889 | } |
| 890 | 890 | }; |
| 891 | 891 | |
| 892 | const DynamicLinker = struct { | |
| 892 | const B = struct { | |
| 893 | 893 | buffer: [255]u8 = undefined, |
| 894 | 894 | }; |
| 895 | 895 | }; |
| 896 | 896 | |
| 897 | 897 | comptime { |
| 898 | S.CrossTarget.parse(); | |
| 899 | S.CrossTarget.parse(); | |
| 898 | S.A.d(); | |
| 899 | S.A.d(); | |
| 900 | 900 | } |
| 901 | 901 | } |
| 902 | 902 |
test/cases.zig+5-5| ... | ... | @@ -9,9 +9,9 @@ pub const BuildOptions = struct { |
| 9 | 9 | llvm_has_xtensa: bool, |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | pub fn addCases(cases: *Cases, build_options: BuildOptions) !void { | |
| 13 | try @import("compile_errors.zig").addCases(cases); | |
| 14 | try @import("cbe.zig").addCases(cases); | |
| 15 | try @import("llvm_targets.zig").addCases(cases, build_options); | |
| 16 | try @import("nvptx.zig").addCases(cases); | |
| 12 | pub fn addCases(cases: *Cases, build_options: BuildOptions, b: *std.Build) !void { | |
| 13 | try @import("compile_errors.zig").addCases(cases, b); | |
| 14 | try @import("cbe.zig").addCases(cases, b); | |
| 15 | try @import("llvm_targets.zig").addCases(cases, build_options, b); | |
| 16 | try @import("nvptx.zig").addCases(cases, b); | |
| 17 | 17 | } |
test/cbe.zig+24-24| ... | ... | @@ -2,16 +2,16 @@ const std = @import("std"); |
| 2 | 2 | const Cases = @import("src/Cases.zig"); |
| 3 | 3 | const nl = if (@import("builtin").os.tag == .windows) "\r\n" else "\n"; |
| 4 | 4 | |
| 5 | // These tests should work with all platforms, but we're using linux_x64 for | |
| 6 | // now for consistency. Will be expanded eventually. | |
| 7 | const linux_x64 = std.zig.CrossTarget{ | |
| 8 | .cpu_arch = .x86_64, | |
| 9 | .os_tag = .linux, | |
| 10 | }; | |
| 11 | ||
| 12 | pub fn addCases(ctx: *Cases) !void { | |
| 5 | pub fn addCases(ctx: *Cases, b: *std.Build) !void { | |
| 6 | // These tests should work with all platforms, but we're using linux_x64 for | |
| 7 | // now for consistency. Will be expanded eventually. | |
| 8 | const linux_x64: std.zig.CrossTarget = .{ | |
| 9 | .cpu_arch = .x86_64, | |
| 10 | .os_tag = .linux, | |
| 11 | }; | |
| 12 | ||
| 13 | 13 | { |
| 14 | var case = ctx.exeFromCompiledC("hello world with updates", .{}); | |
| 14 | var case = ctx.exeFromCompiledC("hello world with updates", .{}, b); | |
| 15 | 15 | |
| 16 | 16 | // Regular old hello world |
| 17 | 17 | case.addCompareOutput( |
| ... | ... | @@ -59,7 +59,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | { |
| 62 | var case = ctx.exeFromCompiledC("var args", .{}); | |
| 62 | var case = ctx.exeFromCompiledC("var args", .{}, b); | |
| 63 | 63 | |
| 64 | 64 | case.addCompareOutput( |
| 65 | 65 | \\extern fn printf(format: [*:0]const u8, ...) c_int; |
| ... | ... | @@ -72,7 +72,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | { |
| 75 | var case = ctx.exeFromCompiledC("errorFromInt", .{}); | |
| 75 | var case = ctx.exeFromCompiledC("errorFromInt", .{}, b); | |
| 76 | 76 | |
| 77 | 77 | case.addCompareOutput( |
| 78 | 78 | \\pub export fn main() c_int { |
| ... | ... | @@ -108,7 +108,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | { |
| 111 | var case = ctx.exeFromCompiledC("x86_64-linux inline assembly", linux_x64); | |
| 111 | var case = ctx.exeFromCompiledC("x86_64-linux inline assembly", linux_x64, b); | |
| 112 | 112 | |
| 113 | 113 | // Exit with 0 |
| 114 | 114 | case.addCompareOutput( |
| ... | ... | @@ -202,7 +202,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | { |
| 205 | var case = ctx.exeFromCompiledC("alloc and retptr", .{}); | |
| 205 | var case = ctx.exeFromCompiledC("alloc and retptr", .{}, b); | |
| 206 | 206 | |
| 207 | 207 | case.addCompareOutput( |
| 208 | 208 | \\fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -220,7 +220,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | { |
| 223 | var case = ctx.exeFromCompiledC("inferred local const and var", .{}); | |
| 223 | var case = ctx.exeFromCompiledC("inferred local const and var", .{}, b); | |
| 224 | 224 | |
| 225 | 225 | case.addCompareOutput( |
| 226 | 226 | \\fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -236,7 +236,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 236 | 236 | , ""); |
| 237 | 237 | } |
| 238 | 238 | { |
| 239 | var case = ctx.exeFromCompiledC("control flow", .{}); | |
| 239 | var case = ctx.exeFromCompiledC("control flow", .{}, b); | |
| 240 | 240 | |
| 241 | 241 | // Simple while loop |
| 242 | 242 | case.addCompareOutput( |
| ... | ... | @@ -423,7 +423,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 423 | 423 | }); |
| 424 | 424 | } |
| 425 | 425 | //{ |
| 426 | // var case = ctx.exeFromCompiledC("optionals", .{}); | |
| 426 | // var case = ctx.exeFromCompiledC("optionals", .{}, b); | |
| 427 | 427 | |
| 428 | 428 | // // Simple while loop |
| 429 | 429 | // case.addCompareOutput( |
| ... | ... | @@ -451,7 +451,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 451 | 451 | //} |
| 452 | 452 | |
| 453 | 453 | { |
| 454 | var case = ctx.exeFromCompiledC("errors", .{}); | |
| 454 | var case = ctx.exeFromCompiledC("errors", .{}, b); | |
| 455 | 455 | case.addCompareOutput( |
| 456 | 456 | \\pub export fn main() c_int { |
| 457 | 457 | \\ var e1 = error.Foo; |
| ... | ... | @@ -495,7 +495,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | { |
| 498 | var case = ctx.exeFromCompiledC("structs", .{}); | |
| 498 | var case = ctx.exeFromCompiledC("structs", .{}, b); | |
| 499 | 499 | case.addError( |
| 500 | 500 | \\const Point = struct { x: i32, y: i32 }; |
| 501 | 501 | \\pub export fn main() c_int { |
| ... | ... | @@ -562,7 +562,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | { |
| 565 | var case = ctx.exeFromCompiledC("unions", .{}); | |
| 565 | var case = ctx.exeFromCompiledC("unions", .{}, b); | |
| 566 | 566 | |
| 567 | 567 | case.addError( |
| 568 | 568 | \\const U = union { |
| ... | ... | @@ -596,7 +596,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | { |
| 599 | var case = ctx.exeFromCompiledC("enums", .{}); | |
| 599 | var case = ctx.exeFromCompiledC("enums", .{}, b); | |
| 600 | 600 | |
| 601 | 601 | case.addError( |
| 602 | 602 | \\const E1 = packed enum { a, b, c }; |
| ... | ... | @@ -838,7 +838,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | { |
| 841 | var case = ctx.exeFromCompiledC("shift right and left", .{}); | |
| 841 | var case = ctx.exeFromCompiledC("shift right and left", .{}, b); | |
| 842 | 842 | case.addCompareOutput( |
| 843 | 843 | \\pub export fn main() c_int { |
| 844 | 844 | \\ var i: u32 = 16; |
| ... | ... | @@ -863,7 +863,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | { |
| 866 | var case = ctx.exeFromCompiledC("inferred error sets", .{}); | |
| 866 | var case = ctx.exeFromCompiledC("inferred error sets", .{}, b); | |
| 867 | 867 | |
| 868 | 868 | case.addCompareOutput( |
| 869 | 869 | \\pub export fn main() c_int { |
| ... | ... | @@ -884,7 +884,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 884 | 884 | |
| 885 | 885 | { |
| 886 | 886 | // TODO: add u64 tests, ran into issues with the literal generated for std.math.maxInt(u64) |
| 887 | var case = ctx.exeFromCompiledC("add and sub wrapping operations", .{}); | |
| 887 | var case = ctx.exeFromCompiledC("add and sub wrapping operations", .{}, b); | |
| 888 | 888 | case.addCompareOutput( |
| 889 | 889 | \\pub export fn main() c_int { |
| 890 | 890 | \\ // Addition |
| ... | ... | @@ -933,7 +933,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | { |
| 936 | var case = ctx.exeFromCompiledC("rem", linux_x64); | |
| 936 | var case = ctx.exeFromCompiledC("rem", linux_x64, b); | |
| 937 | 937 | case.addCompareOutput( |
| 938 | 938 | \\fn assert(ok: bool) void { |
| 939 | 939 | \\ if (!ok) unreachable; |
test/compile_errors.zig+11-11| ... | ... | @@ -2,9 +2,9 @@ const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const Cases = @import("src/Cases.zig"); |
| 4 | 4 | |
| 5 | pub fn addCases(ctx: *Cases) !void { | |
| 5 | pub fn addCases(ctx: *Cases, b: *std.Build) !void { | |
| 6 | 6 | { |
| 7 | const case = ctx.obj("multiline error messages", .{}); | |
| 7 | const case = ctx.obj("multiline error messages", b.host); | |
| 8 | 8 | |
| 9 | 9 | case.addError( |
| 10 | 10 | \\comptime { |
| ... | ... | @@ -39,7 +39,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | { |
| 42 | const case = ctx.obj("isolated carriage return in multiline string literal", .{}); | |
| 42 | const case = ctx.obj("isolated carriage return in multiline string literal", b.host); | |
| 43 | 43 | |
| 44 | 44 | case.addError("const foo = \\\\\test\r\r rogue carriage return\n;", &[_][]const u8{ |
| 45 | 45 | ":1:19: error: expected ';' after declaration", |
| ... | ... | @@ -48,7 +48,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | { |
| 51 | const case = ctx.obj("missing semicolon at EOF", .{}); | |
| 51 | const case = ctx.obj("missing semicolon at EOF", b.host); | |
| 52 | 52 | case.addError( |
| 53 | 53 | \\const foo = 1 |
| 54 | 54 | , &[_][]const u8{ |
| ... | ... | @@ -57,7 +57,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | { |
| 60 | const case = ctx.obj("argument causes error", .{}); | |
| 60 | const case = ctx.obj("argument causes error", b.host); | |
| 61 | 61 | |
| 62 | 62 | case.addError( |
| 63 | 63 | \\pub export fn entry() void { |
| ... | ... | @@ -80,7 +80,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | { |
| 83 | const case = ctx.obj("astgen failure in file struct", .{}); | |
| 83 | const case = ctx.obj("astgen failure in file struct", b.host); | |
| 84 | 84 | |
| 85 | 85 | case.addError( |
| 86 | 86 | \\pub export fn entry() void { |
| ... | ... | @@ -95,7 +95,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | { |
| 98 | const case = ctx.obj("invalid store to comptime field", .{}); | |
| 98 | const case = ctx.obj("invalid store to comptime field", b.host); | |
| 99 | 99 | |
| 100 | 100 | case.addError( |
| 101 | 101 | \\const a = @import("a.zig"); |
| ... | ... | @@ -119,7 +119,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | { |
| 122 | const case = ctx.obj("file in multiple modules", .{}); | |
| 122 | const case = ctx.obj("file in multiple modules", b.host); | |
| 123 | 123 | case.addDepModule("foo", "foo.zig"); |
| 124 | 124 | |
| 125 | 125 | case.addError( |
| ... | ... | @@ -138,7 +138,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | { |
| 141 | const case = ctx.obj("wrong same named struct", .{}); | |
| 141 | const case = ctx.obj("wrong same named struct", b.host); | |
| 142 | 142 | |
| 143 | 143 | case.addError( |
| 144 | 144 | \\const a = @import("a.zig"); |
| ... | ... | @@ -172,7 +172,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | { |
| 175 | const case = ctx.obj("non-printable invalid character", .{}); | |
| 175 | const case = ctx.obj("non-printable invalid character", b.host); | |
| 176 | 176 | |
| 177 | 177 | case.addError("\xff\xfe" ++ |
| 178 | 178 | \\export fn foo() bool { |
| ... | ... | @@ -185,7 +185,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | { |
| 188 | const case = ctx.obj("imported generic method call with invalid param", .{}); | |
| 188 | const case = ctx.obj("imported generic method call with invalid param", b.host); | |
| 189 | 189 | |
| 190 | 190 | case.addError( |
| 191 | 191 | \\pub const import = @import("import.zig"); |
test/link/bss/build.zig+1| ... | ... | @@ -7,6 +7,7 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | const exe = b.addExecutable(.{ |
| 8 | 8 | .name = "bss", |
| 9 | 9 | .root_source_file = .{ .path = "main.zig" }, |
| 10 | .target = b.host, | |
| 10 | 11 | .optimize = .Debug, |
| 11 | 12 | }); |
| 12 | 13 |
test/link/common_symbols/build.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | 16 | .optimize = optimize, |
| 17 | .target = .{}, | |
| 17 | .target = b.host, | |
| 18 | 18 | }); |
| 19 | 19 | lib_a.addCSourceFiles(.{ |
| 20 | 20 | .files = &.{ "c.c", "a.c", "b.c" }, |
test/link/common_symbols_alignment/build.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | 16 | .optimize = optimize, |
| 17 | .target = .{}, | |
| 17 | .target = b.host, | |
| 18 | 18 | }); |
| 19 | 19 | lib_a.addCSourceFiles(.{ |
| 20 | 20 | .files = &.{"a.c"}, |
test/link/elf.zig+656-441| ... | ... | @@ -5,20 +5,20 @@ |
| 5 | 5 | pub fn testAll(b: *Build) *Step { |
| 6 | 6 | const elf_step = b.step("test-elf", "Run ELF tests"); |
| 7 | 7 | |
| 8 | const default_target = CrossTarget{ | |
| 8 | const default_target = b.resolveTargetQuery(.{ | |
| 9 | 9 | .cpu_arch = .x86_64, // TODO relax this once ELF linker is able to handle other archs |
| 10 | 10 | .os_tag = .linux, |
| 11 | }; | |
| 12 | const musl_target = CrossTarget{ | |
| 11 | }); | |
| 12 | const musl_target = b.resolveTargetQuery(.{ | |
| 13 | 13 | .cpu_arch = .x86_64, |
| 14 | 14 | .os_tag = .linux, |
| 15 | 15 | .abi = .musl, |
| 16 | }; | |
| 17 | const glibc_target = CrossTarget{ | |
| 16 | }); | |
| 17 | const glibc_target = b.resolveTargetQuery(.{ | |
| 18 | 18 | .cpu_arch = .x86_64, |
| 19 | 19 | .os_tag = .linux, |
| 20 | 20 | .abi = .gnu, |
| 21 | }; | |
| 21 | }); | |
| 22 | 22 | |
| 23 | 23 | // Exercise linker in -r mode |
| 24 | 24 | elf_step.dependOn(testEmitRelocatable(b, .{ .use_llvm = false, .target = musl_target })); |
| ... | ... | @@ -132,14 +132,18 @@ pub fn testAll(b: *Build) *Step { |
| 132 | 132 | fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| 133 | 133 | const test_step = addTestStep(b, "abs-symbols", opts); |
| 134 | 134 | |
| 135 | const obj = addObject(b, "obj", opts); | |
| 136 | addAsmSourceBytes(obj, | |
| 135 | const obj = addObject(b, opts, .{ | |
| 136 | .name = "obj", | |
| 137 | .asm_source_bytes = | |
| 137 | 138 | \\.globl foo |
| 138 | 139 | \\foo = 0x800008 |
| 139 | ); | |
| 140 | \\ | |
| 141 | , | |
| 142 | }); | |
| 140 | 143 | |
| 141 | const exe = addExecutable(b, "test", opts); | |
| 142 | addCSourceBytes(exe, | |
| 144 | const exe = addExecutable(b, opts, .{ | |
| 145 | .name = "test", | |
| 146 | .c_source_bytes = | |
| 143 | 147 | \\#include <signal.h> |
| 144 | 148 | \\#include <stdio.h> |
| 145 | 149 | \\#include <stdlib.h> |
| ... | ... | @@ -159,7 +163,8 @@ fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| 159 | 163 | \\ foo = 5; |
| 160 | 164 | \\ return 0; |
| 161 | 165 | \\} |
| 162 | , &.{}); | |
| 166 | , | |
| 167 | }); | |
| 163 | 168 | exe.addObject(obj); |
| 164 | 169 | exe.linkLibC(); |
| 165 | 170 | |
| ... | ... | @@ -173,31 +178,36 @@ fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| 173 | 178 | fn testAsNeeded(b: *Build, opts: Options) *Step { |
| 174 | 179 | const test_step = addTestStep(b, "as-needed", opts); |
| 175 | 180 | |
| 176 | const main_o = addObject(b, "main", opts); | |
| 177 | addCSourceBytes(main_o, | |
| 181 | const main_o = addObject(b, opts, .{ | |
| 182 | .name = "main", | |
| 183 | .c_source_bytes = | |
| 178 | 184 | \\#include <stdio.h> |
| 179 | 185 | \\int baz(); |
| 180 | 186 | \\int main() { |
| 181 | 187 | \\ printf("%d\n", baz()); |
| 182 | 188 | \\ return 0; |
| 183 | 189 | \\} |
| 184 | , &.{}); | |
| 190 | \\ | |
| 191 | , | |
| 192 | }); | |
| 185 | 193 | main_o.linkLibC(); |
| 186 | 194 | |
| 187 | const libfoo = addSharedLibrary(b, "foo", opts); | |
| 195 | const libfoo = addSharedLibrary(b, opts, .{ .name = "foo" }); | |
| 188 | 196 | addCSourceBytes(libfoo, "int foo() { return 42; }", &.{}); |
| 189 | 197 | |
| 190 | const libbar = addSharedLibrary(b, "bar", opts); | |
| 198 | const libbar = addSharedLibrary(b, opts, .{ .name = "bar" }); | |
| 191 | 199 | addCSourceBytes(libbar, "int bar() { return 42; }", &.{}); |
| 192 | 200 | |
| 193 | const libbaz = addSharedLibrary(b, "baz", opts); | |
| 201 | const libbaz = addSharedLibrary(b, opts, .{ .name = "baz" }); | |
| 194 | 202 | addCSourceBytes(libbaz, |
| 195 | 203 | \\int foo(); |
| 196 | 204 | \\int baz() { return foo(); } |
| 197 | 205 | , &.{}); |
| 198 | 206 | |
| 199 | 207 | { |
| 200 | const exe = addExecutable(b, "test", opts); | |
| 208 | const exe = addExecutable(b, opts, .{ | |
| 209 | .name = "test", | |
| 210 | }); | |
| 201 | 211 | exe.addObject(main_o); |
| 202 | 212 | exe.linkSystemLibrary2("foo", .{ .needed = true }); |
| 203 | 213 | exe.addLibraryPath(libfoo.getEmittedBinDirectory()); |
| ... | ... | @@ -225,7 +235,9 @@ fn testAsNeeded(b: *Build, opts: Options) *Step { |
| 225 | 235 | } |
| 226 | 236 | |
| 227 | 237 | { |
| 228 | const exe = addExecutable(b, "test", opts); | |
| 238 | const exe = addExecutable(b, opts, .{ | |
| 239 | .name = "test", | |
| 240 | }); | |
| 229 | 241 | exe.addObject(main_o); |
| 230 | 242 | exe.linkSystemLibrary2("foo", .{ .needed = false }); |
| 231 | 243 | exe.addLibraryPath(libfoo.getEmittedBinDirectory()); |
| ... | ... | @@ -259,7 +271,7 @@ fn testAsNeeded(b: *Build, opts: Options) *Step { |
| 259 | 271 | fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 260 | 272 | const test_step = addTestStep(b, "canonical-plt", opts); |
| 261 | 273 | |
| 262 | const dso = addSharedLibrary(b, "a", opts); | |
| 274 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 263 | 275 | addCSourceBytes(dso, |
| 264 | 276 | \\void *foo() { |
| 265 | 277 | \\ return foo; |
| ... | ... | @@ -269,17 +281,21 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 269 | 281 | \\} |
| 270 | 282 | , &.{}); |
| 271 | 283 | |
| 272 | const b_o = addObject(b, "obj", opts); | |
| 273 | addCSourceBytes(b_o, | |
| 284 | const b_o = addObject(b, opts, .{ | |
| 285 | .name = "obj", | |
| 286 | .c_source_bytes = | |
| 274 | 287 | \\void *bar(); |
| 275 | 288 | \\void *baz() { |
| 276 | 289 | \\ return bar; |
| 277 | 290 | \\} |
| 278 | , &.{}); | |
| 279 | b_o.force_pic = true; | |
| 291 | \\ | |
| 292 | , | |
| 293 | .pic = true, | |
| 294 | }); | |
| 280 | 295 | |
| 281 | const main_o = addObject(b, "main", opts); | |
| 282 | addCSourceBytes(main_o, | |
| 296 | const main_o = addObject(b, opts, .{ | |
| 297 | .name = "main", | |
| 298 | .c_source_bytes = | |
| 283 | 299 | \\#include <assert.h> |
| 284 | 300 | \\void *foo(); |
| 285 | 301 | \\void *bar(); |
| ... | ... | @@ -290,11 +306,15 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 290 | 306 | \\ assert(bar == baz()); |
| 291 | 307 | \\ return 0; |
| 292 | 308 | \\} |
| 293 | , &.{}); | |
| 309 | \\ | |
| 310 | , | |
| 311 | .pic = false, | |
| 312 | }); | |
| 294 | 313 | main_o.linkLibC(); |
| 295 | main_o.force_pic = false; | |
| 296 | 314 | |
| 297 | const exe = addExecutable(b, "main", opts); | |
| 315 | const exe = addExecutable(b, opts, .{ | |
| 316 | .name = "main", | |
| 317 | }); | |
| 298 | 318 | exe.addObject(main_o); |
| 299 | 319 | exe.addObject(b_o); |
| 300 | 320 | exe.linkLibrary(dso); |
| ... | ... | @@ -311,7 +331,9 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 311 | 331 | fn testCommonSymbols(b: *Build, opts: Options) *Step { |
| 312 | 332 | const test_step = addTestStep(b, "common-symbols", opts); |
| 313 | 333 | |
| 314 | const exe = addExecutable(b, "test", opts); | |
| 334 | const exe = addExecutable(b, opts, .{ | |
| 335 | .name = "test", | |
| 336 | }); | |
| 315 | 337 | addCSourceBytes(exe, |
| 316 | 338 | \\int foo; |
| 317 | 339 | \\int bar; |
| ... | ... | @@ -338,8 +360,9 @@ fn testCommonSymbols(b: *Build, opts: Options) *Step { |
| 338 | 360 | fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 339 | 361 | const test_step = addTestStep(b, "common-symbols-in-archive", opts); |
| 340 | 362 | |
| 341 | const a_o = addObject(b, "a", opts); | |
| 342 | addCSourceBytes(a_o, | |
| 363 | const a_o = addObject(b, opts, .{ | |
| 364 | .name = "a", | |
| 365 | .c_source_bytes = | |
| 343 | 366 | \\#include <stdio.h> |
| 344 | 367 | \\int foo; |
| 345 | 368 | \\int bar; |
| ... | ... | @@ -348,28 +371,43 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 348 | 371 | \\int main() { |
| 349 | 372 | \\ printf("%d %d %d %d\n", foo, bar, baz, two ? two() : -1); |
| 350 | 373 | \\} |
| 351 | , &.{"-fcommon"}); | |
| 374 | \\ | |
| 375 | , | |
| 376 | .c_source_flags = &.{"-fcommon"}, | |
| 377 | }); | |
| 352 | 378 | a_o.linkLibC(); |
| 353 | 379 | |
| 354 | const b_o = addObject(b, "b", opts); | |
| 355 | addCSourceBytes(b_o, "int foo = 5;", &.{"-fcommon"}); | |
| 380 | const b_o = addObject(b, opts, .{ | |
| 381 | .name = "b", | |
| 382 | .c_source_bytes = "int foo = 5;", | |
| 383 | .c_source_flags = &.{"-fcommon"}, | |
| 384 | }); | |
| 356 | 385 | |
| 357 | 386 | { |
| 358 | const c_o = addObject(b, "c", opts); | |
| 359 | addCSourceBytes(c_o, | |
| 387 | const c_o = addObject(b, opts, .{ | |
| 388 | .name = "c", | |
| 389 | .c_source_bytes = | |
| 360 | 390 | \\int bar; |
| 361 | 391 | \\int two() { return 2; } |
| 362 | , &.{"-fcommon"}); | |
| 363 | ||
| 364 | const d_o = addObject(b, "d", opts); | |
| 365 | addCSourceBytes(d_o, "int baz;", &.{"-fcommon"}); | |
| 366 | ||
| 367 | const lib = addStaticLibrary(b, "lib", opts); | |
| 392 | \\ | |
| 393 | , | |
| 394 | .c_source_flags = &.{"-fcommon"}, | |
| 395 | }); | |
| 396 | ||
| 397 | const d_o = addObject(b, opts, .{ | |
| 398 | .name = "d", | |
| 399 | .c_source_bytes = "int baz;", | |
| 400 | .c_source_flags = &.{"-fcommon"}, | |
| 401 | }); | |
| 402 | ||
| 403 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); | |
| 368 | 404 | lib.addObject(b_o); |
| 369 | 405 | lib.addObject(c_o); |
| 370 | 406 | lib.addObject(d_o); |
| 371 | 407 | |
| 372 | const exe = addExecutable(b, "test", opts); | |
| 408 | const exe = addExecutable(b, opts, .{ | |
| 409 | .name = "test", | |
| 410 | }); | |
| 373 | 411 | exe.addObject(a_o); |
| 374 | 412 | exe.linkLibrary(lib); |
| 375 | 413 | exe.linkLibC(); |
| ... | ... | @@ -380,18 +418,23 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 380 | 418 | } |
| 381 | 419 | |
| 382 | 420 | { |
| 383 | const e_o = addObject(b, "e", opts); | |
| 384 | addCSourceBytes(e_o, | |
| 421 | const e_o = addObject(b, opts, .{ | |
| 422 | .name = "e", | |
| 423 | .c_source_bytes = | |
| 385 | 424 | \\int bar = 0; |
| 386 | 425 | \\int baz = 7; |
| 387 | 426 | \\int two() { return 2; } |
| 388 | , &.{"-fcommon"}); | |
| 427 | , | |
| 428 | .c_source_flags = &.{"-fcommon"}, | |
| 429 | }); | |
| 389 | 430 | |
| 390 | const lib = addStaticLibrary(b, "lib", opts); | |
| 431 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); | |
| 391 | 432 | lib.addObject(b_o); |
| 392 | 433 | lib.addObject(e_o); |
| 393 | 434 | |
| 394 | const exe = addExecutable(b, "test", opts); | |
| 435 | const exe = addExecutable(b, opts, .{ | |
| 436 | .name = "test", | |
| 437 | }); | |
| 395 | 438 | exe.addObject(a_o); |
| 396 | 439 | exe.linkLibrary(lib); |
| 397 | 440 | exe.linkLibC(); |
| ... | ... | @@ -407,21 +450,23 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 407 | 450 | fn testCopyrel(b: *Build, opts: Options) *Step { |
| 408 | 451 | const test_step = addTestStep(b, "copyrel", opts); |
| 409 | 452 | |
| 410 | const dso = addSharedLibrary(b, "a", opts); | |
| 453 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 411 | 454 | addCSourceBytes(dso, |
| 412 | 455 | \\int foo = 3; |
| 413 | 456 | \\int bar = 5; |
| 414 | 457 | , &.{}); |
| 415 | 458 | |
| 416 | const exe = addExecutable(b, "main", opts); | |
| 417 | addCSourceBytes(exe, | |
| 459 | const exe = addExecutable(b, opts, .{ | |
| 460 | .name = "main", | |
| 461 | .c_source_bytes = | |
| 418 | 462 | \\#include<stdio.h> |
| 419 | 463 | \\extern int foo, bar; |
| 420 | 464 | \\int main() { |
| 421 | 465 | \\ printf("%d %d\n", foo, bar); |
| 422 | 466 | \\ return 0; |
| 423 | 467 | \\} |
| 424 | , &.{}); | |
| 468 | , | |
| 469 | }); | |
| 425 | 470 | exe.linkLibrary(dso); |
| 426 | 471 | exe.linkLibC(); |
| 427 | 472 | // https://github.com/ziglang/zig/issues/17619 |
| ... | ... | @@ -437,7 +482,7 @@ fn testCopyrel(b: *Build, opts: Options) *Step { |
| 437 | 482 | fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 438 | 483 | const test_step = addTestStep(b, "copyrel-alias", opts); |
| 439 | 484 | |
| 440 | const dso = addSharedLibrary(b, "a", opts); | |
| 485 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 441 | 486 | addCSourceBytes(dso, |
| 442 | 487 | \\int bruh = 31; |
| 443 | 488 | \\int foo = 42; |
| ... | ... | @@ -445,7 +490,10 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 445 | 490 | \\extern int baz __attribute__((alias("foo"))); |
| 446 | 491 | , &.{}); |
| 447 | 492 | |
| 448 | const exe = addExecutable(b, "main", opts); | |
| 493 | const exe = addExecutable(b, opts, .{ | |
| 494 | .name = "main", | |
| 495 | .pic = false, | |
| 496 | }); | |
| 449 | 497 | addCSourceBytes(exe, |
| 450 | 498 | \\#include<stdio.h> |
| 451 | 499 | \\extern int foo; |
| ... | ... | @@ -461,7 +509,6 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 461 | 509 | , &.{}); |
| 462 | 510 | exe.linkLibrary(dso); |
| 463 | 511 | exe.linkLibC(); |
| 464 | exe.force_pic = false; | |
| 465 | 512 | exe.pie = false; |
| 466 | 513 | |
| 467 | 514 | const run = addRunArtifact(exe); |
| ... | ... | @@ -474,28 +521,31 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 474 | 521 | fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 475 | 522 | const test_step = addTestStep(b, "copyrel-alignment", opts); |
| 476 | 523 | |
| 477 | const a_so = addSharedLibrary(b, "a", opts); | |
| 524 | const a_so = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 478 | 525 | addCSourceBytes(a_so, "__attribute__((aligned(32))) int foo = 5;", &.{}); |
| 479 | 526 | |
| 480 | const b_so = addSharedLibrary(b, "b", opts); | |
| 527 | const b_so = addSharedLibrary(b, opts, .{ .name = "b" }); | |
| 481 | 528 | addCSourceBytes(b_so, "__attribute__((aligned(8))) int foo = 5;", &.{}); |
| 482 | 529 | |
| 483 | const c_so = addSharedLibrary(b, "c", opts); | |
| 530 | const c_so = addSharedLibrary(b, opts, .{ .name = "c" }); | |
| 484 | 531 | addCSourceBytes(c_so, "__attribute__((aligned(256))) int foo = 5;", &.{}); |
| 485 | 532 | |
| 486 | const obj = addObject(b, "main", opts); | |
| 487 | addCSourceBytes(obj, | |
| 533 | const obj = addObject(b, opts, .{ | |
| 534 | .name = "main", | |
| 535 | .c_source_bytes = | |
| 488 | 536 | \\#include <stdio.h> |
| 489 | 537 | \\extern int foo; |
| 490 | 538 | \\int main() { printf("%d\n", foo); } |
| 491 | , &.{}); | |
| 539 | \\ | |
| 540 | , | |
| 541 | .pic = false, | |
| 542 | }); | |
| 492 | 543 | obj.linkLibC(); |
| 493 | obj.force_pic = false; | |
| 494 | 544 | |
| 495 | 545 | const exp_stdout = "5\n"; |
| 496 | 546 | |
| 497 | 547 | { |
| 498 | const exe = addExecutable(b, "main", opts); | |
| 548 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 499 | 549 | exe.addObject(obj); |
| 500 | 550 | exe.linkLibrary(a_so); |
| 501 | 551 | exe.linkLibC(); |
| ... | ... | @@ -514,7 +564,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 514 | 564 | } |
| 515 | 565 | |
| 516 | 566 | { |
| 517 | const exe = addExecutable(b, "main", opts); | |
| 567 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 518 | 568 | exe.addObject(obj); |
| 519 | 569 | exe.linkLibrary(b_so); |
| 520 | 570 | exe.linkLibC(); |
| ... | ... | @@ -533,7 +583,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 533 | 583 | } |
| 534 | 584 | |
| 535 | 585 | { |
| 536 | const exe = addExecutable(b, "main", opts); | |
| 586 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 537 | 587 | exe.addObject(obj); |
| 538 | 588 | exe.linkLibrary(c_so); |
| 539 | 589 | exe.linkLibC(); |
| ... | ... | @@ -557,7 +607,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 557 | 607 | fn testDsoPlt(b: *Build, opts: Options) *Step { |
| 558 | 608 | const test_step = addTestStep(b, "dso-plt", opts); |
| 559 | 609 | |
| 560 | const dso = addSharedLibrary(b, "dso", opts); | |
| 610 | const dso = addSharedLibrary(b, opts, .{ .name = "dso" }); | |
| 561 | 611 | addCSourceBytes(dso, |
| 562 | 612 | \\#include<stdio.h> |
| 563 | 613 | \\void world() { |
| ... | ... | @@ -573,7 +623,7 @@ fn testDsoPlt(b: *Build, opts: Options) *Step { |
| 573 | 623 | , &.{}); |
| 574 | 624 | dso.linkLibC(); |
| 575 | 625 | |
| 576 | const exe = addExecutable(b, "test", opts); | |
| 626 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 577 | 627 | addCSourceBytes(exe, |
| 578 | 628 | \\#include<stdio.h> |
| 579 | 629 | \\void world() { |
| ... | ... | @@ -599,7 +649,7 @@ fn testDsoPlt(b: *Build, opts: Options) *Step { |
| 599 | 649 | fn testDsoUndef(b: *Build, opts: Options) *Step { |
| 600 | 650 | const test_step = addTestStep(b, "dso-undef", opts); |
| 601 | 651 | |
| 602 | const dso = addSharedLibrary(b, "dso", opts); | |
| 652 | const dso = addSharedLibrary(b, opts, .{ .name = "dso" }); | |
| 603 | 653 | addCSourceBytes(dso, |
| 604 | 654 | \\extern int foo; |
| 605 | 655 | \\int bar = 5; |
| ... | ... | @@ -607,13 +657,15 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { |
| 607 | 657 | , &.{}); |
| 608 | 658 | dso.linkLibC(); |
| 609 | 659 | |
| 610 | const obj = addObject(b, "obj", opts); | |
| 611 | addCSourceBytes(obj, "int foo = 3;", &.{}); | |
| 660 | const obj = addObject(b, opts, .{ | |
| 661 | .name = "obj", | |
| 662 | .c_source_bytes = "int foo = 3;", | |
| 663 | }); | |
| 612 | 664 | |
| 613 | const lib = addStaticLibrary(b, "lib", opts); | |
| 665 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); | |
| 614 | 666 | lib.addObject(obj); |
| 615 | 667 | |
| 616 | const exe = addExecutable(b, "test", opts); | |
| 668 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 617 | 669 | exe.linkLibrary(dso); |
| 618 | 670 | exe.linkLibrary(lib); |
| 619 | 671 | addCSourceBytes(exe, |
| ... | ... | @@ -641,8 +693,9 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { |
| 641 | 693 | fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 642 | 694 | const test_step = addTestStep(b, "emit-relocatable", opts); |
| 643 | 695 | |
| 644 | const obj1 = addObject(b, "obj1", opts); | |
| 645 | addZigSourceBytes(obj1, | |
| 696 | const obj1 = addObject(b, opts, .{ | |
| 697 | .name = "obj1", | |
| 698 | .zig_source_bytes = | |
| 646 | 699 | \\const std = @import("std"); |
| 647 | 700 | \\extern var bar: i32; |
| 648 | 701 | \\export fn foo() i32 { |
| ... | ... | @@ -651,18 +704,20 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 651 | 704 | \\export fn printFoo() void { |
| 652 | 705 | \\ std.debug.print("foo={d}\n", .{foo()}); |
| 653 | 706 | \\} |
| 654 | ); | |
| 655 | addCSourceBytes(obj1, | |
| 707 | , | |
| 708 | .c_source_bytes = | |
| 656 | 709 | \\#include <stdio.h> |
| 657 | 710 | \\int bar = 42; |
| 658 | 711 | \\void printBar() { |
| 659 | 712 | \\ fprintf(stderr, "bar=%d\n", bar); |
| 660 | 713 | \\} |
| 661 | , &.{}); | |
| 714 | , | |
| 715 | }); | |
| 662 | 716 | obj1.linkLibC(); |
| 663 | 717 | |
| 664 | const exe = addExecutable(b, "test", opts); | |
| 665 | addZigSourceBytes(exe, | |
| 718 | const exe = addExecutable(b, opts, .{ | |
| 719 | .name = "test", | |
| 720 | .zig_source_bytes = | |
| 666 | 721 | \\const std = @import("std"); |
| 667 | 722 | \\extern fn printFoo() void; |
| 668 | 723 | \\extern fn printBar() void; |
| ... | ... | @@ -670,7 +725,8 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 670 | 725 | \\ printFoo(); |
| 671 | 726 | \\ printBar(); |
| 672 | 727 | \\} |
| 673 | ); | |
| 728 | , | |
| 729 | }); | |
| 674 | 730 | exe.addObject(obj1); |
| 675 | 731 | exe.linkLibC(); |
| 676 | 732 | |
| ... | ... | @@ -688,20 +744,26 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 688 | 744 | fn testEmitStaticLib(b: *Build, opts: Options) *Step { |
| 689 | 745 | const test_step = addTestStep(b, "emit-static-lib", opts); |
| 690 | 746 | |
| 691 | const obj1 = addObject(b, "obj1", opts); | |
| 692 | addCSourceBytes(obj1, | |
| 747 | const obj1 = addObject(b, opts, .{ | |
| 748 | .name = "obj1", | |
| 749 | .c_source_bytes = | |
| 693 | 750 | \\int foo = 0; |
| 694 | 751 | \\int bar = 2; |
| 695 | 752 | \\int fooBar() { |
| 696 | 753 | \\ return foo + bar; |
| 697 | 754 | \\} |
| 698 | , &.{}); | |
| 755 | , | |
| 756 | }); | |
| 699 | 757 | |
| 700 | const obj2 = addObject(b, "obj2", opts); | |
| 701 | addCSourceBytes(obj2, "int tentative;", &.{"-fcommon"}); | |
| 758 | const obj2 = addObject(b, opts, .{ | |
| 759 | .name = "obj2", | |
| 760 | .c_source_bytes = "int tentative;", | |
| 761 | .c_source_flags = &.{"-fcommon"}, | |
| 762 | }); | |
| 702 | 763 | |
| 703 | const obj3 = addObject(b, "a_very_long_file_name_so_that_it_ends_up_in_strtab", opts); | |
| 704 | addZigSourceBytes(obj3, | |
| 764 | const obj3 = addObject(b, opts, .{ | |
| 765 | .name = "a_very_long_file_name_so_that_it_ends_up_in_strtab", | |
| 766 | .zig_source_bytes = | |
| 705 | 767 | \\fn weakFoo() callconv(.C) usize { |
| 706 | 768 | \\ return 42; |
| 707 | 769 | \\} |
| ... | ... | @@ -710,9 +772,10 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step { |
| 710 | 772 | \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak }); |
| 711 | 773 | \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong }); |
| 712 | 774 | \\} |
| 713 | ); | |
| 775 | , | |
| 776 | }); | |
| 714 | 777 | |
| 715 | const lib = addStaticLibrary(b, "lib", opts); | |
| 778 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); | |
| 716 | 779 | lib.addObject(obj1); |
| 717 | 780 | lib.addObject(obj2); |
| 718 | 781 | lib.addObject(obj3); |
| ... | ... | @@ -747,30 +810,36 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step { |
| 747 | 810 | fn testEmitStaticLibZig(b: *Build, opts: Options) *Step { |
| 748 | 811 | const test_step = addTestStep(b, "emit-static-lib-zig", opts); |
| 749 | 812 | |
| 750 | const obj1 = addObject(b, "obj1", opts); | |
| 751 | addZigSourceBytes(obj1, | |
| 813 | const obj1 = addObject(b, opts, .{ | |
| 814 | .name = "obj1", | |
| 815 | .zig_source_bytes = | |
| 752 | 816 | \\export var foo: i32 = 42; |
| 753 | 817 | \\export var bar: i32 = 2; |
| 754 | ); | |
| 818 | , | |
| 819 | }); | |
| 755 | 820 | |
| 756 | const lib = addStaticLibrary(b, "lib", opts); | |
| 757 | addZigSourceBytes(lib, | |
| 821 | const lib = addStaticLibrary(b, opts, .{ | |
| 822 | .name = "lib", | |
| 823 | .zig_source_bytes = | |
| 758 | 824 | \\extern var foo: i32; |
| 759 | 825 | \\extern var bar: i32; |
| 760 | 826 | \\export fn fooBar() i32 { |
| 761 | 827 | \\ return foo + bar; |
| 762 | 828 | \\} |
| 763 | ); | |
| 829 | , | |
| 830 | }); | |
| 764 | 831 | lib.addObject(obj1); |
| 765 | 832 | |
| 766 | const exe = addExecutable(b, "test", opts); | |
| 767 | addZigSourceBytes(exe, | |
| 833 | const exe = addExecutable(b, opts, .{ | |
| 834 | .name = "test", | |
| 835 | .zig_source_bytes = | |
| 768 | 836 | \\const std = @import("std"); |
| 769 | 837 | \\extern fn fooBar() i32; |
| 770 | 838 | \\pub fn main() void { |
| 771 | 839 | \\ std.debug.print("{d}", .{fooBar()}); |
| 772 | 840 | \\} |
| 773 | ); | |
| 841 | , | |
| 842 | }); | |
| 774 | 843 | exe.linkLibrary(lib); |
| 775 | 844 | |
| 776 | 845 | const run = addRunArtifact(exe); |
| ... | ... | @@ -783,7 +852,7 @@ fn testEmitStaticLibZig(b: *Build, opts: Options) *Step { |
| 783 | 852 | fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 784 | 853 | const test_step = addTestStep(b, "empty-object", opts); |
| 785 | 854 | |
| 786 | const exe = addExecutable(b, "test", opts); | |
| 855 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 787 | 856 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 788 | 857 | addCSourceBytes(exe, "", &.{}); |
| 789 | 858 | exe.linkLibC(); |
| ... | ... | @@ -798,18 +867,23 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 798 | 867 | fn testEntryPoint(b: *Build, opts: Options) *Step { |
| 799 | 868 | const test_step = addTestStep(b, "entry-point", opts); |
| 800 | 869 | |
| 801 | const a_o = addObject(b, "a", opts); | |
| 802 | addAsmSourceBytes(a_o, | |
| 870 | const a_o = addObject(b, opts, .{ | |
| 871 | .name = "a", | |
| 872 | .asm_source_bytes = | |
| 803 | 873 | \\.globl foo, bar |
| 804 | 874 | \\foo = 0x1000 |
| 805 | 875 | \\bar = 0x2000 |
| 806 | ); | |
| 876 | \\ | |
| 877 | , | |
| 878 | }); | |
| 807 | 879 | |
| 808 | const b_o = addObject(b, "b", opts); | |
| 809 | addCSourceBytes(b_o, "int main() { return 0; }", &.{}); | |
| 880 | const b_o = addObject(b, opts, .{ | |
| 881 | .name = "b", | |
| 882 | .c_source_bytes = "int main() { return 0; }", | |
| 883 | }); | |
| 810 | 884 | |
| 811 | 885 | { |
| 812 | const exe = addExecutable(b, "main", opts); | |
| 886 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 813 | 887 | exe.addObject(a_o); |
| 814 | 888 | exe.addObject(b_o); |
| 815 | 889 | exe.entry = .{ .symbol_name = "foo" }; |
| ... | ... | @@ -825,7 +899,7 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { |
| 825 | 899 | // TODO looks like not assigning a unique name to this executable will |
| 826 | 900 | // cause an artifact collision taking the cached executable from the above |
| 827 | 901 | // step instead of generating a new one. |
| 828 | const exe = addExecutable(b, "other", opts); | |
| 902 | const exe = addExecutable(b, opts, .{ .name = "other" }); | |
| 829 | 903 | exe.addObject(a_o); |
| 830 | 904 | exe.addObject(b_o); |
| 831 | 905 | exe.entry = .{ .symbol_name = "bar" }; |
| ... | ... | @@ -843,8 +917,9 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { |
| 843 | 917 | fn testExportDynamic(b: *Build, opts: Options) *Step { |
| 844 | 918 | const test_step = addTestStep(b, "export-dynamic", opts); |
| 845 | 919 | |
| 846 | const obj = addObject(b, "obj", opts); | |
| 847 | addAsmSourceBytes(obj, | |
| 920 | const obj = addObject(b, opts, .{ | |
| 921 | .name = "obj", | |
| 922 | .asm_source_bytes = | |
| 848 | 923 | \\.text |
| 849 | 924 | \\ .globl foo |
| 850 | 925 | \\ .hidden foo |
| ... | ... | @@ -856,12 +931,14 @@ fn testExportDynamic(b: *Build, opts: Options) *Step { |
| 856 | 931 | \\ .globl _start |
| 857 | 932 | \\_start: |
| 858 | 933 | \\ nop |
| 859 | ); | |
| 934 | \\ | |
| 935 | , | |
| 936 | }); | |
| 860 | 937 | |
| 861 | const dso = addSharedLibrary(b, "a", opts); | |
| 938 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 862 | 939 | addCSourceBytes(dso, "int baz = 10;", &.{}); |
| 863 | 940 | |
| 864 | const exe = addExecutable(b, "main", opts); | |
| 941 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 865 | 942 | addCSourceBytes(exe, |
| 866 | 943 | \\extern int baz; |
| 867 | 944 | \\int callBaz() { |
| ... | ... | @@ -885,7 +962,7 @@ fn testExportDynamic(b: *Build, opts: Options) *Step { |
| 885 | 962 | fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { |
| 886 | 963 | const test_step = addTestStep(b, "export-symbols-from-exe", opts); |
| 887 | 964 | |
| 888 | const dso = addSharedLibrary(b, "a", opts); | |
| 965 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 889 | 966 | addCSourceBytes(dso, |
| 890 | 967 | \\void expfn1(); |
| 891 | 968 | \\void expfn2() {} |
| ... | ... | @@ -895,7 +972,7 @@ fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { |
| 895 | 972 | \\} |
| 896 | 973 | , &.{}); |
| 897 | 974 | |
| 898 | const exe = addExecutable(b, "main", opts); | |
| 975 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 899 | 976 | addCSourceBytes(exe, |
| 900 | 977 | \\void expfn1() {} |
| 901 | 978 | \\void expfn2() {} |
| ... | ... | @@ -923,10 +1000,10 @@ fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { |
| 923 | 1000 | fn testFuncAddress(b: *Build, opts: Options) *Step { |
| 924 | 1001 | const test_step = addTestStep(b, "func-address", opts); |
| 925 | 1002 | |
| 926 | const dso = addSharedLibrary(b, "a", opts); | |
| 1003 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 927 | 1004 | addCSourceBytes(dso, "void fn() {}", &.{}); |
| 928 | 1005 | |
| 929 | const exe = addExecutable(b, "main", opts); | |
| 1006 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 930 | 1007 | addCSourceBytes(exe, |
| 931 | 1008 | \\#include <assert.h> |
| 932 | 1009 | \\typedef void Func(); |
| ... | ... | @@ -937,7 +1014,7 @@ fn testFuncAddress(b: *Build, opts: Options) *Step { |
| 937 | 1014 | \\} |
| 938 | 1015 | , &.{}); |
| 939 | 1016 | exe.linkLibrary(dso); |
| 940 | exe.force_pic = false; | |
| 1017 | exe.root_module.pic = false; | |
| 941 | 1018 | exe.pie = false; |
| 942 | 1019 | |
| 943 | 1020 | const run = addRunArtifact(exe); |
| ... | ... | @@ -950,8 +1027,9 @@ fn testFuncAddress(b: *Build, opts: Options) *Step { |
| 950 | 1027 | fn testGcSections(b: *Build, opts: Options) *Step { |
| 951 | 1028 | const test_step = addTestStep(b, "gc-sections", opts); |
| 952 | 1029 | |
| 953 | const obj = addObject(b, "obj", opts); | |
| 954 | addCppSourceBytes(obj, | |
| 1030 | const obj = addObject(b, opts, .{ | |
| 1031 | .name = "obj", | |
| 1032 | .cpp_source_bytes = | |
| 955 | 1033 | \\#include <stdio.h> |
| 956 | 1034 | \\int two() { return 2; } |
| 957 | 1035 | \\int live_var1 = 1; |
| ... | ... | @@ -966,14 +1044,15 @@ fn testGcSections(b: *Build, opts: Options) *Step { |
| 966 | 1044 | \\ printf("%d %d\n", live_var1, live_var2); |
| 967 | 1045 | \\ live_fn2(); |
| 968 | 1046 | \\} |
| 969 | , &.{}); | |
| 1047 | , | |
| 1048 | }); | |
| 970 | 1049 | obj.link_function_sections = true; |
| 971 | 1050 | obj.link_data_sections = true; |
| 972 | 1051 | obj.linkLibC(); |
| 973 | 1052 | obj.linkLibCpp(); |
| 974 | 1053 | |
| 975 | 1054 | { |
| 976 | const exe = addExecutable(b, "test", opts); | |
| 1055 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 977 | 1056 | exe.addObject(obj); |
| 978 | 1057 | exe.link_gc_sections = false; |
| 979 | 1058 | exe.linkLibC(); |
| ... | ... | @@ -1004,7 +1083,7 @@ fn testGcSections(b: *Build, opts: Options) *Step { |
| 1004 | 1083 | } |
| 1005 | 1084 | |
| 1006 | 1085 | { |
| 1007 | const exe = addExecutable(b, "test", opts); | |
| 1086 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 1008 | 1087 | exe.addObject(obj); |
| 1009 | 1088 | exe.link_gc_sections = true; |
| 1010 | 1089 | exe.linkLibC(); |
| ... | ... | @@ -1040,11 +1119,12 @@ fn testGcSections(b: *Build, opts: Options) *Step { |
| 1040 | 1119 | fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1041 | 1120 | const test_step = addTestStep(b, "gc-sections-zig", opts); |
| 1042 | 1121 | |
| 1043 | const obj = addObject(b, "obj", .{ | |
| 1122 | const obj = addObject(b, .{ | |
| 1044 | 1123 | .target = opts.target, |
| 1045 | 1124 | .use_llvm = true, |
| 1046 | }); | |
| 1047 | addCSourceBytes(obj, | |
| 1125 | }, .{ | |
| 1126 | .name = "obj", | |
| 1127 | .c_source_bytes = | |
| 1048 | 1128 | \\int live_var1 = 1; |
| 1049 | 1129 | \\int live_var2 = 2; |
| 1050 | 1130 | \\int dead_var1 = 3; |
| ... | ... | @@ -1053,13 +1133,15 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1053 | 1133 | \\void live_fn2() { live_fn1(); } |
| 1054 | 1134 | \\void dead_fn1() {} |
| 1055 | 1135 | \\void dead_fn2() { dead_fn1(); } |
| 1056 | , &.{}); | |
| 1136 | , | |
| 1137 | }); | |
| 1057 | 1138 | obj.link_function_sections = true; |
| 1058 | 1139 | obj.link_data_sections = true; |
| 1059 | 1140 | |
| 1060 | 1141 | { |
| 1061 | const exe = addExecutable(b, "test1", opts); | |
| 1062 | addZigSourceBytes(exe, | |
| 1142 | const exe = addExecutable(b, opts, .{ | |
| 1143 | .name = "test1", | |
| 1144 | .zig_source_bytes = | |
| 1063 | 1145 | \\const std = @import("std"); |
| 1064 | 1146 | \\extern var live_var1: i32; |
| 1065 | 1147 | \\extern var live_var2: i32; |
| ... | ... | @@ -1069,7 +1151,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1069 | 1151 | \\ stdout.writer().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable; |
| 1070 | 1152 | \\ live_fn2(); |
| 1071 | 1153 | \\} |
| 1072 | ); | |
| 1154 | , | |
| 1155 | }); | |
| 1073 | 1156 | exe.addObject(obj); |
| 1074 | 1157 | exe.link_gc_sections = false; |
| 1075 | 1158 | |
| ... | ... | @@ -1098,8 +1181,9 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1098 | 1181 | } |
| 1099 | 1182 | |
| 1100 | 1183 | { |
| 1101 | const exe = addExecutable(b, "test2", opts); | |
| 1102 | addZigSourceBytes(exe, | |
| 1184 | const exe = addExecutable(b, opts, .{ | |
| 1185 | .name = "test2", | |
| 1186 | .zig_source_bytes = | |
| 1103 | 1187 | \\const std = @import("std"); |
| 1104 | 1188 | \\extern var live_var1: i32; |
| 1105 | 1189 | \\extern var live_var2: i32; |
| ... | ... | @@ -1109,7 +1193,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1109 | 1193 | \\ stdout.writer().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable; |
| 1110 | 1194 | \\ live_fn2(); |
| 1111 | 1195 | \\} |
| 1112 | ); | |
| 1196 | , | |
| 1197 | }); | |
| 1113 | 1198 | exe.addObject(obj); |
| 1114 | 1199 | exe.link_gc_sections = true; |
| 1115 | 1200 | |
| ... | ... | @@ -1143,7 +1228,7 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1143 | 1228 | fn testHiddenWeakUndef(b: *Build, opts: Options) *Step { |
| 1144 | 1229 | const test_step = addTestStep(b, "hidden-weak-undef", opts); |
| 1145 | 1230 | |
| 1146 | const dso = addSharedLibrary(b, "a", opts); | |
| 1231 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 1147 | 1232 | addCSourceBytes(dso, |
| 1148 | 1233 | \\__attribute__((weak, visibility("hidden"))) void foo(); |
| 1149 | 1234 | \\void bar() { foo(); } |
| ... | ... | @@ -1162,7 +1247,7 @@ fn testHiddenWeakUndef(b: *Build, opts: Options) *Step { |
| 1162 | 1247 | fn testIFuncAlias(b: *Build, opts: Options) *Step { |
| 1163 | 1248 | const test_step = addTestStep(b, "ifunc-alias", opts); |
| 1164 | 1249 | |
| 1165 | const exe = addExecutable(b, "main", opts); | |
| 1250 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1166 | 1251 | addCSourceBytes(exe, |
| 1167 | 1252 | \\#include <assert.h> |
| 1168 | 1253 | \\void foo() {} |
| ... | ... | @@ -1173,7 +1258,7 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step { |
| 1173 | 1258 | \\ assert(bar == bar2); |
| 1174 | 1259 | \\} |
| 1175 | 1260 | , &.{}); |
| 1176 | exe.force_pic = true; | |
| 1261 | exe.root_module.pic = true; | |
| 1177 | 1262 | exe.linkLibC(); |
| 1178 | 1263 | // https://github.com/ziglang/zig/issues/17619 |
| 1179 | 1264 | exe.pie = true; |
| ... | ... | @@ -1188,7 +1273,7 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step { |
| 1188 | 1273 | fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1189 | 1274 | const test_step = addTestStep(b, "ifunc-dlopen", opts); |
| 1190 | 1275 | |
| 1191 | const dso = addSharedLibrary(b, "a", opts); | |
| 1276 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 1192 | 1277 | addCSourceBytes(dso, |
| 1193 | 1278 | \\__attribute__((ifunc("resolve_foo"))) |
| 1194 | 1279 | \\void foo(void); |
| ... | ... | @@ -1200,7 +1285,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1200 | 1285 | \\} |
| 1201 | 1286 | , &.{}); |
| 1202 | 1287 | |
| 1203 | const exe = addExecutable(b, "main", opts); | |
| 1288 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1204 | 1289 | addCSourceBytes(exe, |
| 1205 | 1290 | \\#include <dlfcn.h> |
| 1206 | 1291 | \\#include <assert.h> |
| ... | ... | @@ -1219,7 +1304,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1219 | 1304 | exe.linkLibrary(dso); |
| 1220 | 1305 | exe.linkLibC(); |
| 1221 | 1306 | exe.linkSystemLibrary2("dl", .{}); |
| 1222 | exe.force_pic = false; | |
| 1307 | exe.root_module.pic = false; | |
| 1223 | 1308 | exe.pie = false; |
| 1224 | 1309 | |
| 1225 | 1310 | const run = addRunArtifact(exe); |
| ... | ... | @@ -1232,7 +1317,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1232 | 1317 | fn testIFuncDso(b: *Build, opts: Options) *Step { |
| 1233 | 1318 | const test_step = addTestStep(b, "ifunc-dso", opts); |
| 1234 | 1319 | |
| 1235 | const dso = addSharedLibrary(b, "a", opts); | |
| 1320 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 1236 | 1321 | addCSourceBytes(dso, |
| 1237 | 1322 | \\#include<stdio.h> |
| 1238 | 1323 | \\__attribute__((ifunc("resolve_foobar"))) |
| ... | ... | @@ -1247,7 +1332,7 @@ fn testIFuncDso(b: *Build, opts: Options) *Step { |
| 1247 | 1332 | , &.{}); |
| 1248 | 1333 | dso.linkLibC(); |
| 1249 | 1334 | |
| 1250 | const exe = addExecutable(b, "main", opts); | |
| 1335 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1251 | 1336 | addCSourceBytes(exe, |
| 1252 | 1337 | \\void foobar(void); |
| 1253 | 1338 | \\int main() { |
| ... | ... | @@ -1283,7 +1368,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { |
| 1283 | 1368 | ; |
| 1284 | 1369 | |
| 1285 | 1370 | { |
| 1286 | const exe = addExecutable(b, "main", opts); | |
| 1371 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1287 | 1372 | addCSourceBytes(exe, main_c, &.{}); |
| 1288 | 1373 | exe.linkLibC(); |
| 1289 | 1374 | exe.link_z_lazy = true; |
| ... | ... | @@ -1295,7 +1380,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { |
| 1295 | 1380 | test_step.dependOn(&run.step); |
| 1296 | 1381 | } |
| 1297 | 1382 | { |
| 1298 | const exe = addExecutable(b, "other", opts); | |
| 1383 | const exe = addExecutable(b, opts, .{ .name = "other" }); | |
| 1299 | 1384 | addCSourceBytes(exe, main_c, &.{}); |
| 1300 | 1385 | exe.linkLibC(); |
| 1301 | 1386 | // https://github.com/ziglang/zig/issues/17619 |
| ... | ... | @@ -1312,7 +1397,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { |
| 1312 | 1397 | fn testIFuncExport(b: *Build, opts: Options) *Step { |
| 1313 | 1398 | const test_step = addTestStep(b, "ifunc-export", opts); |
| 1314 | 1399 | |
| 1315 | const dso = addSharedLibrary(b, "a", opts); | |
| 1400 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 1316 | 1401 | addCSourceBytes(dso, |
| 1317 | 1402 | \\#include <stdio.h> |
| 1318 | 1403 | \\__attribute__((ifunc("resolve_foobar"))) |
| ... | ... | @@ -1338,7 +1423,7 @@ fn testIFuncExport(b: *Build, opts: Options) *Step { |
| 1338 | 1423 | fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { |
| 1339 | 1424 | const test_step = addTestStep(b, "ifunc-func-ptr", opts); |
| 1340 | 1425 | |
| 1341 | const exe = addExecutable(b, "main", opts); | |
| 1426 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1342 | 1427 | addCSourceBytes(exe, |
| 1343 | 1428 | \\typedef int Fn(); |
| 1344 | 1429 | \\int foo() __attribute__((ifunc("resolve_foo"))); |
| ... | ... | @@ -1361,7 +1446,7 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { |
| 1361 | 1446 | \\ printf("%d\n", f()); |
| 1362 | 1447 | \\} |
| 1363 | 1448 | , &.{}); |
| 1364 | exe.force_pic = true; | |
| 1449 | exe.root_module.pic = true; | |
| 1365 | 1450 | exe.linkLibC(); |
| 1366 | 1451 | // https://github.com/ziglang/zig/issues/17619 |
| 1367 | 1452 | exe.pie = true; |
| ... | ... | @@ -1376,7 +1461,7 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { |
| 1376 | 1461 | fn testIFuncNoPlt(b: *Build, opts: Options) *Step { |
| 1377 | 1462 | const test_step = addTestStep(b, "ifunc-noplt", opts); |
| 1378 | 1463 | |
| 1379 | const exe = addExecutable(b, "main", opts); | |
| 1464 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1380 | 1465 | addCSourceBytes(exe, |
| 1381 | 1466 | \\#include <stdio.h> |
| 1382 | 1467 | \\__attribute__((ifunc("resolve_foo"))) |
| ... | ... | @@ -1392,7 +1477,7 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step { |
| 1392 | 1477 | \\ foo(); |
| 1393 | 1478 | \\} |
| 1394 | 1479 | , &.{"-fno-plt"}); |
| 1395 | exe.force_pic = true; | |
| 1480 | exe.root_module.pic = true; | |
| 1396 | 1481 | exe.linkLibC(); |
| 1397 | 1482 | // https://github.com/ziglang/zig/issues/17619 |
| 1398 | 1483 | exe.pie = true; |
| ... | ... | @@ -1407,7 +1492,7 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step { |
| 1407 | 1492 | fn testIFuncStatic(b: *Build, opts: Options) *Step { |
| 1408 | 1493 | const test_step = addTestStep(b, "ifunc-static", opts); |
| 1409 | 1494 | |
| 1410 | const exe = addExecutable(b, "main", opts); | |
| 1495 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1411 | 1496 | addCSourceBytes(exe, |
| 1412 | 1497 | \\#include <stdio.h> |
| 1413 | 1498 | \\void foo() __attribute__((ifunc("resolve_foo"))); |
| ... | ... | @@ -1435,7 +1520,7 @@ fn testIFuncStatic(b: *Build, opts: Options) *Step { |
| 1435 | 1520 | fn testIFuncStaticPie(b: *Build, opts: Options) *Step { |
| 1436 | 1521 | const test_step = addTestStep(b, "ifunc-static-pie", opts); |
| 1437 | 1522 | |
| 1438 | const exe = addExecutable(b, "main", opts); | |
| 1523 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1439 | 1524 | addCSourceBytes(exe, |
| 1440 | 1525 | \\#include <stdio.h> |
| 1441 | 1526 | \\void foo() __attribute__((ifunc("resolve_foo"))); |
| ... | ... | @@ -1451,7 +1536,7 @@ fn testIFuncStaticPie(b: *Build, opts: Options) *Step { |
| 1451 | 1536 | \\} |
| 1452 | 1537 | , &.{}); |
| 1453 | 1538 | exe.linkage = .static; |
| 1454 | exe.force_pic = true; | |
| 1539 | exe.root_module.pic = true; | |
| 1455 | 1540 | exe.pie = true; |
| 1456 | 1541 | exe.linkLibC(); |
| 1457 | 1542 | |
| ... | ... | @@ -1478,7 +1563,7 @@ fn testImageBase(b: *Build, opts: Options) *Step { |
| 1478 | 1563 | const test_step = addTestStep(b, "image-base", opts); |
| 1479 | 1564 | |
| 1480 | 1565 | { |
| 1481 | const exe = addExecutable(b, "main1", opts); | |
| 1566 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 1482 | 1567 | addCSourceBytes(exe, |
| 1483 | 1568 | \\#include <stdio.h> |
| 1484 | 1569 | \\int main() { |
| ... | ... | @@ -1502,7 +1587,7 @@ fn testImageBase(b: *Build, opts: Options) *Step { |
| 1502 | 1587 | } |
| 1503 | 1588 | |
| 1504 | 1589 | { |
| 1505 | const exe = addExecutable(b, "main2", opts); | |
| 1590 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 1506 | 1591 | addCSourceBytes(exe, "void _start() {}", &.{}); |
| 1507 | 1592 | exe.image_base = 0xffffffff8000000; |
| 1508 | 1593 | |
| ... | ... | @@ -1520,22 +1605,26 @@ fn testImageBase(b: *Build, opts: Options) *Step { |
| 1520 | 1605 | fn testImportingDataDynamic(b: *Build, opts: Options) *Step { |
| 1521 | 1606 | const test_step = addTestStep(b, "importing-data-dynamic", opts); |
| 1522 | 1607 | |
| 1523 | const dso = addSharedLibrary(b, "a", .{ | |
| 1608 | const dso = addSharedLibrary(b, .{ | |
| 1524 | 1609 | .target = opts.target, |
| 1525 | 1610 | .optimize = opts.optimize, |
| 1526 | 1611 | .use_llvm = true, |
| 1612 | }, .{ | |
| 1613 | .name = "a", | |
| 1614 | .c_source_bytes = "int foo = 42;", | |
| 1527 | 1615 | }); |
| 1528 | addCSourceBytes(dso, "int foo = 42;", &.{}); | |
| 1529 | 1616 | |
| 1530 | const main = addExecutable(b, "main", opts); | |
| 1531 | addZigSourceBytes(main, | |
| 1617 | const main = addExecutable(b, opts, .{ | |
| 1618 | .name = "main", | |
| 1619 | .zig_source_bytes = | |
| 1532 | 1620 | \\extern var foo: i32; |
| 1533 | 1621 | \\pub fn main() void { |
| 1534 | 1622 | \\ @import("std").debug.print("{d}\n", .{foo}); |
| 1535 | 1623 | \\} |
| 1536 | ); | |
| 1624 | , | |
| 1625 | .strip = true, // TODO temp hack | |
| 1626 | }); | |
| 1537 | 1627 | main.pie = true; |
| 1538 | main.strip = true; // TODO temp hack | |
| 1539 | 1628 | main.linkLibrary(dso); |
| 1540 | 1629 | main.linkLibC(); |
| 1541 | 1630 | |
| ... | ... | @@ -1549,28 +1638,34 @@ fn testImportingDataDynamic(b: *Build, opts: Options) *Step { |
| 1549 | 1638 | fn testImportingDataStatic(b: *Build, opts: Options) *Step { |
| 1550 | 1639 | const test_step = addTestStep(b, "importing-data-static", opts); |
| 1551 | 1640 | |
| 1552 | const obj = addObject(b, "a", .{ | |
| 1641 | const obj = addObject(b, .{ | |
| 1553 | 1642 | .target = opts.target, |
| 1554 | 1643 | .optimize = opts.optimize, |
| 1555 | 1644 | .use_llvm = true, |
| 1645 | }, .{ | |
| 1646 | .name = "a", | |
| 1647 | .c_source_bytes = "int foo = 42;", | |
| 1556 | 1648 | }); |
| 1557 | addCSourceBytes(obj, "int foo = 42;", &.{}); | |
| 1558 | 1649 | |
| 1559 | const lib = addStaticLibrary(b, "a", .{ | |
| 1650 | const lib = addStaticLibrary(b, .{ | |
| 1560 | 1651 | .target = opts.target, |
| 1561 | 1652 | .optimize = opts.optimize, |
| 1562 | 1653 | .use_llvm = true, |
| 1654 | }, .{ | |
| 1655 | .name = "a", | |
| 1563 | 1656 | }); |
| 1564 | 1657 | lib.addObject(obj); |
| 1565 | 1658 | |
| 1566 | const main = addExecutable(b, "main", opts); | |
| 1567 | addZigSourceBytes(main, | |
| 1659 | const main = addExecutable(b, opts, .{ | |
| 1660 | .name = "main", | |
| 1661 | .zig_source_bytes = | |
| 1568 | 1662 | \\extern var foo: i32; |
| 1569 | 1663 | \\pub fn main() void { |
| 1570 | 1664 | \\ @import("std").debug.print("{d}\n", .{foo}); |
| 1571 | 1665 | \\} |
| 1572 | ); | |
| 1573 | main.strip = true; // TODO temp hack | |
| 1666 | , | |
| 1667 | .strip = true, // TODO temp hack | |
| 1668 | }); | |
| 1574 | 1669 | main.linkLibrary(lib); |
| 1575 | 1670 | main.linkLibC(); |
| 1576 | 1671 | |
| ... | ... | @@ -1584,63 +1679,76 @@ fn testImportingDataStatic(b: *Build, opts: Options) *Step { |
| 1584 | 1679 | fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1585 | 1680 | const test_step = addTestStep(b, "init-array-order", opts); |
| 1586 | 1681 | |
| 1587 | const a_o = addObject(b, "a", opts); | |
| 1588 | addCSourceBytes(a_o, | |
| 1682 | const a_o = addObject(b, opts, .{ | |
| 1683 | .name = "a", | |
| 1684 | .c_source_bytes = | |
| 1589 | 1685 | \\#include <stdio.h> |
| 1590 | 1686 | \\__attribute__((constructor(10000))) void init4() { printf("1"); } |
| 1591 | , &.{}); | |
| 1687 | , | |
| 1688 | }); | |
| 1592 | 1689 | a_o.linkLibC(); |
| 1593 | 1690 | |
| 1594 | const b_o = addObject(b, "b", opts); | |
| 1595 | addCSourceBytes(b_o, | |
| 1691 | const b_o = addObject(b, opts, .{ | |
| 1692 | .name = "b", | |
| 1693 | .c_source_bytes = | |
| 1596 | 1694 | \\#include <stdio.h> |
| 1597 | 1695 | \\__attribute__((constructor(1000))) void init3() { printf("2"); } |
| 1598 | , &.{}); | |
| 1696 | , | |
| 1697 | }); | |
| 1599 | 1698 | b_o.linkLibC(); |
| 1600 | 1699 | |
| 1601 | const c_o = addObject(b, "c", opts); | |
| 1602 | addCSourceBytes(c_o, | |
| 1700 | const c_o = addObject(b, opts, .{ | |
| 1701 | .name = "c", | |
| 1702 | .c_source_bytes = | |
| 1603 | 1703 | \\#include <stdio.h> |
| 1604 | 1704 | \\__attribute__((constructor)) void init1() { printf("3"); } |
| 1605 | , &.{}); | |
| 1705 | , | |
| 1706 | }); | |
| 1606 | 1707 | c_o.linkLibC(); |
| 1607 | 1708 | |
| 1608 | const d_o = addObject(b, "d", opts); | |
| 1609 | addCSourceBytes(d_o, | |
| 1709 | const d_o = addObject(b, opts, .{ | |
| 1710 | .name = "d", | |
| 1711 | .c_source_bytes = | |
| 1610 | 1712 | \\#include <stdio.h> |
| 1611 | 1713 | \\__attribute__((constructor)) void init2() { printf("4"); } |
| 1612 | , &.{}); | |
| 1714 | , | |
| 1715 | }); | |
| 1613 | 1716 | d_o.linkLibC(); |
| 1614 | 1717 | |
| 1615 | const e_o = addObject(b, "e", opts); | |
| 1616 | addCSourceBytes(e_o, | |
| 1718 | const e_o = addObject(b, opts, .{ | |
| 1719 | .name = "e", | |
| 1720 | .c_source_bytes = | |
| 1617 | 1721 | \\#include <stdio.h> |
| 1618 | 1722 | \\__attribute__((destructor(10000))) void fini4() { printf("5"); } |
| 1619 | , &.{}); | |
| 1723 | , | |
| 1724 | }); | |
| 1620 | 1725 | e_o.linkLibC(); |
| 1621 | 1726 | |
| 1622 | const f_o = addObject(b, "f", opts); | |
| 1623 | addCSourceBytes(f_o, | |
| 1727 | const f_o = addObject(b, opts, .{ | |
| 1728 | .name = "f", | |
| 1729 | .c_source_bytes = | |
| 1624 | 1730 | \\#include <stdio.h> |
| 1625 | 1731 | \\__attribute__((destructor(1000))) void fini3() { printf("6"); } |
| 1626 | , &.{}); | |
| 1732 | , | |
| 1733 | }); | |
| 1627 | 1734 | f_o.linkLibC(); |
| 1628 | 1735 | |
| 1629 | const g_o = addObject(b, "g", opts); | |
| 1630 | addCSourceBytes(g_o, | |
| 1736 | const g_o = addObject(b, opts, .{ | |
| 1737 | .name = "g", | |
| 1738 | .c_source_bytes = | |
| 1631 | 1739 | \\#include <stdio.h> |
| 1632 | 1740 | \\__attribute__((destructor)) void fini1() { printf("7"); } |
| 1633 | , &.{}); | |
| 1741 | , | |
| 1742 | }); | |
| 1634 | 1743 | g_o.linkLibC(); |
| 1635 | 1744 | |
| 1636 | const h_o = addObject(b, "h", opts); | |
| 1637 | addCSourceBytes(h_o, | |
| 1638 | \\#include <stdio.h> | |
| 1639 | \\__attribute__((destructor)) void fini2() { printf("8"); } | |
| 1640 | , &.{}); | |
| 1745 | const h_o = addObject(b, opts, .{ .name = "h", .c_source_bytes = | |
| 1746 | \\#include <stdio.h> | |
| 1747 | \\__attribute__((destructor)) void fini2() { printf("8"); } | |
| 1748 | }); | |
| 1641 | 1749 | h_o.linkLibC(); |
| 1642 | 1750 | |
| 1643 | const exe = addExecutable(b, "main", opts); | |
| 1751 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1644 | 1752 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 1645 | 1753 | exe.addObject(a_o); |
| 1646 | 1754 | exe.addObject(b_o); |
| ... | ... | @@ -1651,7 +1759,7 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1651 | 1759 | exe.addObject(g_o); |
| 1652 | 1760 | exe.addObject(h_o); |
| 1653 | 1761 | |
| 1654 | if (opts.target.isGnuLibC()) { | |
| 1762 | if (opts.target.target.isGnuLibC()) { | |
| 1655 | 1763 | // TODO I think we need to clarify our use of `-fPIC -fPIE` flags for different targets |
| 1656 | 1764 | exe.pie = true; |
| 1657 | 1765 | } |
| ... | ... | @@ -1666,7 +1774,7 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1666 | 1774 | fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { |
| 1667 | 1775 | const test_step = addTestStep(b, "large-alignment-dso", opts); |
| 1668 | 1776 | |
| 1669 | const dso = addSharedLibrary(b, "dso", opts); | |
| 1777 | const dso = addSharedLibrary(b, opts, .{ .name = "dso" }); | |
| 1670 | 1778 | addCSourceBytes(dso, |
| 1671 | 1779 | \\#include <stdio.h> |
| 1672 | 1780 | \\#include <stdint.h> |
| ... | ... | @@ -1695,7 +1803,7 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { |
| 1695 | 1803 | check.checkComputeCompare("addr2 16 %", .{ .op = .eq, .value = .{ .literal = 0 } }); |
| 1696 | 1804 | test_step.dependOn(&check.step); |
| 1697 | 1805 | |
| 1698 | const exe = addExecutable(b, "test", opts); | |
| 1806 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 1699 | 1807 | addCSourceBytes(exe, |
| 1700 | 1808 | \\void greet(); |
| 1701 | 1809 | \\int main() { greet(); } |
| ... | ... | @@ -1715,7 +1823,7 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { |
| 1715 | 1823 | fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { |
| 1716 | 1824 | const test_step = addTestStep(b, "large-alignment-exe", opts); |
| 1717 | 1825 | |
| 1718 | const exe = addExecutable(b, "test", opts); | |
| 1826 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 1719 | 1827 | addCSourceBytes(exe, |
| 1720 | 1828 | \\#include <stdio.h> |
| 1721 | 1829 | \\#include <stdint.h> |
| ... | ... | @@ -1760,7 +1868,7 @@ fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { |
| 1760 | 1868 | fn testLargeBss(b: *Build, opts: Options) *Step { |
| 1761 | 1869 | const test_step = addTestStep(b, "large-bss", opts); |
| 1762 | 1870 | |
| 1763 | const exe = addExecutable(b, "main", opts); | |
| 1871 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1764 | 1872 | addCSourceBytes(exe, |
| 1765 | 1873 | \\char arr[0x100000000]; |
| 1766 | 1874 | \\int main() { |
| ... | ... | @@ -1781,27 +1889,31 @@ fn testLargeBss(b: *Build, opts: Options) *Step { |
| 1781 | 1889 | fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1782 | 1890 | const test_step = addTestStep(b, "link-order", opts); |
| 1783 | 1891 | |
| 1784 | const obj = addObject(b, "obj", opts); | |
| 1785 | addCSourceBytes(obj, "void foo() {}", &.{}); | |
| 1786 | obj.force_pic = true; | |
| 1892 | const obj = addObject(b, opts, .{ | |
| 1893 | .name = "obj", | |
| 1894 | .c_source_bytes = "void foo() {}", | |
| 1895 | .pic = true, | |
| 1896 | }); | |
| 1787 | 1897 | |
| 1788 | const dso = addSharedLibrary(b, "a", opts); | |
| 1898 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 1789 | 1899 | dso.addObject(obj); |
| 1790 | 1900 | |
| 1791 | const lib = addStaticLibrary(b, "b", opts); | |
| 1901 | const lib = addStaticLibrary(b, opts, .{ .name = "b" }); | |
| 1792 | 1902 | lib.addObject(obj); |
| 1793 | 1903 | |
| 1794 | const main_o = addObject(b, "main", opts); | |
| 1795 | addCSourceBytes(main_o, | |
| 1904 | const main_o = addObject(b, opts, .{ | |
| 1905 | .name = "main", | |
| 1906 | .c_source_bytes = | |
| 1796 | 1907 | \\void foo(); |
| 1797 | 1908 | \\int main() { |
| 1798 | 1909 | \\ foo(); |
| 1799 | 1910 | \\} |
| 1800 | , &.{}); | |
| 1911 | , | |
| 1912 | }); | |
| 1801 | 1913 | |
| 1802 | 1914 | // https://github.com/ziglang/zig/issues/17450 |
| 1803 | 1915 | // { |
| 1804 | // const exe = addExecutable(b, "main1", opts); | |
| 1916 | // const exe = addExecutable(b, opts, .{ .name = "main1"}); | |
| 1805 | 1917 | // exe.addObject(main_o); |
| 1806 | 1918 | // exe.linkSystemLibrary2("a", .{}); |
| 1807 | 1919 | // exe.addLibraryPath(dso.getEmittedBinDirectory()); |
| ... | ... | @@ -1818,7 +1930,7 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1818 | 1930 | // } |
| 1819 | 1931 | |
| 1820 | 1932 | { |
| 1821 | const exe = addExecutable(b, "main2", opts); | |
| 1933 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 1822 | 1934 | exe.addObject(main_o); |
| 1823 | 1935 | exe.linkSystemLibrary2("b", .{}); |
| 1824 | 1936 | exe.addLibraryPath(lib.getEmittedBinDirectory()); |
| ... | ... | @@ -1840,14 +1952,14 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1840 | 1952 | fn testLdScript(b: *Build, opts: Options) *Step { |
| 1841 | 1953 | const test_step = addTestStep(b, "ld-script", opts); |
| 1842 | 1954 | |
| 1843 | const dso = addSharedLibrary(b, "bar", opts); | |
| 1955 | const dso = addSharedLibrary(b, opts, .{ .name = "bar" }); | |
| 1844 | 1956 | addCSourceBytes(dso, "int foo() { return 42; }", &.{}); |
| 1845 | 1957 | |
| 1846 | 1958 | const scripts = WriteFile.create(b); |
| 1847 | 1959 | _ = scripts.add("liba.so", "INPUT(libfoo.so)"); |
| 1848 | 1960 | _ = scripts.add("libfoo.so", "GROUP(AS_NEEDED(-lbar))"); |
| 1849 | 1961 | |
| 1850 | const exe = addExecutable(b, "main", opts); | |
| 1962 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1851 | 1963 | addCSourceBytes(exe, |
| 1852 | 1964 | \\int foo(); |
| 1853 | 1965 | \\int main() { |
| ... | ... | @@ -1875,7 +1987,7 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step { |
| 1875 | 1987 | const scripts = WriteFile.create(b); |
| 1876 | 1988 | _ = scripts.add("liba.so", "INPUT(libfoo.so)"); |
| 1877 | 1989 | |
| 1878 | const exe = addExecutable(b, "main", opts); | |
| 1990 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1879 | 1991 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 1880 | 1992 | exe.linkSystemLibrary2("a", .{}); |
| 1881 | 1993 | exe.addLibraryPath(scripts.getDirectory()); |
| ... | ... | @@ -1895,13 +2007,15 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step { |
| 1895 | 2007 | fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { |
| 1896 | 2008 | const test_step = addTestStep(b, "mismatched-cpu-architecture-error", opts); |
| 1897 | 2009 | |
| 1898 | const obj = addObject(b, "a", .{ | |
| 1899 | .target = .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }, | |
| 2010 | const obj = addObject(b, .{ | |
| 2011 | .target = b.resolveTargetQuery(.{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }), | |
| 2012 | }, .{ | |
| 2013 | .name = "a", | |
| 2014 | .c_source_bytes = "int foo;", | |
| 2015 | .strip = true, | |
| 1900 | 2016 | }); |
| 1901 | addCSourceBytes(obj, "int foo;", &.{}); | |
| 1902 | obj.strip = true; | |
| 1903 | 2017 | |
| 1904 | const exe = addExecutable(b, "main", opts); | |
| 2018 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 1905 | 2019 | addCSourceBytes(exe, |
| 1906 | 2020 | \\extern int foo; |
| 1907 | 2021 | \\int main() { |
| ... | ... | @@ -1922,7 +2036,7 @@ fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { |
| 1922 | 2036 | fn testLinkingC(b: *Build, opts: Options) *Step { |
| 1923 | 2037 | const test_step = addTestStep(b, "linking-c", opts); |
| 1924 | 2038 | |
| 1925 | const exe = addExecutable(b, "test", opts); | |
| 2039 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 1926 | 2040 | addCSourceBytes(exe, |
| 1927 | 2041 | \\#include <stdio.h> |
| 1928 | 2042 | \\int main() { |
| ... | ... | @@ -1951,7 +2065,7 @@ fn testLinkingC(b: *Build, opts: Options) *Step { |
| 1951 | 2065 | fn testLinkingCpp(b: *Build, opts: Options) *Step { |
| 1952 | 2066 | const test_step = addTestStep(b, "linking-cpp", opts); |
| 1953 | 2067 | |
| 1954 | const exe = addExecutable(b, "test", opts); | |
| 2068 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 1955 | 2069 | addCppSourceBytes(exe, |
| 1956 | 2070 | \\#include <iostream> |
| 1957 | 2071 | \\int main() { |
| ... | ... | @@ -1981,24 +2095,28 @@ fn testLinkingCpp(b: *Build, opts: Options) *Step { |
| 1981 | 2095 | fn testLinkingObj(b: *Build, opts: Options) *Step { |
| 1982 | 2096 | const test_step = addTestStep(b, "linking-obj", opts); |
| 1983 | 2097 | |
| 1984 | const obj = addObject(b, "aobj", opts); | |
| 1985 | addZigSourceBytes(obj, | |
| 2098 | const obj = addObject(b, opts, .{ | |
| 2099 | .name = "aobj", | |
| 2100 | .zig_source_bytes = | |
| 1986 | 2101 | \\extern var mod: usize; |
| 1987 | 2102 | \\export fn callMe() usize { |
| 1988 | 2103 | \\ return me * mod; |
| 1989 | 2104 | \\} |
| 1990 | 2105 | \\var me: usize = 42; |
| 1991 | ); | |
| 2106 | , | |
| 2107 | }); | |
| 1992 | 2108 | |
| 1993 | const exe = addExecutable(b, "testobj", opts); | |
| 1994 | addZigSourceBytes(exe, | |
| 2109 | const exe = addExecutable(b, opts, .{ | |
| 2110 | .name = "testobj", | |
| 2111 | .zig_source_bytes = | |
| 1995 | 2112 | \\const std = @import("std"); |
| 1996 | 2113 | \\extern fn callMe() usize; |
| 1997 | 2114 | \\export var mod: usize = 2; |
| 1998 | 2115 | \\pub fn main() void { |
| 1999 | 2116 | \\ std.debug.print("{d}\n", .{callMe()}); |
| 2000 | 2117 | \\} |
| 2001 | ); | |
| 2118 | , | |
| 2119 | }); | |
| 2002 | 2120 | exe.addObject(obj); |
| 2003 | 2121 | |
| 2004 | 2122 | const run = addRunArtifact(exe); |
| ... | ... | @@ -2011,26 +2129,32 @@ fn testLinkingObj(b: *Build, opts: Options) *Step { |
| 2011 | 2129 | fn testLinkingStaticLib(b: *Build, opts: Options) *Step { |
| 2012 | 2130 | const test_step = addTestStep(b, "linking-static-lib", opts); |
| 2013 | 2131 | |
| 2014 | const obj = addObject(b, "bobj", opts); | |
| 2015 | addZigSourceBytes(obj, "export var bar: i32 = -42;"); | |
| 2132 | const obj = addObject(b, opts, .{ | |
| 2133 | .name = "bobj", | |
| 2134 | .zig_source_bytes = "export var bar: i32 = -42;", | |
| 2135 | }); | |
| 2016 | 2136 | |
| 2017 | const lib = addStaticLibrary(b, "alib", opts); | |
| 2018 | addZigSourceBytes(lib, | |
| 2137 | const lib = addStaticLibrary(b, opts, .{ | |
| 2138 | .name = "alib", | |
| 2139 | .zig_source_bytes = | |
| 2019 | 2140 | \\export fn foo() i32 { |
| 2020 | 2141 | \\ return 42; |
| 2021 | 2142 | \\} |
| 2022 | ); | |
| 2143 | , | |
| 2144 | }); | |
| 2023 | 2145 | lib.addObject(obj); |
| 2024 | 2146 | |
| 2025 | const exe = addExecutable(b, "testlib", opts); | |
| 2026 | addZigSourceBytes(exe, | |
| 2147 | const exe = addExecutable(b, opts, .{ | |
| 2148 | .name = "testlib", | |
| 2149 | .zig_source_bytes = | |
| 2027 | 2150 | \\const std = @import("std"); |
| 2028 | 2151 | \\extern fn foo() i32; |
| 2029 | 2152 | \\extern var bar: i32; |
| 2030 | 2153 | \\pub fn main() void { |
| 2031 | 2154 | \\ std.debug.print("{d}\n", .{foo() + bar}); |
| 2032 | 2155 | \\} |
| 2033 | ); | |
| 2156 | , | |
| 2157 | }); | |
| 2034 | 2158 | exe.linkLibrary(lib); |
| 2035 | 2159 | |
| 2036 | 2160 | const run = addRunArtifact(exe); |
| ... | ... | @@ -2043,12 +2167,14 @@ fn testLinkingStaticLib(b: *Build, opts: Options) *Step { |
| 2043 | 2167 | fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 2044 | 2168 | const test_step = addTestStep(b, "linking-zig-static", opts); |
| 2045 | 2169 | |
| 2046 | const exe = addExecutable(b, "test", opts); | |
| 2047 | addZigSourceBytes(exe, | |
| 2170 | const exe = addExecutable(b, opts, .{ | |
| 2171 | .name = "test", | |
| 2172 | .zig_source_bytes = | |
| 2048 | 2173 | \\pub fn main() void { |
| 2049 | 2174 | \\ @import("std").debug.print("Hello World!\n", .{}); |
| 2050 | 2175 | \\} |
| 2051 | ); | |
| 2176 | , | |
| 2177 | }); | |
| 2052 | 2178 | |
| 2053 | 2179 | const run = addRunArtifact(exe); |
| 2054 | 2180 | run.expectStdErrEqual("Hello World!\n"); |
| ... | ... | @@ -2069,7 +2195,7 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 2069 | 2195 | fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { |
| 2070 | 2196 | const test_step = addTestStep(b, "no-eh-frame-hdr", opts); |
| 2071 | 2197 | |
| 2072 | const exe = addExecutable(b, "main", opts); | |
| 2198 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2073 | 2199 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 2074 | 2200 | exe.link_eh_frame_hdr = false; |
| 2075 | 2201 | exe.linkLibC(); |
| ... | ... | @@ -2086,7 +2212,7 @@ fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { |
| 2086 | 2212 | fn testPie(b: *Build, opts: Options) *Step { |
| 2087 | 2213 | const test_step = addTestStep(b, "hello-pie", opts); |
| 2088 | 2214 | |
| 2089 | const exe = addExecutable(b, "main", opts); | |
| 2215 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2090 | 2216 | addCSourceBytes(exe, |
| 2091 | 2217 | \\#include <stdio.h> |
| 2092 | 2218 | \\int main() { |
| ... | ... | @@ -2095,7 +2221,7 @@ fn testPie(b: *Build, opts: Options) *Step { |
| 2095 | 2221 | \\} |
| 2096 | 2222 | , &.{}); |
| 2097 | 2223 | exe.linkLibC(); |
| 2098 | exe.force_pic = true; | |
| 2224 | exe.root_module.pic = true; | |
| 2099 | 2225 | exe.pie = true; |
| 2100 | 2226 | |
| 2101 | 2227 | const run = addRunArtifact(exe); |
| ... | ... | @@ -2117,7 +2243,7 @@ fn testPie(b: *Build, opts: Options) *Step { |
| 2117 | 2243 | fn testPltGot(b: *Build, opts: Options) *Step { |
| 2118 | 2244 | const test_step = addTestStep(b, "plt-got", opts); |
| 2119 | 2245 | |
| 2120 | const dso = addSharedLibrary(b, "a", opts); | |
| 2246 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2121 | 2247 | addCSourceBytes(dso, |
| 2122 | 2248 | \\#include <stdio.h> |
| 2123 | 2249 | \\void ignore(void *foo) {} |
| ... | ... | @@ -2127,7 +2253,7 @@ fn testPltGot(b: *Build, opts: Options) *Step { |
| 2127 | 2253 | , &.{}); |
| 2128 | 2254 | dso.linkLibC(); |
| 2129 | 2255 | |
| 2130 | const exe = addExecutable(b, "main", opts); | |
| 2256 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2131 | 2257 | addCSourceBytes(exe, |
| 2132 | 2258 | \\void ignore(void *); |
| 2133 | 2259 | \\int hello(); |
| ... | ... | @@ -2135,7 +2261,7 @@ fn testPltGot(b: *Build, opts: Options) *Step { |
| 2135 | 2261 | \\int main() { hello(); } |
| 2136 | 2262 | , &.{}); |
| 2137 | 2263 | exe.linkLibrary(dso); |
| 2138 | exe.force_pic = true; | |
| 2264 | exe.root_module.pic = true; | |
| 2139 | 2265 | exe.linkLibC(); |
| 2140 | 2266 | // https://github.com/ziglang/zig/issues/17619 |
| 2141 | 2267 | exe.pie = true; |
| ... | ... | @@ -2151,10 +2277,12 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { |
| 2151 | 2277 | const test_step = addTestStep(b, "preinit-array", opts); |
| 2152 | 2278 | |
| 2153 | 2279 | { |
| 2154 | const obj = addObject(b, "obj", opts); | |
| 2155 | addCSourceBytes(obj, "void _start() {}", &.{}); | |
| 2280 | const obj = addObject(b, opts, .{ | |
| 2281 | .name = "obj", | |
| 2282 | .c_source_bytes = "void _start() {}", | |
| 2283 | }); | |
| 2156 | 2284 | |
| 2157 | const exe = addExecutable(b, "main1", opts); | |
| 2285 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2158 | 2286 | exe.addObject(obj); |
| 2159 | 2287 | |
| 2160 | 2288 | const check = exe.checkObject(); |
| ... | ... | @@ -2163,7 +2291,7 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { |
| 2163 | 2291 | } |
| 2164 | 2292 | |
| 2165 | 2293 | { |
| 2166 | const exe = addExecutable(b, "main2", opts); | |
| 2294 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 2167 | 2295 | addCSourceBytes(exe, |
| 2168 | 2296 | \\void preinit_fn() {} |
| 2169 | 2297 | \\int main() {} |
| ... | ... | @@ -2183,38 +2311,48 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { |
| 2183 | 2311 | fn testRelocatableArchive(b: *Build, opts: Options) *Step { |
| 2184 | 2312 | const test_step = addTestStep(b, "relocatable-archive", opts); |
| 2185 | 2313 | |
| 2186 | const obj1 = addObject(b, "obj1", opts); | |
| 2187 | addCSourceBytes(obj1, | |
| 2314 | const obj1 = addObject(b, opts, .{ | |
| 2315 | .name = "obj1", | |
| 2316 | .c_source_bytes = | |
| 2188 | 2317 | \\void bar(); |
| 2189 | 2318 | \\void foo() { |
| 2190 | 2319 | \\ bar(); |
| 2191 | 2320 | \\} |
| 2192 | , &.{}); | |
| 2321 | , | |
| 2322 | }); | |
| 2193 | 2323 | |
| 2194 | const obj2 = addObject(b, "obj2", opts); | |
| 2195 | addCSourceBytes(obj2, | |
| 2324 | const obj2 = addObject(b, opts, .{ | |
| 2325 | .name = "obj2", | |
| 2326 | .c_source_bytes = | |
| 2196 | 2327 | \\void bar() {} |
| 2197 | , &.{}); | |
| 2328 | , | |
| 2329 | }); | |
| 2198 | 2330 | |
| 2199 | const obj3 = addObject(b, "obj3", opts); | |
| 2200 | addCSourceBytes(obj3, | |
| 2331 | const obj3 = addObject(b, opts, .{ | |
| 2332 | .name = "obj3", | |
| 2333 | .c_source_bytes = | |
| 2201 | 2334 | \\void baz(); |
| 2202 | , &.{}); | |
| 2335 | , | |
| 2336 | }); | |
| 2203 | 2337 | |
| 2204 | const obj4 = addObject(b, "obj4", opts); | |
| 2205 | addCSourceBytes(obj4, | |
| 2338 | const obj4 = addObject(b, opts, .{ | |
| 2339 | .name = "obj4", | |
| 2340 | .c_source_bytes = | |
| 2206 | 2341 | \\void foo(); |
| 2207 | 2342 | \\int main() { |
| 2208 | 2343 | \\ foo(); |
| 2209 | 2344 | \\} |
| 2210 | , &.{}); | |
| 2345 | , | |
| 2346 | }); | |
| 2211 | 2347 | |
| 2212 | const lib = addStaticLibrary(b, "lib", opts); | |
| 2348 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); | |
| 2213 | 2349 | lib.addObject(obj1); |
| 2214 | 2350 | lib.addObject(obj2); |
| 2215 | 2351 | lib.addObject(obj3); |
| 2216 | 2352 | |
| 2217 | const obj5 = addObject(b, "obj5", opts); | |
| 2353 | const obj5 = addObject(b, opts, .{ | |
| 2354 | .name = "obj5", | |
| 2355 | }); | |
| 2218 | 2356 | obj5.addObject(obj4); |
| 2219 | 2357 | obj5.linkLibrary(lib); |
| 2220 | 2358 | |
| ... | ... | @@ -2234,13 +2372,15 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2234 | 2372 | const test_step = addTestStep(b, "relocatable-eh-frame", opts); |
| 2235 | 2373 | |
| 2236 | 2374 | { |
| 2237 | const obj = addObject(b, "obj1", opts); | |
| 2238 | addCppSourceBytes(obj, | |
| 2375 | const obj = addObject(b, opts, .{ | |
| 2376 | .name = "obj1", | |
| 2377 | .cpp_source_bytes = | |
| 2239 | 2378 | \\#include <stdexcept> |
| 2240 | 2379 | \\int try_me() { |
| 2241 | 2380 | \\ throw std::runtime_error("Oh no!"); |
| 2242 | 2381 | \\} |
| 2243 | , &.{}); | |
| 2382 | , | |
| 2383 | }); | |
| 2244 | 2384 | addCppSourceBytes(obj, |
| 2245 | 2385 | \\extern int try_me(); |
| 2246 | 2386 | \\int try_again() { |
| ... | ... | @@ -2249,7 +2389,7 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2249 | 2389 | , &.{}); |
| 2250 | 2390 | obj.linkLibCpp(); |
| 2251 | 2391 | |
| 2252 | const exe = addExecutable(b, "test1", opts); | |
| 2392 | const exe = addExecutable(b, opts, .{ .name = "test1" }); | |
| 2253 | 2393 | addCppSourceBytes(exe, |
| 2254 | 2394 | \\#include <iostream> |
| 2255 | 2395 | \\#include <stdexcept> |
| ... | ... | @@ -2273,13 +2413,15 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2273 | 2413 | |
| 2274 | 2414 | { |
| 2275 | 2415 | // Let's make the object file COMDAT group heavy! |
| 2276 | const obj = addObject(b, "obj2", opts); | |
| 2277 | addCppSourceBytes(obj, | |
| 2416 | const obj = addObject(b, opts, .{ | |
| 2417 | .name = "obj2", | |
| 2418 | .cpp_source_bytes = | |
| 2278 | 2419 | \\#include <stdexcept> |
| 2279 | 2420 | \\int try_me() { |
| 2280 | 2421 | \\ throw std::runtime_error("Oh no!"); |
| 2281 | 2422 | \\} |
| 2282 | , &.{}); | |
| 2423 | , | |
| 2424 | }); | |
| 2283 | 2425 | addCppSourceBytes(obj, |
| 2284 | 2426 | \\extern int try_me(); |
| 2285 | 2427 | \\int try_again() { |
| ... | ... | @@ -2301,7 +2443,7 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2301 | 2443 | , &.{}); |
| 2302 | 2444 | obj.linkLibCpp(); |
| 2303 | 2445 | |
| 2304 | const exe = addExecutable(b, "test2", opts); | |
| 2446 | const exe = addExecutable(b, opts, .{ .name = "test2" }); | |
| 2305 | 2447 | exe.addObject(obj); |
| 2306 | 2448 | exe.linkLibCpp(); |
| 2307 | 2449 | |
| ... | ... | @@ -2316,13 +2458,18 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2316 | 2458 | fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step { |
| 2317 | 2459 | const test_step = addTestStep(b, "relocatable-no-eh-frame", opts); |
| 2318 | 2460 | |
| 2319 | const obj1 = addObject(b, "obj1", opts); | |
| 2320 | addCSourceBytes(obj1, "int bar() { return 42; }", &.{ | |
| 2321 | "-fno-unwind-tables", | |
| 2322 | "-fno-asynchronous-unwind-tables", | |
| 2461 | const obj1 = addObject(b, opts, .{ | |
| 2462 | .name = "obj1", | |
| 2463 | .c_source_bytes = "int bar() { return 42; }", | |
| 2464 | .c_source_flags = &.{ | |
| 2465 | "-fno-unwind-tables", | |
| 2466 | "-fno-asynchronous-unwind-tables", | |
| 2467 | }, | |
| 2323 | 2468 | }); |
| 2324 | 2469 | |
| 2325 | const obj2 = addObject(b, "obj2", opts); | |
| 2470 | const obj2 = addObject(b, opts, .{ | |
| 2471 | .name = "obj2", | |
| 2472 | }); | |
| 2326 | 2473 | obj2.addObject(obj1); |
| 2327 | 2474 | |
| 2328 | 2475 | const check1 = obj1.checkObject(); |
| ... | ... | @@ -2343,23 +2490,25 @@ fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step { |
| 2343 | 2490 | fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { |
| 2344 | 2491 | const test_step = addTestStep(b, "shared-abs-symbol", opts); |
| 2345 | 2492 | |
| 2346 | const dso = addSharedLibrary(b, "a", opts); | |
| 2493 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2347 | 2494 | addAsmSourceBytes(dso, |
| 2348 | 2495 | \\.globl foo |
| 2349 | 2496 | \\foo = 3; |
| 2350 | 2497 | ); |
| 2351 | 2498 | |
| 2352 | const obj = addObject(b, "obj", opts); | |
| 2353 | addCSourceBytes(obj, | |
| 2499 | const obj = addObject(b, opts, .{ | |
| 2500 | .name = "obj", | |
| 2501 | .c_source_bytes = | |
| 2354 | 2502 | \\#include <stdio.h> |
| 2355 | 2503 | \\extern char foo; |
| 2356 | 2504 | \\int main() { printf("foo=%p\n", &foo); } |
| 2357 | , &.{}); | |
| 2358 | obj.force_pic = true; | |
| 2505 | , | |
| 2506 | .pic = true, | |
| 2507 | }); | |
| 2359 | 2508 | obj.linkLibC(); |
| 2360 | 2509 | |
| 2361 | 2510 | { |
| 2362 | const exe = addExecutable(b, "main1", opts); | |
| 2511 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2363 | 2512 | exe.addObject(obj); |
| 2364 | 2513 | exe.linkLibrary(dso); |
| 2365 | 2514 | exe.pie = true; |
| ... | ... | @@ -2380,7 +2529,7 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { |
| 2380 | 2529 | |
| 2381 | 2530 | // https://github.com/ziglang/zig/issues/17430 |
| 2382 | 2531 | // { |
| 2383 | // const exe = addExecutable(b, "main2", opts); | |
| 2532 | // const exe = addExecutable(b, opts, .{ .name = "main2"}); | |
| 2384 | 2533 | // exe.addObject(obj); |
| 2385 | 2534 | // exe.linkLibrary(dso); |
| 2386 | 2535 | // exe.pie = false; |
| ... | ... | @@ -2405,20 +2554,22 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { |
| 2405 | 2554 | fn testStrip(b: *Build, opts: Options) *Step { |
| 2406 | 2555 | const test_step = addTestStep(b, "strip", opts); |
| 2407 | 2556 | |
| 2408 | const obj = addObject(b, "obj", opts); | |
| 2409 | addCSourceBytes(obj, | |
| 2557 | const obj = addObject(b, opts, .{ | |
| 2558 | .name = "obj", | |
| 2559 | .c_source_bytes = | |
| 2410 | 2560 | \\#include <stdio.h> |
| 2411 | 2561 | \\int main() { |
| 2412 | 2562 | \\ printf("Hello!\n"); |
| 2413 | 2563 | \\ return 0; |
| 2414 | 2564 | \\} |
| 2415 | , &.{}); | |
| 2565 | , | |
| 2566 | }); | |
| 2416 | 2567 | obj.linkLibC(); |
| 2417 | 2568 | |
| 2418 | 2569 | { |
| 2419 | const exe = addExecutable(b, "main1", opts); | |
| 2570 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2420 | 2571 | exe.addObject(obj); |
| 2421 | exe.strip = false; | |
| 2572 | exe.root_module.strip = false; | |
| 2422 | 2573 | exe.linkLibC(); |
| 2423 | 2574 | |
| 2424 | 2575 | const check = exe.checkObject(); |
| ... | ... | @@ -2429,9 +2580,9 @@ fn testStrip(b: *Build, opts: Options) *Step { |
| 2429 | 2580 | } |
| 2430 | 2581 | |
| 2431 | 2582 | { |
| 2432 | const exe = addExecutable(b, "main2", opts); | |
| 2583 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 2433 | 2584 | exe.addObject(obj); |
| 2434 | exe.strip = true; | |
| 2585 | exe.root_module.strip = true; | |
| 2435 | 2586 | exe.linkLibC(); |
| 2436 | 2587 | |
| 2437 | 2588 | const check = exe.checkObject(); |
| ... | ... | @@ -2447,16 +2598,19 @@ fn testStrip(b: *Build, opts: Options) *Step { |
| 2447 | 2598 | fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { |
| 2448 | 2599 | const test_step = addTestStep(b, "tls-df-static-tls", opts); |
| 2449 | 2600 | |
| 2450 | const obj = addObject(b, "obj", opts); | |
| 2451 | addCSourceBytes(obj, | |
| 2601 | const obj = addObject(b, opts, .{ | |
| 2602 | .name = "obj", | |
| 2603 | .c_source_bytes = | |
| 2452 | 2604 | \\static _Thread_local int foo = 5; |
| 2453 | 2605 | \\void mutate() { ++foo; } |
| 2454 | 2606 | \\int bar() { return foo; } |
| 2455 | , &.{"-ftls-model=initial-exec"}); | |
| 2456 | obj.force_pic = true; | |
| 2607 | , | |
| 2608 | .c_source_flags = &.{"-ftls-model=initial-exec"}, | |
| 2609 | .pic = true, | |
| 2610 | }); | |
| 2457 | 2611 | |
| 2458 | 2612 | { |
| 2459 | const dso = addSharedLibrary(b, "a", opts); | |
| 2613 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2460 | 2614 | dso.addObject(obj); |
| 2461 | 2615 | // dso.link_relax = true; |
| 2462 | 2616 | |
| ... | ... | @@ -2468,7 +2622,7 @@ fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { |
| 2468 | 2622 | |
| 2469 | 2623 | // TODO add -Wl,--no-relax |
| 2470 | 2624 | // { |
| 2471 | // const dso = addSharedLibrary(b, "a", opts); | |
| 2625 | // const dso = addSharedLibrary(b, opts, .{ .name = "a"}); | |
| 2472 | 2626 | // dso.addObject(obj); |
| 2473 | 2627 | // dso.link_relax = false; |
| 2474 | 2628 | |
| ... | ... | @@ -2484,7 +2638,7 @@ fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { |
| 2484 | 2638 | fn testTlsDso(b: *Build, opts: Options) *Step { |
| 2485 | 2639 | const test_step = addTestStep(b, "tls-dso", opts); |
| 2486 | 2640 | |
| 2487 | const dso = addSharedLibrary(b, "a", opts); | |
| 2641 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2488 | 2642 | addCSourceBytes(dso, |
| 2489 | 2643 | \\extern _Thread_local int foo; |
| 2490 | 2644 | \\_Thread_local int bar; |
| ... | ... | @@ -2492,7 +2646,7 @@ fn testTlsDso(b: *Build, opts: Options) *Step { |
| 2492 | 2646 | \\int get_bar1() { return bar; } |
| 2493 | 2647 | , &.{}); |
| 2494 | 2648 | |
| 2495 | const exe = addExecutable(b, "main", opts); | |
| 2649 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2496 | 2650 | addCSourceBytes(exe, |
| 2497 | 2651 | \\#include <stdio.h> |
| 2498 | 2652 | \\_Thread_local int foo; |
| ... | ... | @@ -2526,8 +2680,9 @@ fn testTlsDso(b: *Build, opts: Options) *Step { |
| 2526 | 2680 | fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2527 | 2681 | const test_step = addTestStep(b, "tls-gd", opts); |
| 2528 | 2682 | |
| 2529 | const main_o = addObject(b, "main", opts); | |
| 2530 | addCSourceBytes(main_o, | |
| 2683 | const main_o = addObject(b, opts, .{ | |
| 2684 | .name = "main", | |
| 2685 | .c_source_bytes = | |
| 2531 | 2686 | \\#include <stdio.h> |
| 2532 | 2687 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| 2533 | 2688 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; |
| ... | ... | @@ -2540,37 +2695,42 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2540 | 2695 | \\ printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); |
| 2541 | 2696 | \\ return 0; |
| 2542 | 2697 | \\} |
| 2543 | , &.{}); | |
| 2698 | , | |
| 2699 | .pic = true, | |
| 2700 | }); | |
| 2544 | 2701 | main_o.linkLibC(); |
| 2545 | main_o.force_pic = true; | |
| 2546 | 2702 | |
| 2547 | const a_o = addObject(b, "a", opts); | |
| 2548 | addCSourceBytes(a_o, | |
| 2703 | const a_o = addObject(b, opts, .{ | |
| 2704 | .name = "a", | |
| 2705 | .c_source_bytes = | |
| 2549 | 2706 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; |
| 2550 | 2707 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; |
| 2551 | 2708 | \\int get_x5() { return x5; } |
| 2552 | , &.{}); | |
| 2553 | a_o.force_pic = true; | |
| 2709 | , | |
| 2710 | .pic = true, | |
| 2711 | }); | |
| 2554 | 2712 | |
| 2555 | const b_o = addObject(b, "b", opts); | |
| 2556 | addCSourceBytes(b_o, | |
| 2713 | const b_o = addObject(b, opts, .{ | |
| 2714 | .name = "b", | |
| 2715 | .c_source_bytes = | |
| 2557 | 2716 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; |
| 2558 | 2717 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; |
| 2559 | 2718 | \\int get_x6() { return x6; } |
| 2560 | , &.{}); | |
| 2561 | b_o.force_pic = true; | |
| 2719 | , | |
| 2720 | .pic = true, | |
| 2721 | }); | |
| 2562 | 2722 | |
| 2563 | 2723 | const exp_stdout = "1 2 3 4 5 6\n"; |
| 2564 | 2724 | |
| 2565 | const dso1 = addSharedLibrary(b, "a", opts); | |
| 2725 | const dso1 = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2566 | 2726 | dso1.addObject(a_o); |
| 2567 | 2727 | |
| 2568 | const dso2 = addSharedLibrary(b, "b", opts); | |
| 2728 | const dso2 = addSharedLibrary(b, opts, .{ .name = "b" }); | |
| 2569 | 2729 | dso2.addObject(b_o); |
| 2570 | 2730 | // dso2.link_relax = false; // TODO |
| 2571 | 2731 | |
| 2572 | 2732 | { |
| 2573 | const exe = addExecutable(b, "main1", opts); | |
| 2733 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2574 | 2734 | exe.addObject(main_o); |
| 2575 | 2735 | exe.linkLibrary(dso1); |
| 2576 | 2736 | exe.linkLibrary(dso2); |
| ... | ... | @@ -2581,7 +2741,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2581 | 2741 | } |
| 2582 | 2742 | |
| 2583 | 2743 | { |
| 2584 | const exe = addExecutable(b, "main2", opts); | |
| 2744 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 2585 | 2745 | exe.addObject(main_o); |
| 2586 | 2746 | // exe.link_relax = false; // TODO |
| 2587 | 2747 | exe.linkLibrary(dso1); |
| ... | ... | @@ -2594,7 +2754,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2594 | 2754 | |
| 2595 | 2755 | // https://github.com/ziglang/zig/issues/17430 ?? |
| 2596 | 2756 | // { |
| 2597 | // const exe = addExecutable(b, "main3", opts); | |
| 2757 | // const exe = addExecutable(b, opts, .{ .name = "main3"}); | |
| 2598 | 2758 | // exe.addObject(main_o); |
| 2599 | 2759 | // exe.linkLibrary(dso1); |
| 2600 | 2760 | // exe.linkLibrary(dso2); |
| ... | ... | @@ -2606,7 +2766,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2606 | 2766 | // } |
| 2607 | 2767 | |
| 2608 | 2768 | // { |
| 2609 | // const exe = addExecutable(b, "main4", opts); | |
| 2769 | // const exe = addExecutable(b, opts, .{ .name = "main4"}); | |
| 2610 | 2770 | // exe.addObject(main_o); |
| 2611 | 2771 | // // exe.link_relax = false; // TODO |
| 2612 | 2772 | // exe.linkLibrary(dso1); |
| ... | ... | @@ -2624,8 +2784,9 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2624 | 2784 | fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2625 | 2785 | const test_step = addTestStep(b, "tls-gd-no-plt", opts); |
| 2626 | 2786 | |
| 2627 | const obj = addObject(b, "obj", opts); | |
| 2628 | addCSourceBytes(obj, | |
| 2787 | const obj = addObject(b, opts, .{ | |
| 2788 | .name = "obj", | |
| 2789 | .c_source_bytes = | |
| 2629 | 2790 | \\#include <stdio.h> |
| 2630 | 2791 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| 2631 | 2792 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; |
| ... | ... | @@ -2639,18 +2800,20 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2639 | 2800 | \\ printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); |
| 2640 | 2801 | \\ return 0; |
| 2641 | 2802 | \\} |
| 2642 | , &.{"-fno-plt"}); | |
| 2643 | obj.force_pic = true; | |
| 2803 | , | |
| 2804 | .c_source_flags = &.{"-fno-plt"}, | |
| 2805 | .pic = true, | |
| 2806 | }); | |
| 2644 | 2807 | obj.linkLibC(); |
| 2645 | 2808 | |
| 2646 | const a_so = addSharedLibrary(b, "a", opts); | |
| 2809 | const a_so = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2647 | 2810 | addCSourceBytes(a_so, |
| 2648 | 2811 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; |
| 2649 | 2812 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; |
| 2650 | 2813 | \\int get_x5() { return x5; } |
| 2651 | 2814 | , &.{"-fno-plt"}); |
| 2652 | 2815 | |
| 2653 | const b_so = addSharedLibrary(b, "b", opts); | |
| 2816 | const b_so = addSharedLibrary(b, opts, .{ .name = "b" }); | |
| 2654 | 2817 | addCSourceBytes(b_so, |
| 2655 | 2818 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; |
| 2656 | 2819 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; |
| ... | ... | @@ -2659,7 +2822,7 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2659 | 2822 | // b_so.link_relax = false; // TODO |
| 2660 | 2823 | |
| 2661 | 2824 | { |
| 2662 | const exe = addExecutable(b, "main1", opts); | |
| 2825 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2663 | 2826 | exe.addObject(obj); |
| 2664 | 2827 | exe.linkLibrary(a_so); |
| 2665 | 2828 | exe.linkLibrary(b_so); |
| ... | ... | @@ -2673,7 +2836,7 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2673 | 2836 | } |
| 2674 | 2837 | |
| 2675 | 2838 | { |
| 2676 | const exe = addExecutable(b, "main2", opts); | |
| 2839 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 2677 | 2840 | exe.addObject(obj); |
| 2678 | 2841 | exe.linkLibrary(a_so); |
| 2679 | 2842 | exe.linkLibrary(b_so); |
| ... | ... | @@ -2693,8 +2856,9 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2693 | 2856 | fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2694 | 2857 | const test_step = addTestStep(b, "tls-gd-to-ie", opts); |
| 2695 | 2858 | |
| 2696 | const a_o = addObject(b, "a", opts); | |
| 2697 | addCSourceBytes(a_o, | |
| 2859 | const a_o = addObject(b, opts, .{ | |
| 2860 | .name = "a", | |
| 2861 | .c_source_bytes = | |
| 2698 | 2862 | \\#include <stdio.h> |
| 2699 | 2863 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| 2700 | 2864 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x2 = 2; |
| ... | ... | @@ -2705,22 +2869,25 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2705 | 2869 | \\ printf("%d %d %d\n", x1, x2, x3); |
| 2706 | 2870 | \\ return 0; |
| 2707 | 2871 | \\} |
| 2708 | , &.{}); | |
| 2872 | , | |
| 2873 | .pic = true, | |
| 2874 | }); | |
| 2709 | 2875 | a_o.linkLibC(); |
| 2710 | a_o.force_pic = true; | |
| 2711 | 2876 | |
| 2712 | const b_o = addObject(b, "b", opts); | |
| 2713 | addCSourceBytes(b_o, | |
| 2877 | const b_o = addObject(b, opts, .{ | |
| 2878 | .name = "b", | |
| 2879 | .c_source_bytes = | |
| 2714 | 2880 | \\int foo(); |
| 2715 | 2881 | \\int main() { foo(); } |
| 2716 | , &.{}); | |
| 2717 | b_o.force_pic = true; | |
| 2882 | , | |
| 2883 | .pic = true, | |
| 2884 | }); | |
| 2718 | 2885 | |
| 2719 | 2886 | { |
| 2720 | const dso = addSharedLibrary(b, "a1", opts); | |
| 2887 | const dso = addSharedLibrary(b, opts, .{ .name = "a1" }); | |
| 2721 | 2888 | dso.addObject(a_o); |
| 2722 | 2889 | |
| 2723 | const exe = addExecutable(b, "main1", opts); | |
| 2890 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2724 | 2891 | exe.addObject(b_o); |
| 2725 | 2892 | exe.linkLibrary(dso); |
| 2726 | 2893 | exe.linkLibC(); |
| ... | ... | @@ -2733,11 +2900,11 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2733 | 2900 | } |
| 2734 | 2901 | |
| 2735 | 2902 | { |
| 2736 | const dso = addSharedLibrary(b, "a2", opts); | |
| 2903 | const dso = addSharedLibrary(b, opts, .{ .name = "a2" }); | |
| 2737 | 2904 | dso.addObject(a_o); |
| 2738 | 2905 | // dso.link_relax = false; // TODO |
| 2739 | 2906 | |
| 2740 | const exe = addExecutable(b, "main2", opts); | |
| 2907 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 2741 | 2908 | exe.addObject(b_o); |
| 2742 | 2909 | exe.linkLibrary(dso); |
| 2743 | 2910 | exe.linkLibC(); |
| ... | ... | @@ -2750,11 +2917,11 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2750 | 2917 | } |
| 2751 | 2918 | |
| 2752 | 2919 | // { |
| 2753 | // const dso = addSharedLibrary(b, "a", opts); | |
| 2920 | // const dso = addSharedLibrary(b, opts, .{ .name = "a"}); | |
| 2754 | 2921 | // dso.addObject(a_o); |
| 2755 | 2922 | // dso.link_z_nodlopen = true; |
| 2756 | 2923 | |
| 2757 | // const exe = addExecutable(b, "main", opts); | |
| 2924 | // const exe = addExecutable(b, opts, .{ .name = "main"}); | |
| 2758 | 2925 | // exe.addObject(b_o); |
| 2759 | 2926 | // exe.linkLibrary(dso); |
| 2760 | 2927 | |
| ... | ... | @@ -2764,12 +2931,12 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2764 | 2931 | // } |
| 2765 | 2932 | |
| 2766 | 2933 | // { |
| 2767 | // const dso = addSharedLibrary(b, "a", opts); | |
| 2934 | // const dso = addSharedLibrary(b, opts, .{ .name = "a"}); | |
| 2768 | 2935 | // dso.addObject(a_o); |
| 2769 | 2936 | // dso.link_relax = false; |
| 2770 | 2937 | // dso.link_z_nodlopen = true; |
| 2771 | 2938 | |
| 2772 | // const exe = addExecutable(b, "main", opts); | |
| 2939 | // const exe = addExecutable(b, opts, .{ .name = "main"}); | |
| 2773 | 2940 | // exe.addObject(b_o); |
| 2774 | 2941 | // exe.linkLibrary(dso); |
| 2775 | 2942 | |
| ... | ... | @@ -2784,7 +2951,7 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2784 | 2951 | fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2785 | 2952 | const test_step = addTestStep(b, "tls-ie", opts); |
| 2786 | 2953 | |
| 2787 | const dso = addSharedLibrary(b, "a", opts); | |
| 2954 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2788 | 2955 | addCSourceBytes(dso, |
| 2789 | 2956 | \\#include <stdio.h> |
| 2790 | 2957 | \\__attribute__((tls_model("initial-exec"))) static _Thread_local int foo; |
| ... | ... | @@ -2799,8 +2966,9 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2799 | 2966 | , &.{}); |
| 2800 | 2967 | dso.linkLibC(); |
| 2801 | 2968 | |
| 2802 | const main_o = addObject(b, "main", opts); | |
| 2803 | addCSourceBytes(main_o, | |
| 2969 | const main_o = addObject(b, opts, .{ | |
| 2970 | .name = "main", | |
| 2971 | .c_source_bytes = | |
| 2804 | 2972 | \\#include <stdio.h> |
| 2805 | 2973 | \\_Thread_local int baz; |
| 2806 | 2974 | \\void set(); |
| ... | ... | @@ -2812,13 +2980,14 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2812 | 2980 | \\ print(); |
| 2813 | 2981 | \\ printf("%d\n", baz); |
| 2814 | 2982 | \\} |
| 2815 | , &.{}); | |
| 2983 | , | |
| 2984 | }); | |
| 2816 | 2985 | main_o.linkLibC(); |
| 2817 | 2986 | |
| 2818 | 2987 | const exp_stdout = "0 0 3 5 7\n"; |
| 2819 | 2988 | |
| 2820 | 2989 | { |
| 2821 | const exe = addExecutable(b, "main1", opts); | |
| 2990 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2822 | 2991 | exe.addObject(main_o); |
| 2823 | 2992 | exe.linkLibrary(dso); |
| 2824 | 2993 | exe.linkLibC(); |
| ... | ... | @@ -2831,7 +3000,7 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2831 | 3000 | } |
| 2832 | 3001 | |
| 2833 | 3002 | { |
| 2834 | const exe = addExecutable(b, "main2", opts); | |
| 3003 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 2835 | 3004 | exe.addObject(main_o); |
| 2836 | 3005 | exe.linkLibrary(dso); |
| 2837 | 3006 | exe.linkLibC(); |
| ... | ... | @@ -2850,38 +3019,46 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2850 | 3019 | fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { |
| 2851 | 3020 | const test_step = addTestStep(b, "tls-large-alignment", opts); |
| 2852 | 3021 | |
| 2853 | const a_o = addObject(b, "a", opts); | |
| 2854 | addCSourceBytes(a_o, | |
| 3022 | const a_o = addObject(b, opts, .{ | |
| 3023 | .name = "a", | |
| 3024 | .c_source_bytes = | |
| 2855 | 3025 | \\__attribute__((section(".tdata1"))) |
| 2856 | 3026 | \\_Thread_local int x = 42; |
| 2857 | , &.{"-std=c11"}); | |
| 2858 | a_o.force_pic = true; | |
| 3027 | , | |
| 3028 | .c_source_flags = &.{"-std=c11"}, | |
| 3029 | .pic = true, | |
| 3030 | }); | |
| 2859 | 3031 | |
| 2860 | const b_o = addObject(b, "b", opts); | |
| 2861 | addCSourceBytes(b_o, | |
| 3032 | const b_o = addObject(b, opts, .{ | |
| 3033 | .name = "b", | |
| 3034 | .c_source_bytes = | |
| 2862 | 3035 | \\__attribute__((section(".tdata2"))) |
| 2863 | 3036 | \\_Alignas(256) _Thread_local int y[] = { 1, 2, 3 }; |
| 2864 | , &.{"-std=c11"}); | |
| 2865 | b_o.force_pic = true; | |
| 3037 | , | |
| 3038 | .c_source_flags = &.{"-std=c11"}, | |
| 3039 | .pic = true, | |
| 3040 | }); | |
| 2866 | 3041 | |
| 2867 | const c_o = addObject(b, "c", opts); | |
| 2868 | addCSourceBytes(c_o, | |
| 3042 | const c_o = addObject(b, opts, .{ | |
| 3043 | .name = "c", | |
| 3044 | .c_source_bytes = | |
| 2869 | 3045 | \\#include <stdio.h> |
| 2870 | 3046 | \\extern _Thread_local int x; |
| 2871 | 3047 | \\extern _Thread_local int y[]; |
| 2872 | 3048 | \\int main() { |
| 2873 | 3049 | \\ printf("%d %d %d %d\n", x, y[0], y[1], y[2]); |
| 2874 | 3050 | \\} |
| 2875 | , &.{}); | |
| 2876 | c_o.force_pic = true; | |
| 3051 | , | |
| 3052 | .pic = true, | |
| 3053 | }); | |
| 2877 | 3054 | c_o.linkLibC(); |
| 2878 | 3055 | |
| 2879 | 3056 | { |
| 2880 | const dso = addSharedLibrary(b, "a", opts); | |
| 3057 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 2881 | 3058 | dso.addObject(a_o); |
| 2882 | 3059 | dso.addObject(b_o); |
| 2883 | 3060 | |
| 2884 | const exe = addExecutable(b, "main", opts); | |
| 3061 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2885 | 3062 | exe.addObject(c_o); |
| 2886 | 3063 | exe.linkLibrary(dso); |
| 2887 | 3064 | exe.linkLibC(); |
| ... | ... | @@ -2894,7 +3071,7 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { |
| 2894 | 3071 | } |
| 2895 | 3072 | |
| 2896 | 3073 | { |
| 2897 | const exe = addExecutable(b, "main", opts); | |
| 3074 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2898 | 3075 | exe.addObject(a_o); |
| 2899 | 3076 | exe.addObject(b_o); |
| 2900 | 3077 | exe.addObject(c_o); |
| ... | ... | @@ -2913,7 +3090,7 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { |
| 2913 | 3090 | fn testTlsLargeTbss(b: *Build, opts: Options) *Step { |
| 2914 | 3091 | const test_step = addTestStep(b, "tls-large-tbss", opts); |
| 2915 | 3092 | |
| 2916 | const exe = addExecutable(b, "main", opts); | |
| 3093 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2917 | 3094 | addAsmSourceBytes(exe, |
| 2918 | 3095 | \\.globl x, y |
| 2919 | 3096 | \\.section .tbss,"awT",@nobits |
| ... | ... | @@ -2947,7 +3124,7 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step { |
| 2947 | 3124 | fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { |
| 2948 | 3125 | const test_step = addTestStep(b, "tls-large-static-image", opts); |
| 2949 | 3126 | |
| 2950 | const exe = addExecutable(b, "main", opts); | |
| 3127 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 2951 | 3128 | addCSourceBytes(exe, "_Thread_local int x[] = { 1, 2, 3, [10000] = 5 };", &.{}); |
| 2952 | 3129 | addCSourceBytes(exe, |
| 2953 | 3130 | \\#include <stdio.h> |
| ... | ... | @@ -2956,7 +3133,7 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { |
| 2956 | 3133 | \\ printf("%d %d %d %d %d\n", x[0], x[1], x[2], x[3], x[10000]); |
| 2957 | 3134 | \\} |
| 2958 | 3135 | , &.{}); |
| 2959 | exe.force_pic = true; | |
| 3136 | exe.root_module.pic = true; | |
| 2960 | 3137 | exe.linkLibC(); |
| 2961 | 3138 | // https://github.com/ziglang/zig/issues/17619 |
| 2962 | 3139 | exe.pie = true; |
| ... | ... | @@ -2971,8 +3148,9 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { |
| 2971 | 3148 | fn testTlsLd(b: *Build, opts: Options) *Step { |
| 2972 | 3149 | const test_step = addTestStep(b, "tls-ld", opts); |
| 2973 | 3150 | |
| 2974 | const main_o = addObject(b, "main", opts); | |
| 2975 | addCSourceBytes(main_o, | |
| 3151 | const main_o = addObject(b, opts, .{ | |
| 3152 | .name = "main", | |
| 3153 | .c_source_bytes = | |
| 2976 | 3154 | \\#include <stdio.h> |
| 2977 | 3155 | \\extern _Thread_local int foo; |
| 2978 | 3156 | \\static _Thread_local int bar; |
| ... | ... | @@ -2983,18 +3161,23 @@ fn testTlsLd(b: *Build, opts: Options) *Step { |
| 2983 | 3161 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); |
| 2984 | 3162 | \\ return 0; |
| 2985 | 3163 | \\} |
| 2986 | , &.{"-ftls-model=local-dynamic"}); | |
| 2987 | main_o.force_pic = true; | |
| 3164 | , | |
| 3165 | .c_source_flags = &.{"-ftls-model=local-dynamic"}, | |
| 3166 | .pic = true, | |
| 3167 | }); | |
| 2988 | 3168 | main_o.linkLibC(); |
| 2989 | 3169 | |
| 2990 | const a_o = addObject(b, "a", opts); | |
| 2991 | addCSourceBytes(a_o, "_Thread_local int foo = 3;", &.{"-ftls-model=local-dynamic"}); | |
| 2992 | a_o.force_pic = true; | |
| 3170 | const a_o = addObject(b, opts, .{ | |
| 3171 | .name = "a", | |
| 3172 | .c_source_bytes = "_Thread_local int foo = 3;", | |
| 3173 | .c_source_flags = &.{"-ftls-model=local-dynamic"}, | |
| 3174 | .pic = true, | |
| 3175 | }); | |
| 2993 | 3176 | |
| 2994 | 3177 | const exp_stdout = "3 5 3 5\n"; |
| 2995 | 3178 | |
| 2996 | 3179 | { |
| 2997 | const exe = addExecutable(b, "main1", opts); | |
| 3180 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 2998 | 3181 | exe.addObject(main_o); |
| 2999 | 3182 | exe.addObject(a_o); |
| 3000 | 3183 | exe.linkLibC(); |
| ... | ... | @@ -3007,7 +3190,7 @@ fn testTlsLd(b: *Build, opts: Options) *Step { |
| 3007 | 3190 | } |
| 3008 | 3191 | |
| 3009 | 3192 | { |
| 3010 | const exe = addExecutable(b, "main2", opts); | |
| 3193 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 3011 | 3194 | exe.addObject(main_o); |
| 3012 | 3195 | exe.addObject(a_o); |
| 3013 | 3196 | exe.linkLibC(); |
| ... | ... | @@ -3026,14 +3209,14 @@ fn testTlsLd(b: *Build, opts: Options) *Step { |
| 3026 | 3209 | fn testTlsLdDso(b: *Build, opts: Options) *Step { |
| 3027 | 3210 | const test_step = addTestStep(b, "tls-ld-dso", opts); |
| 3028 | 3211 | |
| 3029 | const dso = addSharedLibrary(b, "a", opts); | |
| 3212 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3030 | 3213 | addCSourceBytes(dso, |
| 3031 | 3214 | \\static _Thread_local int def, def1; |
| 3032 | 3215 | \\int f0() { return ++def; } |
| 3033 | 3216 | \\int f1() { return ++def1 + def; } |
| 3034 | 3217 | , &.{"-ftls-model=local-dynamic"}); |
| 3035 | 3218 | |
| 3036 | const exe = addExecutable(b, "main", opts); | |
| 3219 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3037 | 3220 | addCSourceBytes(exe, |
| 3038 | 3221 | \\#include <stdio.h> |
| 3039 | 3222 | \\extern int f0(); |
| ... | ... | @@ -3060,8 +3243,9 @@ fn testTlsLdDso(b: *Build, opts: Options) *Step { |
| 3060 | 3243 | fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3061 | 3244 | const test_step = addTestStep(b, "tls-ld-no-plt", opts); |
| 3062 | 3245 | |
| 3063 | const a_o = addObject(b, "a", opts); | |
| 3064 | addCSourceBytes(a_o, | |
| 3246 | const a_o = addObject(b, opts, .{ | |
| 3247 | .name = "a", | |
| 3248 | .c_source_bytes = | |
| 3065 | 3249 | \\#include <stdio.h> |
| 3066 | 3250 | \\extern _Thread_local int foo; |
| 3067 | 3251 | \\static _Thread_local int bar; |
| ... | ... | @@ -3073,16 +3257,21 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3073 | 3257 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); |
| 3074 | 3258 | \\ return 0; |
| 3075 | 3259 | \\} |
| 3076 | , &.{ "-ftls-model=local-dynamic", "-fno-plt" }); | |
| 3260 | , | |
| 3261 | .c_source_flags = &.{ "-ftls-model=local-dynamic", "-fno-plt" }, | |
| 3262 | .pic = true, | |
| 3263 | }); | |
| 3077 | 3264 | a_o.linkLibC(); |
| 3078 | a_o.force_pic = true; | |
| 3079 | 3265 | |
| 3080 | const b_o = addObject(b, "b", opts); | |
| 3081 | addCSourceBytes(b_o, "_Thread_local int foo = 3;", &.{ "-ftls-model=local-dynamic", "-fno-plt" }); | |
| 3082 | b_o.force_pic = true; | |
| 3266 | const b_o = addObject(b, opts, .{ | |
| 3267 | .name = "b", | |
| 3268 | .c_source_bytes = "_Thread_local int foo = 3;", | |
| 3269 | .c_source_flags = &.{ "-ftls-model=local-dynamic", "-fno-plt" }, | |
| 3270 | .pic = true, | |
| 3271 | }); | |
| 3083 | 3272 | |
| 3084 | 3273 | { |
| 3085 | const exe = addExecutable(b, "main1", opts); | |
| 3274 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | |
| 3086 | 3275 | exe.addObject(a_o); |
| 3087 | 3276 | exe.addObject(b_o); |
| 3088 | 3277 | exe.linkLibC(); |
| ... | ... | @@ -3095,7 +3284,7 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3095 | 3284 | } |
| 3096 | 3285 | |
| 3097 | 3286 | { |
| 3098 | const exe = addExecutable(b, "main2", opts); | |
| 3287 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | |
| 3099 | 3288 | exe.addObject(a_o); |
| 3100 | 3289 | exe.addObject(b_o); |
| 3101 | 3290 | exe.linkLibC(); |
| ... | ... | @@ -3114,7 +3303,7 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3114 | 3303 | fn testTlsNoPic(b: *Build, opts: Options) *Step { |
| 3115 | 3304 | const test_step = addTestStep(b, "tls-no-pic", opts); |
| 3116 | 3305 | |
| 3117 | const exe = addExecutable(b, "main", opts); | |
| 3306 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3118 | 3307 | addCSourceBytes(exe, |
| 3119 | 3308 | \\#include <stdio.h> |
| 3120 | 3309 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int foo; |
| ... | ... | @@ -3132,7 +3321,7 @@ fn testTlsNoPic(b: *Build, opts: Options) *Step { |
| 3132 | 3321 | addCSourceBytes(exe, |
| 3133 | 3322 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int foo; |
| 3134 | 3323 | , &.{}); |
| 3135 | exe.force_pic = false; | |
| 3324 | exe.root_module.pic = false; | |
| 3136 | 3325 | exe.linkLibC(); |
| 3137 | 3326 | |
| 3138 | 3327 | const run = addRunArtifact(exe); |
| ... | ... | @@ -3145,7 +3334,7 @@ fn testTlsNoPic(b: *Build, opts: Options) *Step { |
| 3145 | 3334 | fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3146 | 3335 | const test_step = addTestStep(b, "tls-offset-alignment", opts); |
| 3147 | 3336 | |
| 3148 | const dso = addSharedLibrary(b, "a", opts); | |
| 3337 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3149 | 3338 | addCSourceBytes(dso, |
| 3150 | 3339 | \\#include <assert.h> |
| 3151 | 3340 | \\#include <stdlib.h> |
| ... | ... | @@ -3163,7 +3352,7 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3163 | 3352 | , &.{}); |
| 3164 | 3353 | dso.linkLibC(); |
| 3165 | 3354 | |
| 3166 | const exe = addExecutable(b, "main", opts); | |
| 3355 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3167 | 3356 | addCSourceBytes(exe, |
| 3168 | 3357 | \\#include <pthread.h> |
| 3169 | 3358 | \\#include <dlfcn.h> |
| ... | ... | @@ -3186,7 +3375,7 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3186 | 3375 | , &.{}); |
| 3187 | 3376 | exe.addRPath(dso.getEmittedBinDirectory()); |
| 3188 | 3377 | exe.linkLibC(); |
| 3189 | exe.force_pic = true; | |
| 3378 | exe.root_module.pic = true; | |
| 3190 | 3379 | // https://github.com/ziglang/zig/issues/17619 |
| 3191 | 3380 | exe.pie = true; |
| 3192 | 3381 | |
| ... | ... | @@ -3200,8 +3389,9 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3200 | 3389 | fn testTlsPic(b: *Build, opts: Options) *Step { |
| 3201 | 3390 | const test_step = addTestStep(b, "tls-pic", opts); |
| 3202 | 3391 | |
| 3203 | const obj = addObject(b, "obj", opts); | |
| 3204 | addCSourceBytes(obj, | |
| 3392 | const obj = addObject(b, opts, .{ | |
| 3393 | .name = "obj", | |
| 3394 | .c_source_bytes = | |
| 3205 | 3395 | \\#include <stdio.h> |
| 3206 | 3396 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int foo; |
| 3207 | 3397 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int bar; |
| ... | ... | @@ -3213,11 +3403,12 @@ fn testTlsPic(b: *Build, opts: Options) *Step { |
| 3213 | 3403 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); |
| 3214 | 3404 | \\ return 0; |
| 3215 | 3405 | \\} |
| 3216 | , &.{}); | |
| 3406 | , | |
| 3407 | .pic = true, | |
| 3408 | }); | |
| 3217 | 3409 | obj.linkLibC(); |
| 3218 | obj.force_pic = true; | |
| 3219 | 3410 | |
| 3220 | const exe = addExecutable(b, "main", opts); | |
| 3411 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3221 | 3412 | addCSourceBytes(exe, |
| 3222 | 3413 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int foo = 3; |
| 3223 | 3414 | , &.{}); |
| ... | ... | @@ -3236,30 +3427,38 @@ fn testTlsPic(b: *Build, opts: Options) *Step { |
| 3236 | 3427 | fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { |
| 3237 | 3428 | const test_step = addTestStep(b, "tls-small-alignment", opts); |
| 3238 | 3429 | |
| 3239 | const a_o = addObject(b, "a", opts); | |
| 3240 | addAsmSourceBytes(a_o, | |
| 3430 | const a_o = addObject(b, opts, .{ | |
| 3431 | .name = "a", | |
| 3432 | .asm_source_bytes = | |
| 3241 | 3433 | \\.text |
| 3242 | 3434 | \\.byte 0 |
| 3243 | ); | |
| 3244 | a_o.force_pic = true; | |
| 3435 | \\ | |
| 3436 | , | |
| 3437 | .pic = true, | |
| 3438 | }); | |
| 3245 | 3439 | |
| 3246 | const b_o = addObject(b, "b", opts); | |
| 3247 | addCSourceBytes(b_o, "_Thread_local char x = 42;", &.{"-std=c11"}); | |
| 3248 | b_o.force_pic = true; | |
| 3440 | const b_o = addObject(b, opts, .{ | |
| 3441 | .name = "b", | |
| 3442 | .c_source_bytes = "_Thread_local char x = 42;", | |
| 3443 | .c_source_flags = &.{"-std=c11"}, | |
| 3444 | .pic = true, | |
| 3445 | }); | |
| 3249 | 3446 | |
| 3250 | const c_o = addObject(b, "c", opts); | |
| 3251 | addCSourceBytes(c_o, | |
| 3447 | const c_o = addObject(b, opts, .{ | |
| 3448 | .name = "c", | |
| 3449 | .c_source_bytes = | |
| 3252 | 3450 | \\#include <stdio.h> |
| 3253 | 3451 | \\extern _Thread_local char x; |
| 3254 | 3452 | \\int main() { |
| 3255 | 3453 | \\ printf("%d\n", x); |
| 3256 | 3454 | \\} |
| 3257 | , &.{}); | |
| 3455 | , | |
| 3456 | .pic = true, | |
| 3457 | }); | |
| 3258 | 3458 | c_o.linkLibC(); |
| 3259 | c_o.force_pic = true; | |
| 3260 | 3459 | |
| 3261 | 3460 | { |
| 3262 | const exe = addExecutable(b, "main", opts); | |
| 3461 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3263 | 3462 | exe.addObject(a_o); |
| 3264 | 3463 | exe.addObject(b_o); |
| 3265 | 3464 | exe.addObject(c_o); |
| ... | ... | @@ -3273,11 +3472,11 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { |
| 3273 | 3472 | } |
| 3274 | 3473 | |
| 3275 | 3474 | { |
| 3276 | const dso = addSharedLibrary(b, "a", opts); | |
| 3475 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3277 | 3476 | dso.addObject(a_o); |
| 3278 | 3477 | dso.addObject(b_o); |
| 3279 | 3478 | |
| 3280 | const exe = addExecutable(b, "main", opts); | |
| 3479 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3281 | 3480 | exe.addObject(c_o); |
| 3282 | 3481 | exe.linkLibrary(dso); |
| 3283 | 3482 | exe.linkLibC(); |
| ... | ... | @@ -3295,7 +3494,7 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { |
| 3295 | 3494 | fn testTlsStatic(b: *Build, opts: Options) *Step { |
| 3296 | 3495 | const test_step = addTestStep(b, "tls-static", opts); |
| 3297 | 3496 | |
| 3298 | const exe = addExecutable(b, "test", opts); | |
| 3497 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 3299 | 3498 | addCSourceBytes(exe, |
| 3300 | 3499 | \\#include <stdio.h> |
| 3301 | 3500 | \\_Thread_local int a = 10; |
| ... | ... | @@ -3326,12 +3525,14 @@ fn testTlsStatic(b: *Build, opts: Options) *Step { |
| 3326 | 3525 | fn testUnknownFileTypeError(b: *Build, opts: Options) *Step { |
| 3327 | 3526 | const test_step = addTestStep(b, "unknown-file-type-error", opts); |
| 3328 | 3527 | |
| 3329 | const dylib = addSharedLibrary(b, "a", .{ | |
| 3330 | .target = .{ .cpu_arch = .x86_64, .os_tag = .macos }, | |
| 3528 | const dylib = addSharedLibrary(b, .{ | |
| 3529 | .target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .macos }), | |
| 3530 | }, .{ | |
| 3531 | .name = "a", | |
| 3532 | .zig_source_bytes = "export var foo: i32 = 0;", | |
| 3331 | 3533 | }); |
| 3332 | addZigSourceBytes(dylib, "export var foo: i32 = 0;"); | |
| 3333 | 3534 | |
| 3334 | const exe = addExecutable(b, "main", opts); | |
| 3535 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3335 | 3536 | addCSourceBytes(exe, |
| 3336 | 3537 | \\extern int foo; |
| 3337 | 3538 | \\int main() { |
| ... | ... | @@ -3354,28 +3555,34 @@ fn testUnknownFileTypeError(b: *Build, opts: Options) *Step { |
| 3354 | 3555 | fn testUnresolvedError(b: *Build, opts: Options) *Step { |
| 3355 | 3556 | const test_step = addTestStep(b, "unresolved-error", opts); |
| 3356 | 3557 | |
| 3357 | const obj1 = addObject(b, "a", opts); | |
| 3358 | addCSourceBytes(obj1, | |
| 3558 | const obj1 = addObject(b, opts, .{ | |
| 3559 | .name = "a", | |
| 3560 | .c_source_bytes = | |
| 3359 | 3561 | \\#include <stdio.h> |
| 3360 | 3562 | \\int foo(); |
| 3361 | 3563 | \\int bar() { |
| 3362 | 3564 | \\ return foo() + 1; |
| 3363 | 3565 | \\} |
| 3364 | , &.{"-ffunction-sections"}); | |
| 3566 | , | |
| 3567 | .c_source_flags = &.{"-ffunction-sections"}, | |
| 3568 | }); | |
| 3365 | 3569 | obj1.linkLibC(); |
| 3366 | 3570 | |
| 3367 | const obj2 = addObject(b, "b", opts); | |
| 3368 | addCSourceBytes(obj2, | |
| 3571 | const obj2 = addObject(b, opts, .{ | |
| 3572 | .name = "b", | |
| 3573 | .c_source_bytes = | |
| 3369 | 3574 | \\#include <stdio.h> |
| 3370 | 3575 | \\int foo(); |
| 3371 | 3576 | \\int bar(); |
| 3372 | 3577 | \\int main() { |
| 3373 | 3578 | \\ return foo() + bar(); |
| 3374 | 3579 | \\} |
| 3375 | , &.{"-ffunction-sections"}); | |
| 3580 | , | |
| 3581 | .c_source_flags = &.{"-ffunction-sections"}, | |
| 3582 | }); | |
| 3376 | 3583 | obj2.linkLibC(); |
| 3377 | 3584 | |
| 3378 | const exe = addExecutable(b, "main", opts); | |
| 3585 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3379 | 3586 | exe.addObject(obj1); |
| 3380 | 3587 | exe.addObject(obj2); |
| 3381 | 3588 | exe.linkLibC(); |
| ... | ... | @@ -3392,19 +3599,21 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step { |
| 3392 | 3599 | fn testWeakExports(b: *Build, opts: Options) *Step { |
| 3393 | 3600 | const test_step = addTestStep(b, "weak-exports", opts); |
| 3394 | 3601 | |
| 3395 | const obj = addObject(b, "obj", opts); | |
| 3396 | addCSourceBytes(obj, | |
| 3602 | const obj = addObject(b, opts, .{ | |
| 3603 | .name = "obj", | |
| 3604 | .c_source_bytes = | |
| 3397 | 3605 | \\#include <stdio.h> |
| 3398 | 3606 | \\__attribute__((weak)) int foo(); |
| 3399 | 3607 | \\int main() { |
| 3400 | 3608 | \\ printf("%d\n", foo ? foo() : 3); |
| 3401 | 3609 | \\} |
| 3402 | , &.{}); | |
| 3610 | , | |
| 3611 | .pic = true, | |
| 3612 | }); | |
| 3403 | 3613 | obj.linkLibC(); |
| 3404 | obj.force_pic = true; | |
| 3405 | 3614 | |
| 3406 | 3615 | { |
| 3407 | const dso = addSharedLibrary(b, "a", opts); | |
| 3616 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3408 | 3617 | dso.addObject(obj); |
| 3409 | 3618 | dso.linkLibC(); |
| 3410 | 3619 | |
| ... | ... | @@ -3415,7 +3624,7 @@ fn testWeakExports(b: *Build, opts: Options) *Step { |
| 3415 | 3624 | } |
| 3416 | 3625 | |
| 3417 | 3626 | { |
| 3418 | const exe = addExecutable(b, "main", opts); | |
| 3627 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3419 | 3628 | exe.addObject(obj); |
| 3420 | 3629 | exe.linkLibC(); |
| 3421 | 3630 | // https://github.com/ziglang/zig/issues/17619 |
| ... | ... | @@ -3437,14 +3646,14 @@ fn testWeakExports(b: *Build, opts: Options) *Step { |
| 3437 | 3646 | fn testWeakUndefsDso(b: *Build, opts: Options) *Step { |
| 3438 | 3647 | const test_step = addTestStep(b, "weak-undef-dso", opts); |
| 3439 | 3648 | |
| 3440 | const dso = addSharedLibrary(b, "a", opts); | |
| 3649 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3441 | 3650 | addCSourceBytes(dso, |
| 3442 | 3651 | \\__attribute__((weak)) int foo(); |
| 3443 | 3652 | \\int bar() { return foo ? foo() : -1; } |
| 3444 | 3653 | , &.{}); |
| 3445 | 3654 | |
| 3446 | 3655 | { |
| 3447 | const exe = addExecutable(b, "main", opts); | |
| 3656 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3448 | 3657 | addCSourceBytes(exe, |
| 3449 | 3658 | \\#include <stdio.h> |
| 3450 | 3659 | \\int bar(); |
| ... | ... | @@ -3461,7 +3670,7 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step { |
| 3461 | 3670 | } |
| 3462 | 3671 | |
| 3463 | 3672 | { |
| 3464 | const exe = addExecutable(b, "main", opts); | |
| 3673 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3465 | 3674 | addCSourceBytes(exe, |
| 3466 | 3675 | \\#include <stdio.h> |
| 3467 | 3676 | \\int foo() { return 5; } |
| ... | ... | @@ -3484,12 +3693,14 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step { |
| 3484 | 3693 | fn testZNow(b: *Build, opts: Options) *Step { |
| 3485 | 3694 | const test_step = addTestStep(b, "z-now", opts); |
| 3486 | 3695 | |
| 3487 | const obj = addObject(b, "obj", opts); | |
| 3488 | addCSourceBytes(obj, "int main() { return 0; }", &.{}); | |
| 3489 | obj.force_pic = true; | |
| 3696 | const obj = addObject(b, opts, .{ | |
| 3697 | .name = "obj", | |
| 3698 | .c_source_bytes = "int main() { return 0; }", | |
| 3699 | .pic = true, | |
| 3700 | }); | |
| 3490 | 3701 | |
| 3491 | 3702 | { |
| 3492 | const dso = addSharedLibrary(b, "a", opts); | |
| 3703 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3493 | 3704 | dso.addObject(obj); |
| 3494 | 3705 | |
| 3495 | 3706 | const check = dso.checkObject(); |
| ... | ... | @@ -3499,7 +3710,7 @@ fn testZNow(b: *Build, opts: Options) *Step { |
| 3499 | 3710 | } |
| 3500 | 3711 | |
| 3501 | 3712 | { |
| 3502 | const dso = addSharedLibrary(b, "a", opts); | |
| 3713 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3503 | 3714 | dso.addObject(obj); |
| 3504 | 3715 | dso.link_z_lazy = true; |
| 3505 | 3716 | |
| ... | ... | @@ -3515,7 +3726,7 @@ fn testZNow(b: *Build, opts: Options) *Step { |
| 3515 | 3726 | fn testZStackSize(b: *Build, opts: Options) *Step { |
| 3516 | 3727 | const test_step = addTestStep(b, "z-stack-size", opts); |
| 3517 | 3728 | |
| 3518 | const exe = addExecutable(b, "main", opts); | |
| 3729 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3519 | 3730 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 3520 | 3731 | exe.stack_size = 0x800000; |
| 3521 | 3732 | exe.linkLibC(); |
| ... | ... | @@ -3540,8 +3751,9 @@ fn testZText(b: *Build, opts: Options) *Step { |
| 3540 | 3751 | // musl supports only a very limited number of text relocations and only in DSOs (and |
| 3541 | 3752 | // rightly so!). |
| 3542 | 3753 | |
| 3543 | const a_o = addObject(b, "a", opts); | |
| 3544 | addAsmSourceBytes(a_o, | |
| 3754 | const a_o = addObject(b, opts, .{ | |
| 3755 | .name = "a", | |
| 3756 | .asm_source_bytes = | |
| 3545 | 3757 | \\.globl fn1 |
| 3546 | 3758 | \\fn1: |
| 3547 | 3759 | \\ sub $8, %rsp |
| ... | ... | @@ -3549,10 +3761,13 @@ fn testZText(b: *Build, opts: Options) *Step { |
| 3549 | 3761 | \\ call *%rax |
| 3550 | 3762 | \\ add $8, %rsp |
| 3551 | 3763 | \\ ret |
| 3552 | ); | |
| 3764 | \\ | |
| 3765 | , | |
| 3766 | }); | |
| 3553 | 3767 | |
| 3554 | const b_o = addObject(b, "b", opts); | |
| 3555 | addCSourceBytes(b_o, | |
| 3768 | const b_o = addObject(b, opts, .{ | |
| 3769 | .name = "b", | |
| 3770 | .c_source_bytes = | |
| 3556 | 3771 | \\int fn1(); |
| 3557 | 3772 | \\int fn2() { |
| 3558 | 3773 | \\ return 3; |
| ... | ... | @@ -3561,15 +3776,16 @@ fn testZText(b: *Build, opts: Options) *Step { |
| 3561 | 3776 | \\int fnn() { |
| 3562 | 3777 | \\ return fn1(); |
| 3563 | 3778 | \\} |
| 3564 | , &.{}); | |
| 3565 | b_o.force_pic = true; | |
| 3779 | , | |
| 3780 | .pic = true, | |
| 3781 | }); | |
| 3566 | 3782 | |
| 3567 | const dso = addSharedLibrary(b, "a", opts); | |
| 3783 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); | |
| 3568 | 3784 | dso.addObject(a_o); |
| 3569 | 3785 | dso.addObject(b_o); |
| 3570 | 3786 | dso.link_z_notext = true; |
| 3571 | 3787 | |
| 3572 | const exe = addExecutable(b, "main", opts); | |
| 3788 | const exe = addExecutable(b, opts, .{ .name = "main" }); | |
| 3573 | 3789 | addCSourceBytes(exe, |
| 3574 | 3790 | \\#include <stdio.h> |
| 3575 | 3791 | \\int fnn(); |
| ... | ... | @@ -3608,7 +3824,6 @@ const addObject = link.addObject; |
| 3608 | 3824 | const addRunArtifact = link.addRunArtifact; |
| 3609 | 3825 | const addSharedLibrary = link.addSharedLibrary; |
| 3610 | 3826 | const addStaticLibrary = link.addStaticLibrary; |
| 3611 | const addZigSourceBytes = link.addZigSourceBytes; | |
| 3612 | 3827 | const expectLinkErrors = link.expectLinkErrors; |
| 3613 | 3828 | const link = @import("link.zig"); |
| 3614 | 3829 | const std = @import("std"); |
test/link/glibc_compat/build.zig+2-2| ... | ... | @@ -8,9 +8,9 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | const exe = b.addExecutable(.{ |
| 9 | 9 | .name = t, |
| 10 | 10 | .root_source_file = .{ .path = "main.c" }, |
| 11 | .target = std.zig.CrossTarget.parse( | |
| 11 | .target = b.resolveTargetQuery(std.zig.CrossTarget.parse( | |
| 12 | 12 | .{ .arch_os_abi = t }, |
| 13 | ) catch unreachable, | |
| 13 | ) catch unreachable), | |
| 14 | 14 | }); |
| 15 | 15 | exe.linkLibC(); |
| 16 | 16 | // TODO: actually test the output |
test/link/interdependent_static_c_libs/build.zig+2-2| ... | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | 16 | .optimize = optimize, |
| 17 | .target = .{}, | |
| 17 | .target = b.host, | |
| 18 | 18 | }); |
| 19 | 19 | lib_a.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &[_][]const u8{} }); |
| 20 | 20 | lib_a.addIncludePath(.{ .path = "." }); |
| ... | ... | @@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 22 | 22 | const lib_b = b.addStaticLibrary(.{ |
| 23 | 23 | .name = "b", |
| 24 | 24 | .optimize = optimize, |
| 25 | .target = .{}, | |
| 25 | .target = b.host, | |
| 26 | 26 | }); |
| 27 | 27 | lib_b.addCSourceFile(.{ .file = .{ .path = "b.c" }, .flags = &[_][]const u8{} }); |
| 28 | 28 | lib_b.addIncludePath(.{ .path = "." }); |
test/link/link.zig+133-42| ... | ... | @@ -7,62 +7,160 @@ pub fn build(b: *Build) void { |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | pub const Options = struct { |
| 10 | target: CrossTarget, | |
| 10 | target: std.Build.ResolvedTarget, | |
| 11 | 11 | optimize: std.builtin.OptimizeMode = .Debug, |
| 12 | 12 | use_llvm: bool = true, |
| 13 | 13 | use_lld: bool = false, |
| 14 | 14 | }; |
| 15 | 15 | |
| 16 | pub fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step { | |
| 17 | const target = opts.target.zigTriple(b.allocator) catch @panic("OOM"); | |
| 16 | pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step { | |
| 17 | const target = opts.target.target.zigTriple(b.allocator) catch @panic("OOM"); | |
| 18 | 18 | const optimize = @tagName(opts.optimize); |
| 19 | 19 | const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm"; |
| 20 | const name = std.fmt.allocPrint(b.allocator, "test-" ++ prefix ++ "-{s}-{s}-{s}", .{ | |
| 21 | target, | |
| 22 | optimize, | |
| 23 | use_llvm, | |
| 20 | const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}", .{ | |
| 21 | prefix, target, optimize, use_llvm, | |
| 24 | 22 | }) catch @panic("OOM"); |
| 25 | 23 | return b.step(name, ""); |
| 26 | 24 | } |
| 27 | 25 | |
| 28 | pub fn addExecutable(b: *Build, name: []const u8, opts: Options) *Compile { | |
| 29 | return b.addExecutable(.{ | |
| 30 | .name = name, | |
| 31 | .target = opts.target, | |
| 32 | .optimize = opts.optimize, | |
| 33 | .use_llvm = opts.use_llvm, | |
| 34 | .use_lld = opts.use_lld, | |
| 26 | const OverlayOptions = struct { | |
| 27 | name: []const u8, | |
| 28 | asm_source_bytes: ?[]const u8 = null, | |
| 29 | c_source_bytes: ?[]const u8 = null, | |
| 30 | c_source_flags: []const []const u8 = &.{}, | |
| 31 | cpp_source_bytes: ?[]const u8 = null, | |
| 32 | cpp_source_flags: []const []const u8 = &.{}, | |
| 33 | zig_source_bytes: ?[]const u8 = null, | |
| 34 | pic: ?bool = null, | |
| 35 | strip: ?bool = null, | |
| 36 | }; | |
| 37 | ||
| 38 | pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Step.Compile { | |
| 39 | const compile_step = b.addExecutable(.{ | |
| 40 | .name = overlay.name, | |
| 41 | .root_source_file = rsf: { | |
| 42 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | |
| 43 | break :rsf b.addWriteFiles().add("a.zig", bytes); | |
| 44 | }, | |
| 45 | .target = base.target, | |
| 46 | .optimize = base.optimize, | |
| 47 | .use_llvm = base.use_llvm, | |
| 48 | .use_lld = base.use_lld, | |
| 49 | .pic = overlay.pic, | |
| 50 | .strip = overlay.strip, | |
| 35 | 51 | }); |
| 52 | if (overlay.cpp_source_bytes) |bytes| { | |
| 53 | compile_step.addCSourceFile(.{ | |
| 54 | .file = b.addWriteFiles().add("a.cpp", bytes), | |
| 55 | .flags = overlay.cpp_source_flags, | |
| 56 | }); | |
| 57 | } | |
| 58 | if (overlay.c_source_bytes) |bytes| { | |
| 59 | compile_step.addCSourceFile(.{ | |
| 60 | .file = b.addWriteFiles().add("a.c", bytes), | |
| 61 | .flags = overlay.c_source_flags, | |
| 62 | }); | |
| 63 | } | |
| 64 | if (overlay.asm_source_bytes) |bytes| { | |
| 65 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | |
| 66 | } | |
| 67 | return compile_step; | |
| 36 | 68 | } |
| 37 | 69 | |
| 38 | pub fn addObject(b: *Build, name: []const u8, opts: Options) *Compile { | |
| 39 | return b.addObject(.{ | |
| 40 | .name = name, | |
| 41 | .target = opts.target, | |
| 42 | .optimize = opts.optimize, | |
| 43 | .use_llvm = opts.use_llvm, | |
| 44 | .use_lld = opts.use_lld, | |
| 70 | pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Step.Compile { | |
| 71 | const compile_step = b.addObject(.{ | |
| 72 | .name = overlay.name, | |
| 73 | .root_source_file = rsf: { | |
| 74 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | |
| 75 | break :rsf b.addWriteFiles().add("a.zig", bytes); | |
| 76 | }, | |
| 77 | .target = base.target, | |
| 78 | .optimize = base.optimize, | |
| 79 | .use_llvm = base.use_llvm, | |
| 80 | .use_lld = base.use_lld, | |
| 81 | .pic = overlay.pic, | |
| 82 | .strip = overlay.strip, | |
| 45 | 83 | }); |
| 84 | if (overlay.cpp_source_bytes) |bytes| { | |
| 85 | compile_step.addCSourceFile(.{ | |
| 86 | .file = b.addWriteFiles().add("a.cpp", bytes), | |
| 87 | .flags = overlay.cpp_source_flags, | |
| 88 | }); | |
| 89 | } | |
| 90 | if (overlay.c_source_bytes) |bytes| { | |
| 91 | compile_step.addCSourceFile(.{ | |
| 92 | .file = b.addWriteFiles().add("a.c", bytes), | |
| 93 | .flags = overlay.c_source_flags, | |
| 94 | }); | |
| 95 | } | |
| 96 | if (overlay.asm_source_bytes) |bytes| { | |
| 97 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | |
| 98 | } | |
| 99 | return compile_step; | |
| 46 | 100 | } |
| 47 | 101 | |
| 48 | pub fn addStaticLibrary(b: *Build, name: []const u8, opts: Options) *Compile { | |
| 49 | return b.addStaticLibrary(.{ | |
| 50 | .name = name, | |
| 51 | .target = opts.target, | |
| 52 | .optimize = opts.optimize, | |
| 53 | .use_llvm = opts.use_llvm, | |
| 54 | .use_lld = opts.use_lld, | |
| 102 | pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { | |
| 103 | const compile_step = b.addStaticLibrary(.{ | |
| 104 | .name = overlay.name, | |
| 105 | .root_source_file = rsf: { | |
| 106 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | |
| 107 | break :rsf b.addWriteFiles().add("a.zig", bytes); | |
| 108 | }, | |
| 109 | .target = base.target, | |
| 110 | .optimize = base.optimize, | |
| 111 | .use_llvm = base.use_llvm, | |
| 112 | .use_lld = base.use_lld, | |
| 113 | .pic = overlay.pic, | |
| 114 | .strip = overlay.strip, | |
| 55 | 115 | }); |
| 116 | if (overlay.cpp_source_bytes) |bytes| { | |
| 117 | compile_step.addCSourceFile(.{ | |
| 118 | .file = b.addWriteFiles().add("a.cpp", bytes), | |
| 119 | .flags = overlay.cpp_source_flags, | |
| 120 | }); | |
| 121 | } | |
| 122 | if (overlay.c_source_bytes) |bytes| { | |
| 123 | compile_step.addCSourceFile(.{ | |
| 124 | .file = b.addWriteFiles().add("a.c", bytes), | |
| 125 | .flags = overlay.c_source_flags, | |
| 126 | }); | |
| 127 | } | |
| 128 | if (overlay.asm_source_bytes) |bytes| { | |
| 129 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | |
| 130 | } | |
| 131 | return compile_step; | |
| 56 | 132 | } |
| 57 | 133 | |
| 58 | pub fn addSharedLibrary(b: *Build, name: []const u8, opts: Options) *Compile { | |
| 59 | return b.addSharedLibrary(.{ | |
| 60 | .name = name, | |
| 61 | .target = opts.target, | |
| 62 | .optimize = opts.optimize, | |
| 63 | .use_llvm = opts.use_llvm, | |
| 64 | .use_lld = opts.use_lld, | |
| 134 | pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { | |
| 135 | const compile_step = b.addSharedLibrary(.{ | |
| 136 | .name = overlay.name, | |
| 137 | .root_source_file = rsf: { | |
| 138 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | |
| 139 | break :rsf b.addWriteFiles().add("a.zig", bytes); | |
| 140 | }, | |
| 141 | .target = base.target, | |
| 142 | .optimize = base.optimize, | |
| 143 | .use_llvm = base.use_llvm, | |
| 144 | .use_lld = base.use_lld, | |
| 145 | .pic = overlay.pic, | |
| 146 | .strip = overlay.strip, | |
| 65 | 147 | }); |
| 148 | if (overlay.cpp_source_bytes) |bytes| { | |
| 149 | compile_step.addCSourceFile(.{ | |
| 150 | .file = b.addWriteFiles().add("a.cpp", bytes), | |
| 151 | .flags = overlay.cpp_source_flags, | |
| 152 | }); | |
| 153 | } | |
| 154 | if (overlay.c_source_bytes) |bytes| { | |
| 155 | compile_step.addCSourceFile(.{ | |
| 156 | .file = b.addWriteFiles().add("a.c", bytes), | |
| 157 | .flags = overlay.c_source_flags, | |
| 158 | }); | |
| 159 | } | |
| 160 | if (overlay.asm_source_bytes) |bytes| { | |
| 161 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | |
| 162 | } | |
| 163 | return compile_step; | |
| 66 | 164 | } |
| 67 | 165 | |
| 68 | 166 | pub fn addRunArtifact(comp: *Compile) *Run { |
| ... | ... | @@ -72,13 +170,6 @@ pub fn addRunArtifact(comp: *Compile) *Run { |
| 72 | 170 | return run; |
| 73 | 171 | } |
| 74 | 172 | |
| 75 | pub fn addZigSourceBytes(comp: *Compile, bytes: []const u8) void { | |
| 76 | const b = comp.step.owner; | |
| 77 | const file = WriteFile.create(b).add("a.zig", bytes); | |
| 78 | file.addStepDependencies(&comp.step); | |
| 79 | comp.root_src = file; | |
| 80 | } | |
| 81 | ||
| 82 | 173 | pub fn addCSourceBytes(comp: *Compile, bytes: []const u8, flags: []const []const u8) void { |
| 83 | 174 | const b = comp.step.owner; |
| 84 | 175 | const file = WriteFile.create(b).add("a.c", bytes); |
test/link/macho.zig+32-27| ... | ... | @@ -1,26 +1,29 @@ |
| 1 | 1 | //! Here we test our MachO linker for correctness and functionality. |
| 2 | 2 | //! TODO migrate standalone tests from test/link/macho/* to here. |
| 3 | 3 | |
| 4 | pub fn testAll(b: *Build) *Step { | |
| 4 | pub fn testAll(b: *std.Build) *Step { | |
| 5 | 5 | const macho_step = b.step("test-macho", "Run MachO tests"); |
| 6 | 6 | |
| 7 | const default_target = CrossTarget{ .os_tag = .macos }; | |
| 8 | ||
| 9 | macho_step.dependOn(testResolvingBoundarySymbols(b, .{ .target = default_target })); | |
| 7 | macho_step.dependOn(testResolvingBoundarySymbols(b, .{ | |
| 8 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 9 | })); | |
| 10 | 10 | |
| 11 | 11 | return macho_step; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { | |
| 14 | fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step { | |
| 15 | 15 | const test_step = addTestStep(b, "macho-resolving-boundary-symbols", opts); |
| 16 | 16 | |
| 17 | const obj1 = addObject(b, "obj1", opts); | |
| 18 | addCppSourceBytes(obj1, | |
| 17 | const obj1 = addObject(b, opts, .{ | |
| 18 | .name = "obj1", | |
| 19 | .cpp_source_bytes = | |
| 19 | 20 | \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST,__message_ptr"))) = "codebase"; |
| 20 | , &.{}); | |
| 21 | , | |
| 22 | }); | |
| 21 | 23 | |
| 22 | const main_o = addObject(b, "main", opts); | |
| 23 | addZigSourceBytes(main_o, | |
| 24 | const main_o = addObject(b, opts, .{ | |
| 25 | .name = "main", | |
| 26 | .zig_source_bytes = | |
| 24 | 27 | \\const std = @import("std"); |
| 25 | 28 | \\extern fn interop() [*:0]const u8; |
| 26 | 29 | \\pub fn main() !void { |
| ... | ... | @@ -28,23 +31,27 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { |
| 28 | 31 | \\ std.mem.span(interop()), |
| 29 | 32 | \\ }); |
| 30 | 33 | \\} |
| 31 | ); | |
| 34 | , | |
| 35 | }); | |
| 32 | 36 | |
| 33 | 37 | { |
| 34 | const obj2 = addObject(b, "obj2", opts); | |
| 35 | addCppSourceBytes(obj2, | |
| 38 | const obj2 = addObject(b, opts, .{ | |
| 39 | .name = "obj2", | |
| 40 | .cpp_source_bytes = | |
| 36 | 41 | \\extern const char* message_pointer __asm("section$start$__DATA_CONST$__message_ptr"); |
| 37 | 42 | \\extern "C" const char* interop() { |
| 38 | 43 | \\ return message_pointer; |
| 39 | 44 | \\} |
| 40 | , &.{}); | |
| 45 | , | |
| 46 | }); | |
| 41 | 47 | |
| 42 | const exe = addExecutable(b, "test", opts); | |
| 48 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 43 | 49 | exe.addObject(obj1); |
| 44 | 50 | exe.addObject(obj2); |
| 45 | 51 | exe.addObject(main_o); |
| 46 | 52 | |
| 47 | const run = addRunArtifact(exe); | |
| 53 | const run = b.addRunArtifact(exe); | |
| 54 | run.skip_foreign_checks = true; | |
| 48 | 55 | run.expectStdErrEqual("All your codebase are belong to us.\n"); |
| 49 | 56 | test_step.dependOn(&run.step); |
| 50 | 57 | |
| ... | ... | @@ -55,15 +62,17 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { |
| 55 | 62 | } |
| 56 | 63 | |
| 57 | 64 | { |
| 58 | const obj3 = addObject(b, "obj3", opts); | |
| 59 | addCppSourceBytes(obj3, | |
| 65 | const obj3 = addObject(b, opts, .{ | |
| 66 | .name = "obj3", | |
| 67 | .cpp_source_bytes = | |
| 60 | 68 | \\extern const char* message_pointer __asm("section$start$__DATA$__message_ptr"); |
| 61 | 69 | \\extern "C" const char* interop() { |
| 62 | 70 | \\ return message_pointer; |
| 63 | 71 | \\} |
| 64 | , &.{}); | |
| 72 | , | |
| 73 | }); | |
| 65 | 74 | |
| 66 | const exe = addExecutable(b, "test", opts); | |
| 75 | const exe = addExecutable(b, opts, .{ .name = "test" }); | |
| 67 | 76 | exe.addObject(obj1); |
| 68 | 77 | exe.addObject(obj3); |
| 69 | 78 | exe.addObject(main_o); |
| ... | ... | @@ -77,20 +86,16 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { |
| 77 | 86 | return test_step; |
| 78 | 87 | } |
| 79 | 88 | |
| 80 | fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step { | |
| 89 | fn addTestStep(b: *std.Build, comptime prefix: []const u8, opts: Options) *Step { | |
| 81 | 90 | return link.addTestStep(b, "macho-" ++ prefix, opts); |
| 82 | 91 | } |
| 83 | 92 | |
| 84 | const addCppSourceBytes = link.addCppSourceBytes; | |
| 85 | const addExecutable = link.addExecutable; | |
| 86 | 93 | const addObject = link.addObject; |
| 87 | const addRunArtifact = link.addRunArtifact; | |
| 88 | const addZigSourceBytes = link.addZigSourceBytes; | |
| 94 | const addExecutable = link.addExecutable; | |
| 89 | 95 | const expectLinkErrors = link.expectLinkErrors; |
| 90 | 96 | const link = @import("link.zig"); |
| 91 | 97 | const std = @import("std"); |
| 92 | 98 | |
| 93 | const Build = std.Build; | |
| 94 | 99 | const CrossTarget = std.zig.CrossTarget; |
| 95 | 100 | const Options = link.Options; |
| 96 | const Step = Build.Step; | |
| 101 | const Step = std.Build.Step; |
test/link/macho/bugs/13056/build.zig+3-3| ... | ... | @@ -14,14 +14,14 @@ pub fn build(b: *std.Build) void { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 18 | const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable; | |
| 19 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target_info.target) orelse | |
| 17 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 18 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.target) orelse | |
| 20 | 19 | @panic("macOS SDK is required to run the test"); |
| 21 | 20 | |
| 22 | 21 | const exe = b.addExecutable(.{ |
| 23 | 22 | .name = "test", |
| 24 | 23 | .optimize = optimize, |
| 24 | .target = b.host, | |
| 25 | 25 | }); |
| 26 | 26 | exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) }); |
| 27 | 27 | exe.addIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }) }); |
test/link/macho/bugs/13457/build.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const exe = b.addExecutable(.{ |
| 19 | 19 | .name = "test", |
test/link/macho/bugs/16308/build.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | const test_step = b.step("test", "Test it"); |
| 7 | 7 | b.default_step = test_step; |
| 8 | 8 | |
| 9 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 9 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 10 | 10 | |
| 11 | 11 | const lib = b.addSharedLibrary(.{ |
| 12 | 12 | .name = "a", |
test/link/macho/bugs/16628/build.zig+1-1| ... | ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 18 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 18 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 19 | 19 | |
| 20 | 20 | const exe = b.addExecutable(.{ |
| 21 | 21 | .name = "test", |
test/link/macho/dead_strip/build.zig+2-2| ... | ... | @@ -4,7 +4,7 @@ pub const requires_symlinks = true; |
| 4 | 4 | |
| 5 | 5 | pub fn build(b: *std.Build) void { |
| 6 | 6 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 7 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 8 | 8 | |
| 9 | 9 | const test_step = b.step("test", "Test the program"); |
| 10 | 10 | b.default_step = test_step; |
| ... | ... | @@ -44,7 +44,7 @@ pub fn build(b: *std.Build) void { |
| 44 | 44 | fn createScenario( |
| 45 | 45 | b: *std.Build, |
| 46 | 46 | optimize: std.builtin.OptimizeMode, |
| 47 | target: std.zig.CrossTarget, | |
| 47 | target: std.Build.ResolvedTarget, | |
| 48 | 48 | name: []const u8, |
| 49 | 49 | ) *std.Build.Step.Compile { |
| 50 | 50 | const exe = b.addExecutable(.{ |
test/link/macho/dead_strip_dylibs/build.zig+1| ... | ... | @@ -52,6 +52,7 @@ fn createScenario( |
| 52 | 52 | const exe = b.addExecutable(.{ |
| 53 | 53 | .name = name, |
| 54 | 54 | .optimize = optimize, |
| 55 | .target = b.host, | |
| 55 | 56 | }); |
| 56 | 57 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 57 | 58 | exe.linkLibC(); |
test/link/macho/dylib/build.zig+2-2| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const dylib = b.addSharedLibrary(.{ |
| 19 | 19 | .name = "a", |
| ... | ... | @@ -55,7 +55,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 55 | 55 | |
| 56 | 56 | check_exe.checkInHeaders(); |
| 57 | 57 | check_exe.checkExact("cmd RPATH"); |
| 58 | check_exe.checkExactPath("path", dylib.getOutputDirectorySource()); | |
| 58 | check_exe.checkExactPath("path", dylib.getEmittedBinDirectory()); | |
| 59 | 59 | test_step.dependOn(&check_exe.step); |
| 60 | 60 | |
| 61 | 61 | const run = b.addRunArtifact(exe); |
test/link/macho/empty/build.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const exe = b.addExecutable(.{ |
| 19 | 19 | .name = "test", |
test/link/macho/entry/build.zig+1-1| ... | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | 16 | const exe = b.addExecutable(.{ |
| 17 | 17 | .name = "main", |
| 18 | 18 | .optimize = optimize, |
| 19 | .target = .{ .os_tag = .macos }, | |
| 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 20 | 20 | }); |
| 21 | 21 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 22 | 22 | exe.linkLibC(); |
test/link/macho/entry_in_archive/build.zig+2-2| ... | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | 16 | const lib = b.addStaticLibrary(.{ |
| 17 | 17 | .name = "main", |
| 18 | 18 | .optimize = optimize, |
| 19 | .target = .{ .os_tag = .macos }, | |
| 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 20 | 20 | }); |
| 21 | 21 | lib.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 22 | 22 | lib.linkLibC(); |
| ... | ... | @@ -24,7 +24,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 24 | 24 | const exe = b.addExecutable(.{ |
| 25 | 25 | .name = "main", |
| 26 | 26 | .optimize = optimize, |
| 27 | .target = .{ .os_tag = .macos }, | |
| 27 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 28 | 28 | }); |
| 29 | 29 | exe.linkLibrary(lib); |
| 30 | 30 | exe.linkLibC(); |
test/link/macho/entry_in_dylib/build.zig+2-2| ... | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | 16 | const lib = b.addSharedLibrary(.{ |
| 17 | 17 | .name = "bootstrap", |
| 18 | 18 | .optimize = optimize, |
| 19 | .target = .{ .os_tag = .macos }, | |
| 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 20 | 20 | }); |
| 21 | 21 | lib.addCSourceFile(.{ .file = .{ .path = "bootstrap.c" }, .flags = &.{} }); |
| 22 | 22 | lib.linkLibC(); |
| ... | ... | @@ -25,7 +25,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 25 | 25 | const exe = b.addExecutable(.{ |
| 26 | 26 | .name = "main", |
| 27 | 27 | .optimize = optimize, |
| 28 | .target = .{ .os_tag = .macos }, | |
| 28 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 29 | 29 | }); |
| 30 | 30 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 31 | 31 | exe.linkLibrary(lib); |
test/link/macho/headerpad/build.zig+1| ... | ... | @@ -112,6 +112,7 @@ fn simpleExe( |
| 112 | 112 | const exe = b.addExecutable(.{ |
| 113 | 113 | .name = name, |
| 114 | 114 | .optimize = optimize, |
| 115 | .target = b.host, | |
| 115 | 116 | }); |
| 116 | 117 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 117 | 118 | exe.linkLibC(); |
test/link/macho/linksection/build.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target = std.zig.CrossTarget{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const obj = b.addObject(.{ |
| 19 | 19 | .name = "test", |
test/link/macho/needed_framework/build.zig+1| ... | ... | @@ -19,6 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 19 | 19 | const exe = b.addExecutable(.{ |
| 20 | 20 | .name = "test", |
| 21 | 21 | .optimize = optimize, |
| 22 | .target = b.host, | |
| 22 | 23 | }); |
| 23 | 24 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 24 | 25 | exe.linkLibC(); |
test/link/macho/needed_library/build.zig+2-2| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const dylib = b.addSharedLibrary(.{ |
| 19 | 19 | .name = "a", |
| ... | ... | @@ -33,7 +33,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 33 | 33 | }); |
| 34 | 34 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 35 | 35 | exe.linkLibC(); |
| 36 | exe.linkSystemLibraryNeeded("a"); | |
| 36 | exe.root_module.linkSystemLibrary("a", .{ .needed = true }); | |
| 37 | 37 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 38 | 38 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 39 | 39 | exe.dead_strip_dylibs = true; |
test/link/macho/objc/build.zig+1| ... | ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | 17 | const exe = b.addExecutable(.{ |
| 18 | 18 | .name = "test", |
| 19 | 19 | .optimize = optimize, |
| 20 | .target = b.host, | |
| 20 | 21 | }); |
| 21 | 22 | exe.addIncludePath(.{ .path = "." }); |
| 22 | 23 | exe.addCSourceFile(.{ .file = .{ .path = "Foo.m" }, .flags = &[0][]const u8{} }); |
test/link/macho/objcpp/build.zig+1| ... | ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | 17 | const exe = b.addExecutable(.{ |
| 18 | 18 | .name = "test", |
| 19 | 19 | .optimize = optimize, |
| 20 | .target = b.host, | |
| 20 | 21 | }); |
| 21 | 22 | b.default_step.dependOn(&exe.step); |
| 22 | 23 | exe.addIncludePath(.{ .path = "." }); |
test/link/macho/pagezero/build.zig+1-1| ... | ... | @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | b.default_step = test_step; |
| 8 | 8 | |
| 9 | 9 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 10 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 10 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 11 | 11 | |
| 12 | 12 | { |
| 13 | 13 | const exe = b.addExecutable(.{ |
test/link/macho/reexports/build.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const lib = b.addStaticLibrary(.{ |
| 19 | 19 | .name = "a", |
test/link/macho/search_strategy/build.zig+3-3| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | { |
| 19 | 19 | // -search_dylibs_first |
| ... | ... | @@ -45,9 +45,9 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 45 | 45 | fn createScenario( |
| 46 | 46 | b: *std.Build, |
| 47 | 47 | optimize: std.builtin.OptimizeMode, |
| 48 | target: std.zig.CrossTarget, | |
| 48 | target: std.Build.ResolvedTarget, | |
| 49 | 49 | name: []const u8, |
| 50 | search_strategy: std.Build.Step.Compile.SystemLib.SearchStrategy, | |
| 50 | search_strategy: std.Build.Module.SystemLib.SearchStrategy, | |
| 51 | 51 | ) *std.Build.Step.Compile { |
| 52 | 52 | const static = b.addStaticLibrary(.{ |
| 53 | 53 | .name = name, |
test/link/macho/stack_size/build.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const exe = b.addExecutable(.{ |
| 19 | 19 | .name = "main", |
test/link/macho/strict_validation/build.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 17 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 18 | 18 | |
| 19 | 19 | const exe = b.addExecutable(.{ |
| 20 | 20 | .name = "main", |
test/link/macho/tbdv3/build.zig+1-1| ... | ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 18 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 18 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 19 | 19 | |
| 20 | 20 | const lib = b.addSharedLibrary(.{ |
| 21 | 21 | .name = "a", |
test/link/macho/tls/build.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const lib = b.addSharedLibrary(.{ |
| 19 | 19 | .name = "a", |
test/link/macho/unwind_info/build.zig+3-3| ... | ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 17 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 18 | 18 | |
| 19 | 19 | testUnwindInfo(b, test_step, optimize, target, false, "no-dead-strip"); |
| 20 | 20 | testUnwindInfo(b, test_step, optimize, target, true, "yes-dead-strip"); |
| ... | ... | @@ -24,7 +24,7 @@ fn testUnwindInfo( |
| 24 | 24 | b: *std.Build, |
| 25 | 25 | test_step: *std.Build.Step, |
| 26 | 26 | optimize: std.builtin.OptimizeMode, |
| 27 | target: std.zig.CrossTarget, | |
| 27 | target: std.Build.ResolvedTarget, | |
| 28 | 28 | dead_strip: bool, |
| 29 | 29 | name: []const u8, |
| 30 | 30 | ) void { |
| ... | ... | @@ -66,7 +66,7 @@ fn testUnwindInfo( |
| 66 | 66 | fn createScenario( |
| 67 | 67 | b: *std.Build, |
| 68 | 68 | optimize: std.builtin.OptimizeMode, |
| 69 | target: std.zig.CrossTarget, | |
| 69 | target: std.Build.ResolvedTarget, | |
| 70 | 70 | name: []const u8, |
| 71 | 71 | ) *std.Build.Step.Compile { |
| 72 | 72 | const exe = b.addExecutable(.{ |
test/link/macho/weak_framework/build.zig+1| ... | ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | 17 | const exe = b.addExecutable(.{ |
| 18 | 18 | .name = "test", |
| 19 | 19 | .optimize = optimize, |
| 20 | .target = b.host, | |
| 20 | 21 | }); |
| 21 | 22 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 22 | 23 | exe.linkLibC(); |
test/link/macho/weak_library/build.zig+2-2| ... | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | |
| 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); | |
| 17 | 17 | |
| 18 | 18 | const dylib = b.addSharedLibrary(.{ |
| 19 | 19 | .name = "a", |
| ... | ... | @@ -32,7 +32,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 32 | 32 | }); |
| 33 | 33 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 34 | 34 | exe.linkLibC(); |
| 35 | exe.linkSystemLibraryWeak("a"); | |
| 35 | exe.root_module.linkSystemLibrary("a", .{ .weak = true }); | |
| 36 | 36 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 37 | 37 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 38 | 38 |
test/link/static_libs_from_object_files/build.zig+8-6| ... | ... | @@ -59,7 +59,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 59 | 59 | .name = "test1", |
| 60 | 60 | .root_source_file = .{ .path = "main.zig" }, |
| 61 | 61 | .optimize = optimize, |
| 62 | .target = .{}, | |
| 62 | .target = b.host, | |
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | 65 | for (files) |file| { |
| ... | ... | @@ -77,12 +77,12 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 77 | 77 | { |
| 78 | 78 | const lib_a = b.addStaticLibrary(.{ |
| 79 | 79 | .name = "test2_a", |
| 80 | .target = .{}, | |
| 80 | .target = b.host, | |
| 81 | 81 | .optimize = optimize, |
| 82 | 82 | }); |
| 83 | 83 | const lib_b = b.addStaticLibrary(.{ |
| 84 | 84 | .name = "test2_b", |
| 85 | .target = .{}, | |
| 85 | .target = b.host, | |
| 86 | 86 | .optimize = optimize, |
| 87 | 87 | }); |
| 88 | 88 | |
| ... | ... | @@ -94,6 +94,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 94 | 94 | const exe = b.addExecutable(.{ |
| 95 | 95 | .name = "test2", |
| 96 | 96 | .root_source_file = .{ .path = "main.zig" }, |
| 97 | .target = b.host, | |
| 97 | 98 | .optimize = optimize, |
| 98 | 99 | }); |
| 99 | 100 | exe.linkLibrary(lib_a); |
| ... | ... | @@ -110,19 +111,19 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 110 | 111 | { |
| 111 | 112 | const lib_a = b.addStaticLibrary(.{ |
| 112 | 113 | .name = "test3_a", |
| 113 | .target = .{}, | |
| 114 | .target = b.host, | |
| 114 | 115 | .optimize = optimize, |
| 115 | 116 | }); |
| 116 | 117 | const lib_b = b.addStaticLibrary(.{ |
| 117 | 118 | .name = "test3_b", |
| 118 | .target = .{}, | |
| 119 | .target = b.host, | |
| 119 | 120 | .optimize = optimize, |
| 120 | 121 | }); |
| 121 | 122 | |
| 122 | 123 | for (files, 1..) |file, i| { |
| 123 | 124 | const obj = b.addObject(.{ |
| 124 | 125 | .name = b.fmt("obj_{}", .{i}), |
| 125 | .target = .{}, | |
| 126 | .target = b.host, | |
| 126 | 127 | .optimize = optimize, |
| 127 | 128 | }); |
| 128 | 129 | obj.addCSourceFile(.{ .file = file, .flags = &flags }); |
| ... | ... | @@ -134,6 +135,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 134 | 135 | const exe = b.addExecutable(.{ |
| 135 | 136 | .name = "test3", |
| 136 | 137 | .root_source_file = .{ .path = "main.zig" }, |
| 138 | .target = b.host, | |
| 137 | 139 | .optimize = optimize, |
| 138 | 140 | }); |
| 139 | 141 | exe.linkLibrary(lib_a); |
test/link/wasm/archive/build.zig+1-1| ... | ... | @@ -20,11 +20,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 20 | 20 | .root_source_file = .{ .path = "main.zig" }, |
| 21 | 21 | .optimize = optimize, |
| 22 | 22 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, |
| 23 | .strip = false, | |
| 23 | 24 | }); |
| 24 | 25 | lib.entry = .disabled; |
| 25 | 26 | lib.use_llvm = false; |
| 26 | 27 | lib.use_lld = false; |
| 27 | lib.strip = false; | |
| 28 | 28 | |
| 29 | 29 | const check = lib.checkObject(); |
| 30 | 30 | check.checkInHeaders(); |
test/link/wasm/basic-features/build.zig+2-2| ... | ... | @@ -8,12 +8,12 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | .name = "lib", |
| 9 | 9 | .root_source_file = .{ .path = "main.zig" }, |
| 10 | 10 | .optimize = .Debug, |
| 11 | .target = .{ | |
| 11 | .target = b.resolveTargetQuery(.{ | |
| 12 | 12 | .cpu_arch = .wasm32, |
| 13 | 13 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, |
| 14 | 14 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), |
| 15 | 15 | .os_tag = .freestanding, |
| 16 | }, | |
| 16 | }), | |
| 17 | 17 | }); |
| 18 | 18 | lib.entry = .disabled; |
| 19 | 19 | lib.use_llvm = false; |
test/link/wasm/bss/build.zig+4-4| ... | ... | @@ -17,13 +17,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 17 | 17 | const lib = b.addExecutable(.{ |
| 18 | 18 | .name = "lib", |
| 19 | 19 | .root_source_file = .{ .path = "lib.zig" }, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | 21 | .optimize = optimize_mode, |
| 22 | .strip = false, | |
| 22 | 23 | }); |
| 23 | 24 | lib.entry = .disabled; |
| 24 | 25 | lib.use_llvm = false; |
| 25 | 26 | lib.use_lld = false; |
| 26 | lib.strip = false; | |
| 27 | 27 | // to make sure the bss segment is emitted, we must import memory |
| 28 | 28 | lib.import_memory = true; |
| 29 | 29 | lib.link_gc_sections = false; |
| ... | ... | @@ -65,13 +65,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 65 | 65 | const lib = b.addExecutable(.{ |
| 66 | 66 | .name = "lib", |
| 67 | 67 | .root_source_file = .{ .path = "lib2.zig" }, |
| 68 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 68 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 69 | 69 | .optimize = optimize_mode, |
| 70 | .strip = false, | |
| 70 | 71 | }); |
| 71 | 72 | lib.entry = .disabled; |
| 72 | 73 | lib.use_llvm = false; |
| 73 | 74 | lib.use_lld = false; |
| 74 | lib.strip = false; | |
| 75 | 75 | // to make sure the bss segment is emitted, we must import memory |
| 76 | 76 | lib.import_memory = true; |
| 77 | 77 | lib.link_gc_sections = false; |
test/link/wasm/export-data/build.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { |
| 17 | 17 | }); |
| 18 | 18 | lib.entry = .disabled; |
| 19 | 19 | lib.use_lld = false; |
| 20 | lib.export_symbol_names = &.{ "foo", "bar" }; | |
| 20 | lib.root_module.export_symbol_names = &.{ "foo", "bar" }; | |
| 21 | 21 | lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse |
| 22 | 22 | |
| 23 | 23 | const check_lib = lib.checkObject(); |
test/link/wasm/export/build.zig+4-4| ... | ... | @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | 17 | .name = "no-export", |
| 18 | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 19 | 19 | .optimize = optimize, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | 21 | }); |
| 22 | 22 | no_export.entry = .disabled; |
| 23 | 23 | no_export.use_llvm = false; |
| ... | ... | @@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 27 | 27 | .name = "dynamic", |
| 28 | 28 | .root_source_file = .{ .path = "main.zig" }, |
| 29 | 29 | .optimize = optimize, |
| 30 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 30 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 31 | 31 | }); |
| 32 | 32 | dynamic_export.entry = .disabled; |
| 33 | 33 | dynamic_export.rdynamic = true; |
| ... | ... | @@ -38,10 +38,10 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 38 | 38 | .name = "force", |
| 39 | 39 | .root_source_file = .{ .path = "main.zig" }, |
| 40 | 40 | .optimize = optimize, |
| 41 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 41 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 42 | 42 | }); |
| 43 | 43 | force_export.entry = .disabled; |
| 44 | force_export.export_symbol_names = &.{"foo"}; | |
| 44 | force_export.root_module.export_symbol_names = &.{"foo"}; | |
| 45 | 45 | force_export.use_llvm = false; |
| 46 | 46 | force_export.use_lld = false; |
| 47 | 47 |
test/link/wasm/extern-mangle/build.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | 14 | const lib = b.addExecutable(.{ |
| 15 | 15 | .name = "lib", |
| 16 | 16 | .root_source_file = .{ .path = "lib.zig" }, |
| 17 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 18 | 18 | .optimize = optimize, |
| 19 | 19 | }); |
| 20 | 20 | lib.entry = .disabled; |
test/link/wasm/extern/build.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | 17 | .name = "extern", |
| 18 | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 19 | 19 | .optimize = optimize, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .wasi }, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), | |
| 21 | 21 | }); |
| 22 | 22 | exe.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); |
| 23 | 23 | exe.use_llvm = false; |
test/link/wasm/function-table/build.zig+3-3| ... | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | 16 | const import_table = b.addExecutable(.{ |
| 17 | 17 | .name = "import_table", |
| 18 | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | 20 | .optimize = optimize, |
| 21 | 21 | }); |
| 22 | 22 | import_table.entry = .disabled; |
| ... | ... | @@ -28,7 +28,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 28 | 28 | const export_table = b.addExecutable(.{ |
| 29 | 29 | .name = "export_table", |
| 30 | 30 | .root_source_file = .{ .path = "lib.zig" }, |
| 31 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 31 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 32 | 32 | .optimize = optimize, |
| 33 | 33 | }); |
| 34 | 34 | export_table.entry = .disabled; |
| ... | ... | @@ -40,7 +40,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 40 | 40 | const regular_table = b.addExecutable(.{ |
| 41 | 41 | .name = "regular_table", |
| 42 | 42 | .root_source_file = .{ .path = "lib.zig" }, |
| 43 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 43 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 44 | 44 | .optimize = optimize, |
| 45 | 45 | }); |
| 46 | 46 | regular_table.entry = .disabled; |
test/link/wasm/infer-features/build.zig+4-4| ... | ... | @@ -7,11 +7,11 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | const c_obj = b.addObject(.{ |
| 8 | 8 | .name = "c_obj", |
| 9 | 9 | .optimize = .Debug, |
| 10 | .target = .{ | |
| 10 | .target = b.resolveTargetQuery(.{ | |
| 11 | 11 | .cpu_arch = .wasm32, |
| 12 | 12 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, |
| 13 | 13 | .os_tag = .freestanding, |
| 14 | }, | |
| 14 | }), | |
| 15 | 15 | }); |
| 16 | 16 | c_obj.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); |
| 17 | 17 | |
| ... | ... | @@ -21,11 +21,11 @@ pub fn build(b: *std.Build) void { |
| 21 | 21 | .name = "lib", |
| 22 | 22 | .root_source_file = .{ .path = "main.zig" }, |
| 23 | 23 | .optimize = .Debug, |
| 24 | .target = .{ | |
| 24 | .target = b.resolveTargetQuery(.{ | |
| 25 | 25 | .cpu_arch = .wasm32, |
| 26 | 26 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, |
| 27 | 27 | .os_tag = .freestanding, |
| 28 | }, | |
| 28 | }), | |
| 29 | 29 | }); |
| 30 | 30 | lib.entry = .disabled; |
| 31 | 31 | lib.use_llvm = false; |
test/link/wasm/producers/build.zig+2-2| ... | ... | @@ -17,13 +17,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | 17 | const lib = b.addExecutable(.{ |
| 18 | 18 | .name = "lib", |
| 19 | 19 | .root_source_file = .{ .path = "lib.zig" }, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | 21 | .optimize = optimize, |
| 22 | .strip = false, | |
| 22 | 23 | }); |
| 23 | 24 | lib.entry = .disabled; |
| 24 | 25 | lib.use_llvm = false; |
| 25 | 26 | lib.use_lld = false; |
| 26 | lib.strip = false; | |
| 27 | 27 | b.installArtifact(lib); |
| 28 | 28 | |
| 29 | 29 | const version_fmt = "version " ++ builtin.zig_version_string; |
test/link/wasm/segments/build.zig+2-2| ... | ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | 16 | const lib = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | 20 | .optimize = optimize, |
| 21 | .strip = false, | |
| 21 | 22 | }); |
| 22 | 23 | lib.entry = .disabled; |
| 23 | 24 | lib.use_llvm = false; |
| 24 | 25 | lib.use_lld = false; |
| 25 | lib.strip = false; | |
| 26 | 26 | lib.link_gc_sections = false; // so data is not garbage collected and we can verify data section |
| 27 | 27 | b.installArtifact(lib); |
| 28 | 28 |
test/link/wasm/shared-memory/build.zig+3-3| ... | ... | @@ -21,16 +21,16 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 21 | 21 | .os_tag = .freestanding, |
| 22 | 22 | }, |
| 23 | 23 | .optimize = optimize_mode, |
| 24 | .strip = false, | |
| 25 | .single_threaded = false, | |
| 24 | 26 | }); |
| 25 | 27 | lib.entry = .disabled; |
| 26 | 28 | lib.use_lld = false; |
| 27 | lib.strip = false; | |
| 28 | 29 | lib.import_memory = true; |
| 29 | 30 | lib.export_memory = true; |
| 30 | 31 | lib.shared_memory = true; |
| 31 | 32 | lib.max_memory = 67108864; |
| 32 | lib.single_threaded = false; | |
| 33 | lib.export_symbol_names = &.{"foo"}; | |
| 33 | lib.root_module.export_symbol_names = &.{"foo"}; | |
| 34 | 34 | |
| 35 | 35 | const check_lib = lib.checkObject(); |
| 36 | 36 |
test/link/wasm/stack_pointer/build.zig+2-2| ... | ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | 16 | const lib = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | 20 | .optimize = optimize, |
| 21 | .strip = false, | |
| 21 | 22 | }); |
| 22 | 23 | lib.entry = .disabled; |
| 23 | 24 | lib.use_llvm = false; |
| 24 | 25 | lib.use_lld = false; |
| 25 | lib.strip = false; | |
| 26 | 26 | lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size |
| 27 | 27 | lib.link_gc_sections = false; |
| 28 | 28 | b.installArtifact(lib); |
test/link/wasm/type/build.zig+2-2| ... | ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | 16 | const lib = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | 20 | .optimize = optimize, |
| 21 | .strip = false, | |
| 21 | 22 | }); |
| 22 | 23 | lib.entry = .disabled; |
| 23 | 24 | lib.use_llvm = false; |
| 24 | 25 | lib.use_lld = false; |
| 25 | lib.strip = false; | |
| 26 | 26 | b.installArtifact(lib); |
| 27 | 27 | |
| 28 | 28 | const check_lib = lib.checkObject(); |
test/llvm_targets.zig+8-4| ... | ... | @@ -127,17 +127,21 @@ const targets = [_]std.zig.CrossTarget{ |
| 127 | 127 | .{ .cpu_arch = .xtensa, .os_tag = .linux, .abi = .none }, |
| 128 | 128 | }; |
| 129 | 129 | |
| 130 | pub fn addCases(ctx: *Cases, build_options: @import("cases.zig").BuildOptions) !void { | |
| 130 | pub fn addCases( | |
| 131 | ctx: *Cases, | |
| 132 | build_options: @import("cases.zig").BuildOptions, | |
| 133 | b: *std.Build, | |
| 134 | ) !void { | |
| 131 | 135 | if (!build_options.enable_llvm) return; |
| 132 | for (targets) |target| { | |
| 133 | if (target.cpu_arch) |arch| switch (arch) { | |
| 136 | for (targets) |target_query| { | |
| 137 | if (target_query.cpu_arch) |arch| switch (arch) { | |
| 134 | 138 | .m68k => if (!build_options.llvm_has_m68k) continue, |
| 135 | 139 | .csky => if (!build_options.llvm_has_csky) continue, |
| 136 | 140 | .arc => if (!build_options.llvm_has_arc) continue, |
| 137 | 141 | .xtensa => if (!build_options.llvm_has_xtensa) continue, |
| 138 | 142 | else => {}, |
| 139 | 143 | }; |
| 140 | var case = ctx.noEmitUsingLlvmBackend("llvm_targets", target); | |
| 144 | var case = ctx.noEmitUsingLlvmBackend("llvm_targets", b.resolveTargetQuery(target_query)); | |
| 141 | 145 | case.addCompile(""); |
| 142 | 146 | } |
| 143 | 147 | } |
test/nvptx.zig+12-15| ... | ... | @@ -1,9 +1,14 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const Cases = @import("src/Cases.zig"); |
| 3 | 3 | |
| 4 | pub fn addCases(ctx: *Cases) !void { | |
| 4 | pub fn addCases(ctx: *Cases, b: *std.Build) !void { | |
| 5 | const target = b.resolveTargetQuery(.{ | |
| 6 | .cpu_arch = .nvptx64, | |
| 7 | .os_tag = .cuda, | |
| 8 | }); | |
| 9 | ||
| 5 | 10 | { |
| 6 | var case = addPtx(ctx, "simple addition and subtraction"); | |
| 11 | var case = addPtx(ctx, target, "simple addition and subtraction"); | |
| 7 | 12 | |
| 8 | 13 | case.addCompile( |
| 9 | 14 | \\fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -20,7 +25,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 20 | 25 | } |
| 21 | 26 | |
| 22 | 27 | { |
| 23 | var case = addPtx(ctx, "read special registers"); | |
| 28 | var case = addPtx(ctx, target, "read special registers"); | |
| 24 | 29 | |
| 25 | 30 | case.addCompile( |
| 26 | 31 | \\fn threadIdX() u32 { |
| ... | ... | @@ -37,7 +42,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 37 | 42 | } |
| 38 | 43 | |
| 39 | 44 | { |
| 40 | var case = addPtx(ctx, "address spaces"); | |
| 45 | var case = addPtx(ctx, target, "address spaces"); | |
| 41 | 46 | |
| 42 | 47 | case.addCompile( |
| 43 | 48 | \\var x: i32 addrspace(.global) = 0; |
| ... | ... | @@ -50,7 +55,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 50 | 55 | } |
| 51 | 56 | |
| 52 | 57 | { |
| 53 | var case = addPtx(ctx, "reduce in shared mem"); | |
| 58 | var case = addPtx(ctx, target, "reduce in shared mem"); | |
| 54 | 59 | case.addCompile( |
| 55 | 60 | \\fn threadIdX() u32 { |
| 56 | 61 | \\ return asm ("mov.u32 \t%[r], %tid.x;" |
| ... | ... | @@ -82,18 +87,10 @@ pub fn addCases(ctx: *Cases) !void { |
| 82 | 87 | } |
| 83 | 88 | } |
| 84 | 89 | |
| 85 | const nvptx_target = std.zig.CrossTarget{ | |
| 86 | .cpu_arch = .nvptx64, | |
| 87 | .os_tag = .cuda, | |
| 88 | }; | |
| 89 | ||
| 90 | pub fn addPtx( | |
| 91 | ctx: *Cases, | |
| 92 | name: []const u8, | |
| 93 | ) *Cases.Case { | |
| 90 | fn addPtx(ctx: *Cases, target: std.Build.ResolvedTarget, name: []const u8) *Cases.Case { | |
| 94 | 91 | ctx.cases.append(.{ |
| 95 | 92 | .name = name, |
| 96 | .target = nvptx_target, | |
| 93 | .target = target, | |
| 97 | 94 | .updates = std.ArrayList(Cases.Update).init(ctx.cases.allocator), |
| 98 | 95 | .output_mode = .Obj, |
| 99 | 96 | .deps = std.ArrayList(Cases.DepModule).init(ctx.cases.allocator), |
test/src/Cases.zig+60-49| ... | ... | @@ -76,7 +76,7 @@ pub const Case = struct { |
| 76 | 76 | name: []const u8, |
| 77 | 77 | /// The platform the test targets. For non-native platforms, an emulator |
| 78 | 78 | /// such as QEMU is required for tests to complete. |
| 79 | target: CrossTarget, | |
| 79 | target: std.Build.ResolvedTarget, | |
| 80 | 80 | /// In order to be able to run e.g. Execution updates, this must be set |
| 81 | 81 | /// to Executable. |
| 82 | 82 | output_mode: std.builtin.OutputMode, |
| ... | ... | @@ -155,7 +155,7 @@ pub const Translate = struct { |
| 155 | 155 | name: []const u8, |
| 156 | 156 | |
| 157 | 157 | input: [:0]const u8, |
| 158 | target: CrossTarget, | |
| 158 | target: std.Build.ResolvedTarget, | |
| 159 | 159 | link_libc: bool, |
| 160 | 160 | c_frontend: CFrontend, |
| 161 | 161 | kind: union(enum) { |
| ... | ... | @@ -171,7 +171,7 @@ pub const Translate = struct { |
| 171 | 171 | pub fn addExe( |
| 172 | 172 | ctx: *Cases, |
| 173 | 173 | name: []const u8, |
| 174 | target: CrossTarget, | |
| 174 | target: std.Build.ResolvedTarget, | |
| 175 | 175 | ) *Case { |
| 176 | 176 | ctx.cases.append(Case{ |
| 177 | 177 | .name = name, |
| ... | ... | @@ -184,16 +184,16 @@ pub fn addExe( |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /// Adds a test case for Zig input, producing an executable |
| 187 | pub fn exe(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | |
| 187 | pub fn exe(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { | |
| 188 | 188 | return ctx.addExe(name, target); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | |
| 192 | var target_adjusted = target; | |
| 193 | target_adjusted.ofmt = .c; | |
| 191 | pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target_query: std.zig.CrossTarget, b: *std.Build) *Case { | |
| 192 | var adjusted_query = target_query; | |
| 193 | adjusted_query.ofmt = .c; | |
| 194 | 194 | ctx.cases.append(Case{ |
| 195 | 195 | .name = name, |
| 196 | .target = target_adjusted, | |
| 196 | .target = b.resolveTargetQuery(adjusted_query), | |
| 197 | 197 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 198 | 198 | .output_mode = .Exe, |
| 199 | 199 | .deps = std.ArrayList(DepModule).init(ctx.arena), |
| ... | ... | @@ -202,7 +202,7 @@ pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target: CrossTarget) *Cas |
| 202 | 202 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | |
| 205 | pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { | |
| 206 | 206 | ctx.cases.append(Case{ |
| 207 | 207 | .name = name, |
| 208 | 208 | .target = target, |
| ... | ... | @@ -217,7 +217,7 @@ pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget |
| 217 | 217 | |
| 218 | 218 | /// Adds a test case that uses the LLVM backend to emit an executable. |
| 219 | 219 | /// Currently this implies linking libc, because only then we can generate a testable executable. |
| 220 | pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | |
| 220 | pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { | |
| 221 | 221 | ctx.cases.append(Case{ |
| 222 | 222 | .name = name, |
| 223 | 223 | .target = target, |
| ... | ... | @@ -233,7 +233,7 @@ pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) * |
| 233 | 233 | pub fn addObj( |
| 234 | 234 | ctx: *Cases, |
| 235 | 235 | name: []const u8, |
| 236 | target: CrossTarget, | |
| 236 | target: std.Build.ResolvedTarget, | |
| 237 | 237 | ) *Case { |
| 238 | 238 | ctx.cases.append(Case{ |
| 239 | 239 | .name = name, |
| ... | ... | @@ -248,7 +248,7 @@ pub fn addObj( |
| 248 | 248 | pub fn addTest( |
| 249 | 249 | ctx: *Cases, |
| 250 | 250 | name: []const u8, |
| 251 | target: CrossTarget, | |
| 251 | target: std.Build.ResolvedTarget, | |
| 252 | 252 | ) *Case { |
| 253 | 253 | ctx.cases.append(Case{ |
| 254 | 254 | .name = name, |
| ... | ... | @@ -262,17 +262,17 @@ pub fn addTest( |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /// Adds a test case for Zig input, producing an object file. |
| 265 | pub fn obj(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | |
| 265 | pub fn obj(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { | |
| 266 | 266 | return ctx.addObj(name, target); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /// Adds a test case for ZIR input, producing an object file. |
| 270 | pub fn objZIR(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | |
| 270 | pub fn objZIR(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { | |
| 271 | 271 | return ctx.addObj(name, target, .ZIR); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /// Adds a test case for Zig or ZIR input, producing C code. |
| 275 | pub fn addC(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | |
| 275 | pub fn addC(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { | |
| 276 | 276 | var target_adjusted = target; |
| 277 | 277 | target_adjusted.ofmt = std.Target.ObjectFormat.c; |
| 278 | 278 | ctx.cases.append(Case{ |
| ... | ... | @@ -308,7 +308,7 @@ pub fn compareOutput( |
| 308 | 308 | pub fn addTransform( |
| 309 | 309 | ctx: *Cases, |
| 310 | 310 | name: []const u8, |
| 311 | target: CrossTarget, | |
| 311 | target: std.Build.ResolvedTarget, | |
| 312 | 312 | src: [:0]const u8, |
| 313 | 313 | result: [:0]const u8, |
| 314 | 314 | ) void { |
| ... | ... | @@ -320,7 +320,7 @@ pub fn addTransform( |
| 320 | 320 | pub fn transform( |
| 321 | 321 | ctx: *Cases, |
| 322 | 322 | name: []const u8, |
| 323 | target: CrossTarget, | |
| 323 | target: std.Build.ResolvedTarget, | |
| 324 | 324 | src: [:0]const u8, |
| 325 | 325 | result: [:0]const u8, |
| 326 | 326 | ) void { |
| ... | ... | @@ -330,7 +330,7 @@ pub fn transform( |
| 330 | 330 | pub fn addError( |
| 331 | 331 | ctx: *Cases, |
| 332 | 332 | name: []const u8, |
| 333 | target: CrossTarget, | |
| 333 | target: std.Build.ResolvedTarget, | |
| 334 | 334 | src: [:0]const u8, |
| 335 | 335 | expected_errors: []const []const u8, |
| 336 | 336 | ) void { |
| ... | ... | @@ -343,7 +343,7 @@ pub fn addError( |
| 343 | 343 | pub fn compileError( |
| 344 | 344 | ctx: *Cases, |
| 345 | 345 | name: []const u8, |
| 346 | target: CrossTarget, | |
| 346 | target: std.Build.ResolvedTarget, | |
| 347 | 347 | src: [:0]const u8, |
| 348 | 348 | expected_errors: []const []const u8, |
| 349 | 349 | ) void { |
| ... | ... | @@ -355,7 +355,7 @@ pub fn compileError( |
| 355 | 355 | pub fn addCompile( |
| 356 | 356 | ctx: *Cases, |
| 357 | 357 | name: []const u8, |
| 358 | target: CrossTarget, | |
| 358 | target: std.Build.ResolvedTarget, | |
| 359 | 359 | src: [:0]const u8, |
| 360 | 360 | ) void { |
| 361 | 361 | ctx.addObj(name, target).addCompile(src); |
| ... | ... | @@ -368,9 +368,9 @@ pub fn addCompile( |
| 368 | 368 | /// Each file should include a test manifest as a contiguous block of comments at |
| 369 | 369 | /// the end of the file. The first line should be the test type, followed by a set of |
| 370 | 370 | /// key-value config values, followed by a blank line, then the expected output. |
| 371 | pub fn addFromDir(ctx: *Cases, dir: std.fs.Dir) void { | |
| 371 | pub fn addFromDir(ctx: *Cases, dir: std.fs.Dir, b: *std.Build) void { | |
| 372 | 372 | var current_file: []const u8 = "none"; |
| 373 | ctx.addFromDirInner(dir, &current_file) catch |err| { | |
| 373 | ctx.addFromDirInner(dir, &current_file, b) catch |err| { | |
| 374 | 374 | std.debug.panicExtra( |
| 375 | 375 | @errorReturnTrace(), |
| 376 | 376 | @returnAddress(), |
| ... | ... | @@ -386,6 +386,7 @@ fn addFromDirInner( |
| 386 | 386 | /// This is kept up to date with the currently being processed file so |
| 387 | 387 | /// that if any errors occur the caller knows it happened during this file. |
| 388 | 388 | current_file: *[]const u8, |
| 389 | b: *std.Build, | |
| 389 | 390 | ) !void { |
| 390 | 391 | var it = try iterable_dir.walk(ctx.arena); |
| 391 | 392 | var filenames = std.ArrayList([]const u8).init(ctx.arena); |
| ... | ... | @@ -422,7 +423,7 @@ fn addFromDirInner( |
| 422 | 423 | var manifest = try TestManifest.parse(ctx.arena, src); |
| 423 | 424 | |
| 424 | 425 | const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend); |
| 425 | const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", CrossTarget); | |
| 426 | const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", std.zig.CrossTarget); | |
| 426 | 427 | const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); |
| 427 | 428 | const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); |
| 428 | 429 | const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); |
| ... | ... | @@ -430,12 +431,12 @@ fn addFromDirInner( |
| 430 | 431 | |
| 431 | 432 | if (manifest.type == .translate_c) { |
| 432 | 433 | for (c_frontends) |c_frontend| { |
| 433 | for (targets) |target| { | |
| 434 | for (targets) |target_query| { | |
| 434 | 435 | const output = try manifest.trailingLinesSplit(ctx.arena); |
| 435 | 436 | try ctx.translate.append(.{ |
| 436 | 437 | .name = std.fs.path.stem(filename), |
| 437 | 438 | .c_frontend = c_frontend, |
| 438 | .target = target, | |
| 439 | .target = b.resolveTargetQuery(target_query), | |
| 439 | 440 | .link_libc = link_libc, |
| 440 | 441 | .input = src, |
| 441 | 442 | .kind = .{ .translate = output }, |
| ... | ... | @@ -446,12 +447,12 @@ fn addFromDirInner( |
| 446 | 447 | } |
| 447 | 448 | if (manifest.type == .run_translated_c) { |
| 448 | 449 | for (c_frontends) |c_frontend| { |
| 449 | for (targets) |target| { | |
| 450 | for (targets) |target_query| { | |
| 450 | 451 | const output = try manifest.trailingSplit(ctx.arena); |
| 451 | 452 | try ctx.translate.append(.{ |
| 452 | 453 | .name = std.fs.path.stem(filename), |
| 453 | 454 | .c_frontend = c_frontend, |
| 454 | .target = target, | |
| 455 | .target = b.resolveTargetQuery(target_query), | |
| 455 | 456 | .link_libc = link_libc, |
| 456 | 457 | .input = src, |
| 457 | 458 | .kind = .{ .run = output }, |
| ... | ... | @@ -464,16 +465,18 @@ fn addFromDirInner( |
| 464 | 465 | var cases = std.ArrayList(usize).init(ctx.arena); |
| 465 | 466 | |
| 466 | 467 | // Cross-product to get all possible test combinations |
| 467 | for (backends) |backend| { | |
| 468 | for (targets) |target| { | |
| 468 | for (targets) |target_query| { | |
| 469 | const resolved_target = b.resolveTargetQuery(target_query); | |
| 470 | const target = resolved_target.target; | |
| 471 | for (backends) |backend| { | |
| 469 | 472 | if (backend == .stage2 and |
| 470 | target.getCpuArch() != .wasm32 and target.getCpuArch() != .x86_64) | |
| 473 | target.cpu.arch != .wasm32 and target.cpu.arch != .x86_64) | |
| 471 | 474 | { |
| 472 | 475 | // Other backends don't support new liveness format |
| 473 | 476 | continue; |
| 474 | 477 | } |
| 475 | if (backend == .stage2 and target.getOsTag() == .macos and | |
| 476 | target.getCpuArch() == .x86_64 and builtin.cpu.arch == .aarch64) | |
| 478 | if (backend == .stage2 and target.os.tag == .macos and | |
| 479 | target.cpu.arch == .x86_64 and builtin.cpu.arch == .aarch64) | |
| 477 | 480 | { |
| 478 | 481 | // Rosetta has issues with ZLD |
| 479 | 482 | continue; |
| ... | ... | @@ -482,7 +485,7 @@ fn addFromDirInner( |
| 482 | 485 | const next = ctx.cases.items.len; |
| 483 | 486 | try ctx.cases.append(.{ |
| 484 | 487 | .name = std.fs.path.stem(filename), |
| 485 | .target = target, | |
| 488 | .target = resolved_target, | |
| 486 | 489 | .backend = backend, |
| 487 | 490 | .updates = std.ArrayList(Cases.Update).init(ctx.cases.allocator), |
| 488 | 491 | .is_test = is_test, |
| ... | ... | @@ -622,8 +625,8 @@ pub fn lowerToBuildSteps( |
| 622 | 625 | } |
| 623 | 626 | |
| 624 | 627 | for (case.deps.items) |dep| { |
| 625 | artifact.addAnonymousModule(dep.name, .{ | |
| 626 | .source_file = file_sources.get(dep.path).?, | |
| 628 | artifact.root_module.addAnonymousImport(dep.name, .{ | |
| 629 | .root_source_file = file_sources.get(dep.path).?, | |
| 627 | 630 | }); |
| 628 | 631 | } |
| 629 | 632 | |
| ... | ... | @@ -644,9 +647,8 @@ pub fn lowerToBuildSteps( |
| 644 | 647 | parent_step.dependOn(&artifact.step); |
| 645 | 648 | }, |
| 646 | 649 | .Execution => |expected_stdout| no_exec: { |
| 647 | const run = if (case.target.ofmt == .c) run_step: { | |
| 648 | const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err| | |
| 649 | std.debug.panic("unable to detect target host: {s}\n", .{@errorName(err)}); | |
| 650 | const run = if (case.target.target.ofmt == .c) run_step: { | |
| 651 | const target_info = case.target.toNativeTargetInfo(); | |
| 650 | 652 | if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) { |
| 651 | 653 | // We wouldn't be able to run the compiled C code. |
| 652 | 654 | break :no_exec; |
| ... | ... | @@ -666,7 +668,7 @@ pub fn lowerToBuildSteps( |
| 666 | 668 | "--", |
| 667 | 669 | "-lc", |
| 668 | 670 | "-target", |
| 669 | case.target.zigTriple(b.allocator) catch @panic("OOM"), | |
| 671 | case.target.target.zigTriple(b.allocator) catch @panic("OOM"), | |
| 670 | 672 | }); |
| 671 | 673 | run_c.addArtifactArg(artifact); |
| 672 | 674 | break :run_step run_c; |
| ... | ... | @@ -692,8 +694,7 @@ pub fn lowerToBuildSteps( |
| 692 | 694 | continue; // Pass test. |
| 693 | 695 | } |
| 694 | 696 | |
| 695 | const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err| | |
| 696 | std.debug.panic("unable to detect target host: {s}\n", .{@errorName(err)}); | |
| 697 | const target_info = case.target.toNativeTargetInfo(); | |
| 697 | 698 | if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) { |
| 698 | 699 | // We wouldn't be able to run the compiled C code. |
| 699 | 700 | continue; // Pass test. |
| ... | ... | @@ -1159,9 +1160,9 @@ const TestManifest = struct { |
| 1159 | 1160 | } |
| 1160 | 1161 | |
| 1161 | 1162 | fn getDefaultParser(comptime T: type) ParseFn(T) { |
| 1162 | if (T == CrossTarget) return struct { | |
| 1163 | if (T == std.zig.CrossTarget) return struct { | |
| 1163 | 1164 | fn parse(str: []const u8) anyerror!T { |
| 1164 | return CrossTarget.parse(.{ .arch_os_abi = str }); | |
| 1165 | return std.zig.CrossTarget.parse(.{ .arch_os_abi = str }); | |
| 1165 | 1166 | } |
| 1166 | 1167 | }.parse; |
| 1167 | 1168 | |
| ... | ... | @@ -1198,7 +1199,6 @@ const builtin = @import("builtin"); |
| 1198 | 1199 | const std = @import("std"); |
| 1199 | 1200 | const assert = std.debug.assert; |
| 1200 | 1201 | const Allocator = std.mem.Allocator; |
| 1201 | const CrossTarget = std.zig.CrossTarget; | |
| 1202 | 1202 | const Compilation = @import("../../src/Compilation.zig"); |
| 1203 | 1203 | const zig_h = @import("../../src/link.zig").File.C.zig_h; |
| 1204 | 1204 | const introspect = @import("../../src/introspect.zig"); |
| ... | ... | @@ -1287,7 +1287,7 @@ pub fn main() !void { |
| 1287 | 1287 | |
| 1288 | 1288 | if (cases.items.len == 0) { |
| 1289 | 1289 | const backends = try manifest.getConfigForKeyAlloc(arena, "backend", Backend); |
| 1290 | const targets = try manifest.getConfigForKeyAlloc(arena, "target", CrossTarget); | |
| 1290 | const targets = try manifest.getConfigForKeyAlloc(arena, "target", std.zig.CrossTarget); | |
| 1291 | 1291 | const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); |
| 1292 | 1292 | const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); |
| 1293 | 1293 | const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); |
| ... | ... | @@ -1295,12 +1295,12 @@ pub fn main() !void { |
| 1295 | 1295 | |
| 1296 | 1296 | if (manifest.type == .translate_c) { |
| 1297 | 1297 | for (c_frontends) |c_frontend| { |
| 1298 | for (targets) |target| { | |
| 1298 | for (targets) |target_query| { | |
| 1299 | 1299 | const output = try manifest.trailingLinesSplit(ctx.arena); |
| 1300 | 1300 | try ctx.translate.append(.{ |
| 1301 | 1301 | .name = std.fs.path.stem(filename), |
| 1302 | 1302 | .c_frontend = c_frontend, |
| 1303 | .target = target, | |
| 1303 | .target = resolveTargetQuery(target_query), | |
| 1304 | 1304 | .is_test = is_test, |
| 1305 | 1305 | .link_libc = link_libc, |
| 1306 | 1306 | .input = src, |
| ... | ... | @@ -1312,12 +1312,12 @@ pub fn main() !void { |
| 1312 | 1312 | } |
| 1313 | 1313 | if (manifest.type == .run_translated_c) { |
| 1314 | 1314 | for (c_frontends) |c_frontend| { |
| 1315 | for (targets) |target| { | |
| 1315 | for (targets) |target_query| { | |
| 1316 | 1316 | const output = try manifest.trailingSplit(ctx.arena); |
| 1317 | 1317 | try ctx.translate.append(.{ |
| 1318 | 1318 | .name = std.fs.path.stem(filename), |
| 1319 | 1319 | .c_frontend = c_frontend, |
| 1320 | .target = target, | |
| 1320 | .target = resolveTargetQuery(target_query), | |
| 1321 | 1321 | .is_test = is_test, |
| 1322 | 1322 | .link_libc = link_libc, |
| 1323 | 1323 | .output = output, |
| ... | ... | @@ -1385,6 +1385,17 @@ pub fn main() !void { |
| 1385 | 1385 | return runCases(&ctx, zig_exe_path); |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | fn resolveTargetQuery(query: std.zig.CrossTarget) std.Build.ResolvedTarget { | |
| 1389 | const result = std.zig.system.NativeTargetInfo.detect(query) catch | |
| 1390 | @panic("unable to resolve target query"); | |
| 1391 | ||
| 1392 | return .{ | |
| 1393 | .query = query, | |
| 1394 | .target = result.target, | |
| 1395 | .dynamic_linker = result.dynamic_linker, | |
| 1396 | }; | |
| 1397 | } | |
| 1398 | ||
| 1388 | 1399 | fn runCases(self: *Cases, zig_exe_path: []const u8) !void { |
| 1389 | 1400 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); |
| 1390 | 1401 |
test/src/CompareOutput.zig+3-3| ... | ... | @@ -96,7 +96,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 96 | 96 | |
| 97 | 97 | const exe = b.addExecutable(.{ |
| 98 | 98 | .name = "test", |
| 99 | .target = .{}, | |
| 99 | .target = b.host, | |
| 100 | 100 | .optimize = .Debug, |
| 101 | 101 | }); |
| 102 | 102 | exe.addAssemblyFile(write_src.files.items[0].getPath()); |
| ... | ... | @@ -121,7 +121,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 121 | 121 | .name = "test", |
| 122 | 122 | .root_source_file = write_src.files.items[0].getPath(), |
| 123 | 123 | .optimize = optimize, |
| 124 | .target = .{}, | |
| 124 | .target = b.host, | |
| 125 | 125 | }); |
| 126 | 126 | if (case.link_libc) { |
| 127 | 127 | exe.linkSystemLibrary("c"); |
| ... | ... | @@ -146,7 +146,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 146 | 146 | const exe = b.addExecutable(.{ |
| 147 | 147 | .name = "test", |
| 148 | 148 | .root_source_file = write_src.files.items[0].getPath(), |
| 149 | .target = .{}, | |
| 149 | .target = b.host, | |
| 150 | 150 | .optimize = .Debug, |
| 151 | 151 | }); |
| 152 | 152 | if (case.link_libc) { |
test/src/StackTrace.zig+1-1| ... | ... | @@ -77,7 +77,7 @@ fn addExpect( |
| 77 | 77 | .name = "test", |
| 78 | 78 | .root_source_file = write_src.files.items[0].getPath(), |
| 79 | 79 | .optimize = optimize_mode, |
| 80 | .target = .{}, | |
| 80 | .target = b.host, | |
| 81 | 81 | }); |
| 82 | 82 | |
| 83 | 83 | const run = b.addRunArtifact(exe); |
test/src/run_translated_c.zig+2-2| ... | ... | @@ -11,7 +11,7 @@ pub const RunTranslatedCContext = struct { |
| 11 | 11 | step: *std.Build.Step, |
| 12 | 12 | test_index: usize, |
| 13 | 13 | test_filter: ?[]const u8, |
| 14 | target: std.zig.CrossTarget, | |
| 14 | target: std.Build.ResolvedTarget, | |
| 15 | 15 | |
| 16 | 16 | const TestCase = struct { |
| 17 | 17 | name: []const u8, |
| ... | ... | @@ -86,7 +86,7 @@ pub const RunTranslatedCContext = struct { |
| 86 | 86 | } |
| 87 | 87 | const translate_c = b.addTranslateC(.{ |
| 88 | 88 | .source_file = write_src.files.items[0].getPath(), |
| 89 | .target = .{}, | |
| 89 | .target = b.host, | |
| 90 | 90 | .optimize = .Debug, |
| 91 | 91 | }); |
| 92 | 92 |
test/src/translate_c.zig+2-2| ... | ... | @@ -18,7 +18,7 @@ pub const TranslateCContext = struct { |
| 18 | 18 | sources: ArrayList(SourceFile), |
| 19 | 19 | expected_lines: ArrayList([]const u8), |
| 20 | 20 | allow_warnings: bool, |
| 21 | target: CrossTarget = CrossTarget{}, | |
| 21 | target: CrossTarget = .{}, | |
| 22 | 22 | |
| 23 | 23 | const SourceFile = struct { |
| 24 | 24 | filename: []const u8, |
| ... | ... | @@ -109,7 +109,7 @@ pub const TranslateCContext = struct { |
| 109 | 109 | |
| 110 | 110 | const translate_c = b.addTranslateC(.{ |
| 111 | 111 | .source_file = write_src.files.items[0].getPath(), |
| 112 | .target = case.target, | |
| 112 | .target = b.resolveTargetQuery(case.target), | |
| 113 | 113 | .optimize = .Debug, |
| 114 | 114 | }); |
| 115 | 115 |
test/standalone.zig-4| ... | ... | @@ -89,10 +89,6 @@ pub const build_cases = [_]BuildCase{ |
| 89 | 89 | // .build_root = "test/standalone/issue_13970", |
| 90 | 90 | // .import = @import("standalone/issue_13970/build.zig"), |
| 91 | 91 | //}, |
| 92 | .{ | |
| 93 | .build_root = "test/standalone/main_pkg_path", | |
| 94 | .import = @import("standalone/main_pkg_path/build.zig"), | |
| 95 | }, | |
| 96 | 92 | .{ |
| 97 | 93 | .build_root = "test/standalone/shared_library", |
| 98 | 94 | .import = @import("standalone/shared_library/build.zig"), |
test/standalone/c_compiler/build.zig+2-2| ... | ... | @@ -23,7 +23,7 @@ fn add( |
| 23 | 23 | cpp_name: []const u8, |
| 24 | 24 | optimize: std.builtin.OptimizeMode, |
| 25 | 25 | ) void { |
| 26 | const target: std.zig.CrossTarget = .{}; | |
| 26 | const target = b.host; | |
| 27 | 27 | |
| 28 | 28 | const exe_c = b.addExecutable(.{ |
| 29 | 29 | .name = c_name, |
| ... | ... | @@ -42,7 +42,7 @@ fn add( |
| 42 | 42 | exe_cpp.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &[0][]const u8{} }); |
| 43 | 43 | exe_cpp.linkLibCpp(); |
| 44 | 44 | |
| 45 | switch (target.getOsTag()) { | |
| 45 | switch (target.target.os.tag) { | |
| 46 | 46 | .windows => { |
| 47 | 47 | // https://github.com/ziglang/zig/issues/8531 |
| 48 | 48 | exe_cpp.want_lto = false; |
test/standalone/child_process/build.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | b.default_step = test_step; |
| 7 | 7 | |
| 8 | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | |
| 9 | const target = b.host; | |
| 10 | 10 | |
| 11 | 11 | if (builtin.os.tag == .wasi) return; |
| 12 | 12 |
test/standalone/compiler_rt_panic/build.zig+4-4| ... | ... | @@ -4,16 +4,16 @@ pub fn build(b: *std.Build) void { |
| 4 | 4 | const test_step = b.step("test", "Test it"); |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | const target = b.standardTargetOptions(.{}); | |
| 7 | const resolved_target = b.standardTargetOptions(.{}); | |
| 8 | const target = resolved_target.target; | |
| 8 | 9 | const optimize = b.standardOptimizeOption(.{}); |
| 9 | 10 | |
| 10 | const abi = target.getAbi(); | |
| 11 | if (target.getObjectFormat() != .elf or !(abi.isMusl() or abi.isGnu())) return; | |
| 11 | if (target.ofmt != .elf or !(target.abi.isMusl() or target.abi.isGnu())) return; | |
| 12 | 12 | |
| 13 | 13 | const exe = b.addExecutable(.{ |
| 14 | 14 | .name = "main", |
| 15 | 15 | .optimize = optimize, |
| 16 | .target = target, | |
| 16 | .target = resolved_target, | |
| 17 | 17 | }); |
| 18 | 18 | exe.linkLibC(); |
| 19 | 19 | exe.addCSourceFile(.{ |
test/standalone/dep_diamond/build.zig+8-7| ... | ... | @@ -7,21 +7,22 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | 9 | const shared = b.createModule(.{ |
| 10 | .source_file = .{ .path = "shared.zig" }, | |
| 10 | .root_source_file = .{ .path = "shared.zig" }, | |
| 11 | 11 | }); |
| 12 | 12 | |
| 13 | 13 | const exe = b.addExecutable(.{ |
| 14 | 14 | .name = "test", |
| 15 | 15 | .root_source_file = .{ .path = "test.zig" }, |
| 16 | .target = b.host, | |
| 16 | 17 | .optimize = optimize, |
| 17 | 18 | }); |
| 18 | exe.addAnonymousModule("foo", .{ | |
| 19 | .source_file = .{ .path = "foo.zig" }, | |
| 20 | .dependencies = &.{.{ .name = "shared", .module = shared }}, | |
| 19 | exe.root_module.addAnonymousImport("foo", .{ | |
| 20 | .root_source_file = .{ .path = "foo.zig" }, | |
| 21 | .imports = &.{.{ .name = "shared", .module = shared }}, | |
| 21 | 22 | }); |
| 22 | exe.addAnonymousModule("bar", .{ | |
| 23 | .source_file = .{ .path = "bar.zig" }, | |
| 24 | .dependencies = &.{.{ .name = "shared", .module = shared }}, | |
| 23 | exe.root_module.addAnonymousImport("bar", .{ | |
| 24 | .root_source_file = .{ .path = "bar.zig" }, | |
| 25 | .imports = &.{.{ .name = "shared", .module = shared }}, | |
| 25 | 26 | }); |
| 26 | 27 | |
| 27 | 28 | const run = b.addRunArtifact(exe); |
test/standalone/dep_mutually_recursive/build.zig+6-5| ... | ... | @@ -7,20 +7,21 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | 9 | const foo = b.createModule(.{ |
| 10 | .source_file = .{ .path = "foo.zig" }, | |
| 10 | .root_source_file = .{ .path = "foo.zig" }, | |
| 11 | 11 | }); |
| 12 | 12 | const bar = b.createModule(.{ |
| 13 | .source_file = .{ .path = "bar.zig" }, | |
| 13 | .root_source_file = .{ .path = "bar.zig" }, | |
| 14 | 14 | }); |
| 15 | foo.dependencies.put("bar", bar) catch @panic("OOM"); | |
| 16 | bar.dependencies.put("foo", foo) catch @panic("OOM"); | |
| 15 | foo.addImport("bar", bar); | |
| 16 | bar.addImport("foo", foo); | |
| 17 | 17 | |
| 18 | 18 | const exe = b.addExecutable(.{ |
| 19 | 19 | .name = "test", |
| 20 | 20 | .root_source_file = .{ .path = "test.zig" }, |
| 21 | .target = b.host, | |
| 21 | 22 | .optimize = optimize, |
| 22 | 23 | }); |
| 23 | exe.addModule("foo", foo); | |
| 24 | exe.root_module.addImport("foo", foo); | |
| 24 | 25 | |
| 25 | 26 | const run = b.addRunArtifact(exe); |
| 26 | 27 | test_step.dependOn(&run.step); |
test/standalone/dep_recursive/build.zig+4-3| ... | ... | @@ -7,16 +7,17 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | 9 | const foo = b.createModule(.{ |
| 10 | .source_file = .{ .path = "foo.zig" }, | |
| 10 | .root_source_file = .{ .path = "foo.zig" }, | |
| 11 | 11 | }); |
| 12 | foo.dependencies.put("foo", foo) catch @panic("OOM"); | |
| 12 | foo.addImport("foo", foo); | |
| 13 | 13 | |
| 14 | 14 | const exe = b.addExecutable(.{ |
| 15 | 15 | .name = "test", |
| 16 | 16 | .root_source_file = .{ .path = "test.zig" }, |
| 17 | .target = b.host, | |
| 17 | 18 | .optimize = optimize, |
| 18 | 19 | }); |
| 19 | exe.addModule("foo", foo); | |
| 20 | exe.root_module.addImport("foo", foo); | |
| 20 | 21 | |
| 21 | 22 | const run = b.addRunArtifact(exe); |
| 22 | 23 | test_step.dependOn(&run.step); |
test/standalone/dep_shared_builtin/build.zig+3-2| ... | ... | @@ -9,10 +9,11 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | const exe = b.addExecutable(.{ |
| 10 | 10 | .name = "test", |
| 11 | 11 | .root_source_file = .{ .path = "test.zig" }, |
| 12 | .target = b.host, | |
| 12 | 13 | .optimize = optimize, |
| 13 | 14 | }); |
| 14 | exe.addAnonymousModule("foo", .{ | |
| 15 | .source_file = .{ .path = "foo.zig" }, | |
| 15 | exe.root_module.addAnonymousImport("foo", .{ | |
| 16 | .root_source_file = .{ .path = "foo.zig" }, | |
| 16 | 17 | }); |
| 17 | 18 | |
| 18 | 19 | const run = b.addRunArtifact(exe); |
test/standalone/dep_triangle/build.zig+6-5| ... | ... | @@ -7,19 +7,20 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | 9 | const shared = b.createModule(.{ |
| 10 | .source_file = .{ .path = "shared.zig" }, | |
| 10 | .root_source_file = .{ .path = "shared.zig" }, | |
| 11 | 11 | }); |
| 12 | 12 | |
| 13 | 13 | const exe = b.addExecutable(.{ |
| 14 | 14 | .name = "test", |
| 15 | 15 | .root_source_file = .{ .path = "test.zig" }, |
| 16 | .target = b.host, | |
| 16 | 17 | .optimize = optimize, |
| 17 | 18 | }); |
| 18 | exe.addAnonymousModule("foo", .{ | |
| 19 | .source_file = .{ .path = "foo.zig" }, | |
| 20 | .dependencies = &.{.{ .name = "shared", .module = shared }}, | |
| 19 | exe.root_module.addAnonymousImport("foo", .{ | |
| 20 | .root_source_file = .{ .path = "foo.zig" }, | |
| 21 | .imports = &.{.{ .name = "shared", .module = shared }}, | |
| 21 | 22 | }); |
| 22 | exe.addModule("shared", shared); | |
| 23 | exe.root_module.addImport("shared", shared); | |
| 23 | 24 | |
| 24 | 25 | const run = b.addRunArtifact(exe); |
| 25 | 26 | test_step.dependOn(&run.step); |
test/standalone/embed_generated_file/build.zig+4-4| ... | ... | @@ -7,10 +7,10 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | const bootloader = b.addExecutable(.{ |
| 8 | 8 | .name = "bootloader", |
| 9 | 9 | .root_source_file = .{ .path = "bootloader.zig" }, |
| 10 | .target = .{ | |
| 10 | .target = b.resolveTargetQuery(.{ | |
| 11 | 11 | .cpu_arch = .x86, |
| 12 | 12 | .os_tag = .freestanding, |
| 13 | }, | |
| 13 | }), | |
| 14 | 14 | .optimize = .ReleaseSmall, |
| 15 | 15 | }); |
| 16 | 16 | |
| ... | ... | @@ -18,8 +18,8 @@ pub fn build(b: *std.Build) void { |
| 18 | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 19 | 19 | .optimize = .Debug, |
| 20 | 20 | }); |
| 21 | exe.addAnonymousModule("bootloader.elf", .{ | |
| 22 | .source_file = bootloader.getEmittedBin(), | |
| 21 | exe.root_module.addAnonymousImport("bootloader.elf", .{ | |
| 22 | .root_source_file = bootloader.getEmittedBin(), | |
| 23 | 23 | }); |
| 24 | 24 | |
| 25 | 25 | // TODO: actually check the output |
test/standalone/empty_env/build.zig+1| ... | ... | @@ -15,6 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | const main = b.addExecutable(.{ |
| 16 | 16 | .name = "main", |
| 17 | 17 | .root_source_file = .{ .path = "main.zig" }, |
| 18 | .target = b.host, | |
| 18 | 19 | .optimize = optimize, |
| 19 | 20 | }); |
| 20 | 21 |
test/standalone/extern/build.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | const obj = b.addObject(.{ |
| 7 | 7 | .name = "exports", |
| 8 | 8 | .root_source_file = .{ .path = "exports.zig" }, |
| 9 | .target = .{}, | |
| 9 | .target = b.host, | |
| 10 | 10 | .optimize = optimize, |
| 11 | 11 | }); |
| 12 | 12 | const main = b.addTest(.{ |
test/standalone/global_linkage/build.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | |
| 8 | const target = b.host; | |
| 9 | 9 | |
| 10 | 10 | const obj1 = b.addStaticLibrary(.{ |
| 11 | 11 | .name = "obj1", |
test/standalone/install_raw_hex/build.zig+2-2| ... | ... | @@ -5,12 +5,12 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | const test_step = b.step("test", "Test it"); |
| 6 | 6 | b.default_step = test_step; |
| 7 | 7 | |
| 8 | const target = .{ | |
| 8 | const target = b.resolveTargetQuery(.{ | |
| 9 | 9 | .cpu_arch = .thumb, |
| 10 | 10 | .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 }, |
| 11 | 11 | .os_tag = .freestanding, |
| 12 | 12 | .abi = .gnueabihf, |
| 13 | }; | |
| 13 | }); | |
| 14 | 14 | |
| 15 | 15 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 16 | 16 |
test/standalone/ios/build.zig+4-4| ... | ... | @@ -8,12 +8,12 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | b.default_step = test_step; |
| 9 | 9 | |
| 10 | 10 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 11 | const target: std.zig.CrossTarget = .{ | |
| 11 | const target = b.resolveTargetQuery(.{ | |
| 12 | 12 | .cpu_arch = .aarch64, |
| 13 | 13 | .os_tag = .ios, |
| 14 | }; | |
| 15 | const target_info = std.zig.system.NativeTargetInfo.detect(target) catch @panic("couldn't detect native target"); | |
| 16 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target_info.target) orelse @panic("no iOS SDK found"); | |
| 14 | }); | |
| 15 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.target) orelse | |
| 16 | @panic("no iOS SDK found"); | |
| 17 | 17 | b.sysroot = sdk; |
| 18 | 18 | |
| 19 | 19 | const exe = b.addExecutable(.{ |
test/standalone/issue_11595/build.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | b.default_step = test_step; |
| 7 | 7 | |
| 8 | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | |
| 9 | const target = b.host; | |
| 10 | 10 | |
| 11 | 11 | if (builtin.os.tag == .windows) { |
| 12 | 12 | // https://github.com/ziglang/zig/issues/12419 |
test/standalone/issue_12588/build.zig+1-2| ... | ... | @@ -5,13 +5,12 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | |
| 9 | 8 | |
| 10 | 9 | const obj = b.addObject(.{ |
| 11 | 10 | .name = "main", |
| 12 | 11 | .root_source_file = .{ .path = "main.zig" }, |
| 13 | 12 | .optimize = optimize, |
| 14 | .target = target, | |
| 13 | .target = b.host, | |
| 15 | 14 | }); |
| 16 | 15 | _ = obj.getEmittedLlvmIr(); |
| 17 | 16 | _ = obj.getEmittedLlvmBc(); |
test/standalone/issue_12706/build.zig+1-2| ... | ... | @@ -1,13 +1,12 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const CrossTarget = std.zig.CrossTarget; | |
| 4 | 3 | |
| 5 | 4 | pub fn build(b: *std.Build) void { |
| 6 | 5 | const test_step = b.step("test", "Test it"); |
| 7 | 6 | b.default_step = test_step; |
| 8 | 7 | |
| 9 | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 10 | const target: std.zig.CrossTarget = .{}; | |
| 9 | const target = b.host; | |
| 11 | 10 | |
| 12 | 11 | const exe = b.addExecutable(.{ |
| 13 | 12 | .name = "main", |
test/standalone/issue_339/build.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | |
| 8 | const target = b.host; | |
| 9 | 9 | |
| 10 | 10 | const obj = b.addObject(.{ |
| 11 | 11 | .name = "test", |
test/standalone/issue_8550/build.zig+2-2| ... | ... | @@ -5,13 +5,13 @@ pub fn build(b: *std.Build) !void { |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target = std.zig.CrossTarget{ | |
| 8 | const target = b.resolveTargetQuery(.{ | |
| 9 | 9 | .os_tag = .freestanding, |
| 10 | 10 | .cpu_arch = .arm, |
| 11 | 11 | .cpu_model = .{ |
| 12 | 12 | .explicit = &std.Target.arm.cpu.arm1176jz_s, |
| 13 | 13 | }, |
| 14 | }; | |
| 14 | }); | |
| 15 | 15 | |
| 16 | 16 | const kernel = b.addExecutable(.{ |
| 17 | 17 | .name = "kernel", |
test/standalone/load_dynamic_library/build.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | b.default_step = test_step; |
| 7 | 7 | |
| 8 | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | |
| 9 | const target = b.host; | |
| 10 | 10 | |
| 11 | 11 | if (builtin.os.tag == .wasi) return; |
| 12 | 12 |
test/standalone/main_pkg_path/a/test.zig deleted-5| ... | ... | @@ -1,5 +0,0 @@ |
| 1 | const b = @import("../b.zig"); | |
| 2 | ||
| 3 | test "main pkg path" { | |
| 4 | b.foo(); | |
| 5 | } |
test/standalone/main_pkg_path/b.zig deleted-1| ... | ... | @@ -1 +0,0 @@ |
| 1 | pub fn foo() void {} |
test/standalone/main_pkg_path/build.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn build(b: *std.Build) void { | |
| 4 | const test_step = b.step("test", "Test it"); | |
| 5 | b.default_step = test_step; | |
| 6 | ||
| 7 | const test_exe = b.addTest(.{ | |
| 8 | .root_source_file = .{ .path = "a/test.zig" }, | |
| 9 | .main_pkg_path = .{ .path = "." }, | |
| 10 | }); | |
| 11 | ||
| 12 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | |
| 13 | } |
test/standalone/mix_c_files/build.zig+1| ... | ... | @@ -19,6 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 19 | 19 | const exe = b.addExecutable(.{ |
| 20 | 20 | .name = "test", |
| 21 | 21 | .root_source_file = .{ .path = "main.zig" }, |
| 22 | .target = b.host, | |
| 22 | 23 | .optimize = optimize, |
| 23 | 24 | }); |
| 24 | 25 | exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &[_][]const u8{"-std=c11"} }); |
test/standalone/mix_o_files/build.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | |
| 8 | const target = b.host; | |
| 9 | 9 | |
| 10 | 10 | const obj = b.addObject(.{ |
| 11 | 11 | .name = "base64", |
test/standalone/options/build.zig+1-1| ... | ... | @@ -3,7 +3,7 @@ const std = @import("std"); |
| 3 | 3 | pub fn build(b: *std.Build) void { |
| 4 | 4 | const main = b.addTest(.{ |
| 5 | 5 | .root_source_file = .{ .path = "src/main.zig" }, |
| 6 | .target = .{}, | |
| 6 | .target = b.host, | |
| 7 | 7 | .optimize = .Debug, |
| 8 | 8 | }); |
| 9 | 9 |
test/standalone/pie/build.zig+2-2| ... | ... | @@ -5,10 +5,10 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{ | |
| 8 | const target = b.resolveTargetQuery(.{ | |
| 9 | 9 | .os_tag = .linux, |
| 10 | 10 | .cpu_arch = .x86_64, |
| 11 | }; | |
| 11 | }); | |
| 12 | 12 | |
| 13 | 13 | const main = b.addTest(.{ |
| 14 | 14 | .root_source_file = .{ .path = "main.zig" }, |
test/standalone/pkg_import/build.zig+2-1| ... | ... | @@ -10,8 +10,9 @@ pub fn build(b: *std.Build) void { |
| 10 | 10 | .name = "test", |
| 11 | 11 | .root_source_file = .{ .path = "test.zig" }, |
| 12 | 12 | .optimize = optimize, |
| 13 | .target = b.host, | |
| 13 | 14 | }); |
| 14 | exe.addAnonymousModule("my_pkg", .{ .source_file = .{ .path = "pkg.zig" } }); | |
| 15 | exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = .{ .path = "pkg.zig" } }); | |
| 15 | 16 | |
| 16 | 17 | const run = b.addRunArtifact(exe); |
| 17 | 18 | test_step.dependOn(&run.step); |
test/standalone/self_exe_symlink/build.zig+2-2| ... | ... | @@ -7,11 +7,11 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | b.default_step = test_step; |
| 8 | 8 | |
| 9 | 9 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 10 | const target: std.zig.CrossTarget = .{}; | |
| 10 | const target = b.host; | |
| 11 | 11 | |
| 12 | 12 | // The test requires getFdPath in order to to get the path of the |
| 13 | 13 | // File returned by openSelfExe |
| 14 | if (!std.os.isGetFdPathSupportedOnTarget(target.getOs())) return; | |
| 14 | if (!std.os.isGetFdPathSupportedOnTarget(target.target.os)) return; | |
| 15 | 15 | |
| 16 | 16 | const main = b.addExecutable(.{ |
| 17 | 17 | .name = "main", |
test/standalone/shared_library/build.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void { |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 13 | const target: std.zig.CrossTarget = .{}; | |
| 13 | const target = b.host; | |
| 14 | 14 | const lib = b.addSharedLibrary(.{ |
| 15 | 15 | .name = "mathtest", |
| 16 | 16 | .root_source_file = .{ .path = "mathtest.zig" }, |
test/standalone/stack_iterator/build.zig+9-10| ... | ... | @@ -22,11 +22,10 @@ pub fn build(b: *std.Build) void { |
| 22 | 22 | .root_source_file = .{ .path = "unwind.zig" }, |
| 23 | 23 | .target = target, |
| 24 | 24 | .optimize = optimize, |
| 25 | .unwind_tables = target.target.isDarwin(), | |
| 26 | .omit_frame_pointer = false, | |
| 25 | 27 | }); |
| 26 | 28 | |
| 27 | if (target.isDarwin()) exe.unwind_tables = true; | |
| 28 | exe.omit_frame_pointer = false; | |
| 29 | ||
| 30 | 29 | const run_cmd = b.addRunArtifact(exe); |
| 31 | 30 | test_step.dependOn(&run_cmd.step); |
| 32 | 31 | } |
| ... | ... | @@ -46,11 +45,10 @@ pub fn build(b: *std.Build) void { |
| 46 | 45 | .root_source_file = .{ .path = "unwind.zig" }, |
| 47 | 46 | .target = target, |
| 48 | 47 | .optimize = optimize, |
| 48 | .unwind_tables = true, | |
| 49 | .omit_frame_pointer = true, | |
| 49 | 50 | }); |
| 50 | 51 | |
| 51 | exe.omit_frame_pointer = true; | |
| 52 | exe.unwind_tables = true; | |
| 53 | ||
| 54 | 52 | const run_cmd = b.addRunArtifact(exe); |
| 55 | 53 | test_step.dependOn(&run_cmd.step); |
| 56 | 54 | } |
| ... | ... | @@ -69,11 +67,12 @@ pub fn build(b: *std.Build) void { |
| 69 | 67 | .name = "c_shared_lib", |
| 70 | 68 | .target = target, |
| 71 | 69 | .optimize = optimize, |
| 70 | .strip = false, | |
| 72 | 71 | }); |
| 73 | 72 | |
| 74 | if (target.isWindows()) c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)"); | |
| 73 | if (target.target.os.tag == .windows) | |
| 74 | c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)"); | |
| 75 | 75 | |
| 76 | c_shared_lib.strip = false; | |
| 77 | 76 | c_shared_lib.addCSourceFile(.{ |
| 78 | 77 | .file = .{ .path = "shared_lib.c" }, |
| 79 | 78 | .flags = &.{"-fomit-frame-pointer"}, |
| ... | ... | @@ -85,10 +84,10 @@ pub fn build(b: *std.Build) void { |
| 85 | 84 | .root_source_file = .{ .path = "shared_lib_unwind.zig" }, |
| 86 | 85 | .target = target, |
| 87 | 86 | .optimize = optimize, |
| 87 | .unwind_tables = target.target.isDarwin(), | |
| 88 | .omit_frame_pointer = true, | |
| 88 | 89 | }); |
| 89 | 90 | |
| 90 | if (target.isDarwin()) exe.unwind_tables = true; | |
| 91 | exe.omit_frame_pointer = true; | |
| 92 | 91 | exe.linkLibrary(c_shared_lib); |
| 93 | 92 | |
| 94 | 93 | const run_cmd = b.addRunArtifact(exe); |
test/standalone/static_c_lib/build.zig+1-1| ... | ... | @@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | const foo = b.addStaticLibrary(.{ |
| 10 | 10 | .name = "foo", |
| 11 | 11 | .optimize = optimize, |
| 12 | .target = .{}, | |
| 12 | .target = b.host, | |
| 13 | 13 | }); |
| 14 | 14 | foo.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &[_][]const u8{} }); |
| 15 | 15 | foo.addIncludePath(.{ .path = "." }); |
test/standalone/strip_empty_loop/build.zig+2-2| ... | ... | @@ -5,15 +5,15 @@ pub fn build(b: *std.Build) void { |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 7 | const optimize = std.builtin.OptimizeMode.Debug; |
| 8 | const target = std.zig.CrossTarget{}; | |
| 8 | const target = b.host; | |
| 9 | 9 | |
| 10 | 10 | const main = b.addExecutable(.{ |
| 11 | 11 | .name = "main", |
| 12 | 12 | .root_source_file = .{ .path = "main.zig" }, |
| 13 | 13 | .optimize = optimize, |
| 14 | 14 | .target = target, |
| 15 | .strip = true, | |
| 15 | 16 | }); |
| 16 | main.strip = true; | |
| 17 | 17 | |
| 18 | 18 | // TODO: actually check the output |
| 19 | 19 | _ = main.getEmittedBin(); |
test/standalone/strip_struct_init/build.zig+1-1| ... | ... | @@ -9,8 +9,8 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | const main = b.addTest(.{ |
| 10 | 10 | .root_source_file = .{ .path = "main.zig" }, |
| 11 | 11 | .optimize = optimize, |
| 12 | .strip = true, | |
| 12 | 13 | }); |
| 13 | main.strip = true; | |
| 14 | 14 | |
| 15 | 15 | test_step.dependOn(&b.addRunArtifact(main).step); |
| 16 | 16 | } |
test/standalone/test_runner_module_imports/build.zig+4-4| ... | ... | @@ -6,13 +6,13 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | .test_runner = "test_runner/main.zig", |
| 7 | 7 | }); |
| 8 | 8 | |
| 9 | const module1 = b.createModule(.{ .source_file = .{ .path = "module1/main.zig" } }); | |
| 9 | const module1 = b.createModule(.{ .root_source_file = .{ .path = "module1/main.zig" } }); | |
| 10 | 10 | const module2 = b.createModule(.{ |
| 11 | .source_file = .{ .path = "module2/main.zig" }, | |
| 12 | .dependencies = &.{.{ .name = "module1", .module = module1 }}, | |
| 11 | .root_source_file = .{ .path = "module2/main.zig" }, | |
| 12 | .imports = &.{.{ .name = "module1", .module = module1 }}, | |
| 13 | 13 | }); |
| 14 | 14 | |
| 15 | t.addModule("module2", module2); | |
| 15 | t.root_module.addImport("module2", module2); | |
| 16 | 16 | |
| 17 | 17 | const test_step = b.step("test", "Run unit tests"); |
| 18 | 18 | test_step.dependOn(&b.addRunArtifact(t).step); |
test/standalone/windows_resources/build.zig+10-6| ... | ... | @@ -4,21 +4,25 @@ pub fn build(b: *std.Build) void { |
| 4 | 4 | const test_step = b.step("test", "Test it"); |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | const native_target: std.zig.CrossTarget = .{}; | |
| 8 | const cross_target = .{ | |
| 7 | const cross_target = b.resolveTargetQuery(.{ | |
| 9 | 8 | .cpu_arch = .x86_64, |
| 10 | 9 | .os_tag = .windows, |
| 11 | 10 | .abi = .gnu, |
| 12 | }; | |
| 11 | }); | |
| 13 | 12 | |
| 14 | add(b, native_target, .any, test_step); | |
| 13 | add(b, b.host, .any, test_step); | |
| 15 | 14 | add(b, cross_target, .any, test_step); |
| 16 | 15 | |
| 17 | add(b, native_target, .gnu, test_step); | |
| 16 | add(b, b.host, .gnu, test_step); | |
| 18 | 17 | add(b, cross_target, .gnu, test_step); |
| 19 | 18 | } |
| 20 | 19 | |
| 21 | fn add(b: *std.Build, target: std.zig.CrossTarget, rc_includes: enum { any, gnu }, test_step: *std.Build.Step) void { | |
| 20 | fn add( | |
| 21 | b: *std.Build, | |
| 22 | target: std.Build.ResolvedTarget, | |
| 23 | rc_includes: enum { any, gnu }, | |
| 24 | test_step: *std.Build.Step, | |
| 25 | ) void { | |
| 22 | 26 | const exe = b.addExecutable(.{ |
| 23 | 27 | .name = "zig_resource_test", |
| 24 | 28 | .root_source_file = .{ .path = "main.zig" }, |
test/standalone/windows_spawn/build.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | b.default_step = test_step; |
| 7 | 7 | |
| 8 | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | |
| 9 | const target = b.host; | |
| 10 | 10 | |
| 11 | 11 | if (builtin.os.tag != .windows) return; |
| 12 | 12 |
test/standalone/zerolength_check/build.zig+2-2| ... | ... | @@ -13,11 +13,11 @@ pub fn build(b: *std.Build) void { |
| 13 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const unit_tests = b.addTest(.{ |
| 15 | 15 | .root_source_file = .{ .path = "src/main.zig" }, |
| 16 | .target = .{ | |
| 16 | .target = b.resolveTargetQuery(.{ | |
| 17 | 17 | .os_tag = .wasi, |
| 18 | 18 | .cpu_arch = .wasm32, |
| 19 | 19 | .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}), |
| 20 | }, | |
| 20 | }), | |
| 21 | 21 | .optimize = optimize, |
| 22 | 22 | }); |
| 23 | 23 |
test/tests.zig+34-35| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const CrossTarget = std.zig.CrossTarget; | |
| 5 | 4 | const mem = std.mem; |
| 6 | 5 | const OptimizeMode = std.builtin.OptimizeMode; |
| 7 | 6 | const Step = std.Build.Step; |
| ... | ... | @@ -22,13 +21,13 @@ pub const CompareOutputContext = @import("src/CompareOutput.zig"); |
| 22 | 21 | pub const StackTracesContext = @import("src/StackTrace.zig"); |
| 23 | 22 | |
| 24 | 23 | const TestTarget = struct { |
| 25 | target: CrossTarget = .{}, | |
| 24 | target: std.zig.CrossTarget = .{}, | |
| 26 | 25 | optimize_mode: std.builtin.OptimizeMode = .Debug, |
| 27 | 26 | link_libc: ?bool = null, |
| 28 | 27 | single_threaded: ?bool = null, |
| 29 | 28 | use_llvm: ?bool = null, |
| 30 | 29 | use_lld: ?bool = null, |
| 31 | force_pic: ?bool = null, | |
| 30 | pic: ?bool = null, | |
| 32 | 31 | strip: ?bool = null, |
| 33 | 32 | }; |
| 34 | 33 | |
| ... | ... | @@ -105,7 +104,7 @@ const test_targets = blk: { |
| 105 | 104 | }, |
| 106 | 105 | .use_llvm = false, |
| 107 | 106 | .use_lld = false, |
| 108 | .force_pic = true, | |
| 107 | .pic = true, | |
| 109 | 108 | }, |
| 110 | 109 | .{ |
| 111 | 110 | .target = .{ |
| ... | ... | @@ -146,7 +145,7 @@ const test_targets = blk: { |
| 146 | 145 | //}, |
| 147 | 146 | // https://github.com/ziglang/zig/issues/13623 |
| 148 | 147 | //.{ |
| 149 | // .target = CrossTarget.parse(.{ | |
| 148 | // .target = std.zig.CrossTarget.parse(.{ | |
| 150 | 149 | // .arch_os_abi = "arm-linux-none", |
| 151 | 150 | // .cpu_features = "generic+v8a", |
| 152 | 151 | // }) catch unreachable, |
| ... | ... | @@ -287,13 +286,13 @@ const test_targets = blk: { |
| 287 | 286 | }, |
| 288 | 287 | |
| 289 | 288 | .{ |
| 290 | .target = CrossTarget.parse(.{ | |
| 289 | .target = std.zig.CrossTarget.parse(.{ | |
| 291 | 290 | .arch_os_abi = "arm-linux-none", |
| 292 | 291 | .cpu_features = "generic+v8a", |
| 293 | 292 | }) catch unreachable, |
| 294 | 293 | }, |
| 295 | 294 | .{ |
| 296 | .target = CrossTarget.parse(.{ | |
| 295 | .target = std.zig.CrossTarget.parse(.{ | |
| 297 | 296 | .arch_os_abi = "arm-linux-musleabihf", |
| 298 | 297 | .cpu_features = "generic+v8a", |
| 299 | 298 | }) catch unreachable, |
| ... | ... | @@ -301,7 +300,7 @@ const test_targets = blk: { |
| 301 | 300 | }, |
| 302 | 301 | // https://github.com/ziglang/zig/issues/3287 |
| 303 | 302 | //.{ |
| 304 | // .target = CrossTarget.parse(.{ | |
| 303 | // .target = std.zig.CrossTarget.parse(.{ | |
| 305 | 304 | // .arch_os_abi = "arm-linux-gnueabihf", |
| 306 | 305 | // .cpu_features = "generic+v8a", |
| 307 | 306 | // }) catch unreachable, |
| ... | ... | @@ -495,10 +494,10 @@ const test_targets = blk: { |
| 495 | 494 | }; |
| 496 | 495 | |
| 497 | 496 | const CAbiTarget = struct { |
| 498 | target: CrossTarget = .{}, | |
| 497 | target: std.zig.CrossTarget = .{}, | |
| 499 | 498 | use_llvm: ?bool = null, |
| 500 | 499 | use_lld: ?bool = null, |
| 501 | force_pic: ?bool = null, | |
| 500 | pic: ?bool = null, | |
| 502 | 501 | strip: ?bool = null, |
| 503 | 502 | c_defines: []const []const u8 = &.{}, |
| 504 | 503 | }; |
| ... | ... | @@ -543,7 +542,7 @@ const c_abi_targets = [_]CAbiTarget{ |
| 543 | 542 | }, |
| 544 | 543 | .use_llvm = false, |
| 545 | 544 | .use_lld = false, |
| 546 | .force_pic = true, | |
| 545 | .pic = true, | |
| 547 | 546 | .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"}, |
| 548 | 547 | }, |
| 549 | 548 | .{ |
| ... | ... | @@ -645,7 +644,7 @@ pub fn addStackTraceTests( |
| 645 | 644 | const check_exe = b.addExecutable(.{ |
| 646 | 645 | .name = "check-stack-trace", |
| 647 | 646 | .root_source_file = .{ .path = "test/src/check-stack-trace.zig" }, |
| 648 | .target = .{}, | |
| 647 | .target = b.host, | |
| 649 | 648 | .optimize = .Debug, |
| 650 | 649 | }); |
| 651 | 650 | |
| ... | ... | @@ -682,12 +681,14 @@ pub fn addStandaloneTests( |
| 682 | 681 | if (os_tag != builtin.os.tag) continue; |
| 683 | 682 | } |
| 684 | 683 | |
| 684 | const resolved_target = b.resolveTargetQuery(case.target); | |
| 685 | ||
| 685 | 686 | if (case.is_exe) { |
| 686 | 687 | const exe = b.addExecutable(.{ |
| 687 | 688 | .name = std.fs.path.stem(case.src_path), |
| 688 | 689 | .root_source_file = .{ .path = case.src_path }, |
| 689 | 690 | .optimize = optimize, |
| 690 | .target = case.target, | |
| 691 | .target = resolved_target, | |
| 691 | 692 | }); |
| 692 | 693 | if (case.link_libc) exe.linkLibC(); |
| 693 | 694 | |
| ... | ... | @@ -701,7 +702,7 @@ pub fn addStandaloneTests( |
| 701 | 702 | .name = std.fs.path.stem(case.src_path), |
| 702 | 703 | .root_source_file = .{ .path = case.src_path }, |
| 703 | 704 | .optimize = optimize, |
| 704 | .target = case.target, | |
| 705 | .target = resolved_target, | |
| 705 | 706 | }); |
| 706 | 707 | if (case.link_libc) exe.linkLibC(); |
| 707 | 708 | |
| ... | ... | @@ -1001,7 +1002,7 @@ pub fn addTranslateCTests(b: *std.Build, test_filter: ?[]const u8) *Step { |
| 1001 | 1002 | pub fn addRunTranslatedCTests( |
| 1002 | 1003 | b: *std.Build, |
| 1003 | 1004 | test_filter: ?[]const u8, |
| 1004 | target: std.zig.CrossTarget, | |
| 1005 | target: std.Build.ResolvedTarget, | |
| 1005 | 1006 | ) *Step { |
| 1006 | 1007 | const cases = b.allocator.create(RunTranslatedCContext) catch @panic("OOM"); |
| 1007 | 1008 | cases.* = .{ |
| ... | ... | @@ -1105,7 +1106,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1105 | 1106 | const these_tests = b.addTest(.{ |
| 1106 | 1107 | .root_source_file = .{ .path = options.root_src }, |
| 1107 | 1108 | .optimize = test_target.optimize_mode, |
| 1108 | .target = test_target.target, | |
| 1109 | .target = b.resolveTargetQuery(test_target.target), | |
| 1109 | 1110 | .max_rss = max_rss, |
| 1110 | 1111 | .filter = options.test_filter, |
| 1111 | 1112 | .link_libc = test_target.link_libc, |
| ... | ... | @@ -1113,9 +1114,9 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1113 | 1114 | .use_llvm = test_target.use_llvm, |
| 1114 | 1115 | .use_lld = test_target.use_lld, |
| 1115 | 1116 | .zig_lib_dir = .{ .path = "lib" }, |
| 1117 | .pic = test_target.pic, | |
| 1118 | .strip = test_target.strip, | |
| 1116 | 1119 | }); |
| 1117 | these_tests.force_pic = test_target.force_pic; | |
| 1118 | these_tests.strip = test_target.strip; | |
| 1119 | 1120 | const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else ""; |
| 1120 | 1121 | const backend_suffix = if (test_target.use_llvm == true) |
| 1121 | 1122 | "-llvm" |
| ... | ... | @@ -1126,7 +1127,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1126 | 1127 | else |
| 1127 | 1128 | ""; |
| 1128 | 1129 | const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; |
| 1129 | const use_pic = if (test_target.force_pic == true) "-pic" else ""; | |
| 1130 | const use_pic = if (test_target.pic == true) "-pic" else ""; | |
| 1130 | 1131 | |
| 1131 | 1132 | these_tests.addIncludePath(.{ .path = "test" }); |
| 1132 | 1133 | |
| ... | ... | @@ -1154,7 +1155,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1154 | 1155 | const compile_c = b.addExecutable(.{ |
| 1155 | 1156 | .name = qualified_name, |
| 1156 | 1157 | .link_libc = test_target.link_libc, |
| 1157 | .target = altered_target, | |
| 1158 | .target = b.resolveTargetQuery(altered_target), | |
| 1158 | 1159 | .zig_lib_dir = .{ .path = "lib" }, |
| 1159 | 1160 | }); |
| 1160 | 1161 | compile_c.addCSourceFile(.{ |
| ... | ... | @@ -1229,41 +1230,39 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S |
| 1229 | 1230 | for (c_abi_targets) |c_abi_target| { |
| 1230 | 1231 | if (skip_non_native and !c_abi_target.target.isNative()) continue; |
| 1231 | 1232 | |
| 1232 | if (c_abi_target.target.isWindows() and c_abi_target.target.getCpuArch() == .aarch64) { | |
| 1233 | const resolved_target = b.resolveTargetQuery(c_abi_target.target); | |
| 1234 | const target = resolved_target.target; | |
| 1235 | ||
| 1236 | if (target.os.tag == .windows and target.cpu.arch == .aarch64) { | |
| 1233 | 1237 | // https://github.com/ziglang/zig/issues/14908 |
| 1234 | 1238 | continue; |
| 1235 | 1239 | } |
| 1236 | 1240 | |
| 1237 | 1241 | const test_step = b.addTest(.{ |
| 1238 | 1242 | .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{ |
| 1239 | c_abi_target.target.zigTriple(b.allocator) catch @panic("OOM"), | |
| 1240 | c_abi_target.target.getCpuModel().name, | |
| 1243 | target.zigTriple(b.allocator) catch @panic("OOM"), | |
| 1244 | target.cpu.model.name, | |
| 1241 | 1245 | @tagName(optimize_mode), |
| 1242 | 1246 | if (c_abi_target.use_llvm == true) |
| 1243 | 1247 | "-llvm" |
| 1244 | else if (c_abi_target.target.ofmt == std.Target.ObjectFormat.c) | |
| 1248 | else if (target.ofmt == .c) | |
| 1245 | 1249 | "-cbe" |
| 1246 | 1250 | else if (c_abi_target.use_llvm == false) |
| 1247 | 1251 | "-selfhosted" |
| 1248 | 1252 | else |
| 1249 | 1253 | "", |
| 1250 | 1254 | if (c_abi_target.use_lld == false) "-no-lld" else "", |
| 1251 | if (c_abi_target.force_pic == true) "-pic" else "", | |
| 1255 | if (c_abi_target.pic == true) "-pic" else "", | |
| 1252 | 1256 | }), |
| 1253 | 1257 | .root_source_file = .{ .path = "test/c_abi/main.zig" }, |
| 1254 | .target = c_abi_target.target, | |
| 1258 | .target = resolved_target, | |
| 1255 | 1259 | .optimize = optimize_mode, |
| 1256 | 1260 | .link_libc = true, |
| 1257 | 1261 | .use_llvm = c_abi_target.use_llvm, |
| 1258 | 1262 | .use_lld = c_abi_target.use_lld, |
| 1263 | .pic = c_abi_target.pic, | |
| 1264 | .strip = c_abi_target.strip, | |
| 1259 | 1265 | }); |
| 1260 | test_step.force_pic = c_abi_target.force_pic; | |
| 1261 | test_step.strip = c_abi_target.strip; | |
| 1262 | if (c_abi_target.target.abi != null and c_abi_target.target.abi.?.isMusl()) { | |
| 1263 | // TODO NativeTargetInfo insists on dynamically linking musl | |
| 1264 | // for some reason? | |
| 1265 | test_step.target_info.dynamic_linker.max_byte = null; | |
| 1266 | } | |
| 1267 | 1266 | test_step.addCSourceFile(.{ |
| 1268 | 1267 | .file = .{ .path = "test/c_abi/cfuncs.c" }, |
| 1269 | 1268 | .flags = &.{"-std=c99"}, |
| ... | ... | @@ -1297,8 +1296,8 @@ pub fn addCases( |
| 1297 | 1296 | var dir = try b.build_root.handle.openDir("test/cases", .{ .iterate = true }); |
| 1298 | 1297 | defer dir.close(); |
| 1299 | 1298 | |
| 1300 | cases.addFromDir(dir); | |
| 1301 | try @import("cases.zig").addCases(&cases, build_options); | |
| 1299 | cases.addFromDir(dir, b); | |
| 1300 | try @import("cases.zig").addCases(&cases, build_options, b); | |
| 1302 | 1301 | |
| 1303 | 1302 | const cases_dir_path = try b.build_root.join(b.allocator, &.{ "test", "cases" }); |
| 1304 | 1303 | cases.lowerToBuildSteps( |