Skip to content

Commit 1b27146

Browse files
authored
Merge pull request #18590 from castholm/move-standalone-test-cases
std.Build: Remove `anonymousDependency`
2 parents 09f1bbe + e5bf1a5 commit 1b27146

24 files changed

+546
-496
lines changed

build.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,10 @@ pub fn build(b: *std.Build) !void {
521521
optimization_modes,
522522
enable_macos_sdk,
523523
enable_ios_sdk,
524-
false,
525524
enable_symlinks_windows,
526525
));
527526
test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release));
528-
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, false, enable_symlinks_windows));
527+
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows));
529528
test_step.dependOn(tests.addStackTraceTests(b, test_filters, optimization_modes));
530529
test_step.dependOn(tests.addCliTests(b));
531530
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes));

build.zig.zon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// The Zig compiler is not intended to be consumed as a package.
2+
// The sole purpose of this manifest file is to test the compiler.
3+
.{
4+
.name = "zig",
5+
.version = "0.0.0",
6+
.dependencies = .{
7+
.standalone_test_cases = .{
8+
.path = "test/standalone",
9+
},
10+
.link_test_cases = .{
11+
.path = "test/link",
12+
},
13+
},
14+
.paths = .{""},
15+
}

lib/std/Build.zig

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,25 +1967,6 @@ pub fn dependencyFromBuildZig(
19671967
debug.panic("'{}' is not a build.zig struct of a dependecy in '{s}'", .{ build_zig, full_path });
19681968
}
19691969

1970-
pub fn anonymousDependency(
1971-
b: *Build,
1972-
/// The path to the directory containing the dependency's build.zig file,
1973-
/// relative to the current package's build.zig.
1974-
relative_build_root: []const u8,
1975-
/// A direct `@import` of the build.zig of the dependency.
1976-
comptime build_zig: type,
1977-
args: anytype,
1978-
) *Dependency {
1979-
const arena = b.allocator;
1980-
const build_root = b.build_root.join(arena, &.{relative_build_root}) catch @panic("OOM");
1981-
const name = arena.dupe(u8, relative_build_root) catch @panic("OOM");
1982-
for (name) |*byte| switch (byte.*) {
1983-
'/', '\\' => byte.* = '.',
1984-
else => continue,
1985-
};
1986-
return dependencyInner(b, name, build_root, build_zig, "anonymous", &.{}, args);
1987-
}
1988-
19891970
fn userValuesAreSame(lhs: UserValue, rhs: UserValue) bool {
19901971
switch (lhs) {
19911972
.flag => {},
@@ -2033,7 +2014,7 @@ fn userValuesAreSame(lhs: UserValue, rhs: UserValue) bool {
20332014
return true;
20342015
}
20352016

2036-
pub fn dependencyInner(
2017+
fn dependencyInner(
20372018
b: *Build,
20382019
name: []const u8,
20392020
build_root_string: []const u8,

test/link.zig

Lines changed: 0 additions & 94 deletions
This file was deleted.

test/link/build.zig

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const std = @import("std");
2+
const builtin = @import("builtin");
3+
const link = @import("link.zig");
4+
5+
pub fn build(b: *std.Build) void {
6+
const step = b.step("test", "Run link test cases");
7+
b.default_step = step;
8+
9+
const enable_ios_sdk = b.option(bool, "enable_ios_sdk", "Run tests requiring presence of iOS SDK and frameworks") orelse false;
10+
const enable_macos_sdk = b.option(bool, "enable_macos_sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse enable_ios_sdk;
11+
const enable_symlinks_windows = b.option(bool, "enable_symlinks_windows", "Run tests requiring presence of symlinks on Windows") orelse false;
12+
const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
13+
14+
const build_opts: link.BuildOptions = .{
15+
.has_ios_sdk = enable_ios_sdk,
16+
.has_macos_sdk = enable_macos_sdk,
17+
.has_symlinks_windows = omit_symlinks,
18+
};
19+
step.dependOn(@import("elf.zig").testAll(b, build_opts));
20+
step.dependOn(@import("macho.zig").testAll(b, build_opts));
21+
22+
add_dep_steps: for (b.available_deps) |available_dep| {
23+
const dep_name, const dep_hash = available_dep;
24+
25+
const all_pkgs = @import("root").dependencies.packages;
26+
inline for (@typeInfo(all_pkgs).Struct.decls) |decl| {
27+
const pkg_hash = decl.name;
28+
if (std.mem.eql(u8, dep_hash, pkg_hash)) {
29+
const pkg = @field(all_pkgs, pkg_hash);
30+
if (!@hasDecl(pkg, "build_zig")) {
31+
std.debug.panic("link test case '{s}' is missing a 'build.zig' file", .{dep_name});
32+
}
33+
const requires_ios_sdk = @hasDecl(pkg.build_zig, "requires_ios_sdk") and
34+
pkg.build_zig.requires_ios_sdk;
35+
const requires_macos_sdk = @hasDecl(pkg.build_zig, "requires_macos_sdk") and
36+
pkg.build_zig.requires_macos_sdk;
37+
const requires_symlinks = @hasDecl(pkg.build_zig, "requires_symlinks") and
38+
pkg.build_zig.requires_symlinks;
39+
if ((requires_symlinks and omit_symlinks) or
40+
(requires_macos_sdk and !enable_macos_sdk) or
41+
(requires_ios_sdk and !enable_ios_sdk))
42+
{
43+
continue :add_dep_steps;
44+
}
45+
break;
46+
}
47+
} else unreachable;
48+
49+
const dep = b.dependency(dep_name, .{});
50+
const dep_step = dep.builder.default_step;
51+
dep_step.name = b.fmt("link_test_cases.{s}", .{dep_name});
52+
step.dependOn(dep_step);
53+
}
54+
}

test/link/build.zig.zon

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.{
2+
.name = "link_test_cases",
3+
.version = "0.0.0",
4+
.dependencies = .{
5+
.bss = .{
6+
.path = "bss",
7+
},
8+
.common_symbols_alignment = .{
9+
.path = "common_symbols_alignment",
10+
},
11+
.interdependent_static_c_libs = .{
12+
.path = "interdependent_static_c_libs",
13+
},
14+
.static_libs_from_object_files = .{
15+
.path = "static_libs_from_object_files",
16+
},
17+
.glibc_compat = .{
18+
.path = "glibc_compat",
19+
},
20+
// WASM Cases
21+
.wasm_archive = .{
22+
.path = "wasm/archive",
23+
},
24+
.wasm_basic_features = .{
25+
.path = "wasm/basic-features",
26+
},
27+
.wasm_bss = .{
28+
.path = "wasm/bss",
29+
},
30+
.wasm_export = .{
31+
.path = "wasm/export",
32+
},
33+
.wasm_export_data = .{
34+
.path = "wasm/export-data",
35+
},
36+
.wasm_extern = .{
37+
.path = "wasm/extern",
38+
},
39+
.wasm_extern_mangle = .{
40+
.path = "wasm/extern-mangle",
41+
},
42+
.wasm_function_table = .{
43+
.path = "wasm/function-table",
44+
},
45+
.wasm_infer_features = .{
46+
.path = "wasm/infer-features",
47+
},
48+
.wasm_producers = .{
49+
.path = "wasm/producers",
50+
},
51+
.wasm_segments = .{
52+
.path = "wasm/segments",
53+
},
54+
.wasm_shared_memory = .{
55+
.path = "wasm/shared-memory",
56+
},
57+
.wasm_stack_pointer = .{
58+
.path = "wasm/stack_pointer",
59+
},
60+
.wasm_type = .{
61+
.path = "wasm/type",
62+
},
63+
},
64+
.paths = .{
65+
"build.zig",
66+
"build.zig.zon",
67+
"link.zig",
68+
},
69+
}

0 commit comments

Comments
 (0)