Skip to content

Commit 1c73b25

Browse files
authored
Merge branch 'master' into patch-1
2 parents 6eb26a0 + bd97b66 commit 1c73b25

File tree

8 files changed

+208
-14
lines changed

8 files changed

+208
-14
lines changed

.github/workflows/ci.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ jobs:
5050
uses: actions/checkout@v4
5151
- name: Build and Test
5252
run: sh ci/aarch64-linux-release.sh
53+
riscv64-linux-debug:
54+
timeout-minutes: 900
55+
runs-on: [self-hosted, Linux, riscv64]
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v4
59+
- name: Build and Test
60+
run: sh ci/riscv64-linux-debug.sh
61+
riscv64-linux-release:
62+
timeout-minutes: 780
63+
runs-on: [self-hosted, Linux, riscv64]
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v4
67+
- name: Build and Test
68+
run: sh ci/riscv64-linux-release.sh
5369
x86_64-macos-release:
5470
runs-on: "macos-13"
5571
env:

ci/riscv64-linux-debug.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
3+
# Requires cmake ninja-build
4+
5+
set -x
6+
set -e
7+
8+
ARCH="$(uname -m)"
9+
TARGET="$ARCH-linux-musl"
10+
MCPU="spacemit_x60"
11+
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.15.0-dev.929+31e46be74"
12+
PREFIX="$HOME/deps/$CACHE_BASENAME"
13+
ZIG="$PREFIX/bin/zig"
14+
15+
export PATH="$HOME/local/bin:$PATH"
16+
17+
# Make the `zig version` number consistent.
18+
# This will affect the cmake command below.
19+
git fetch --unshallow || true
20+
git fetch --tags
21+
22+
# Override the cache directories because they won't actually help other CI runs
23+
# which will be testing alternate versions of zig, and ultimately would just
24+
# fill up space on the hard drive for no reason.
25+
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
26+
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
27+
28+
mkdir build-debug
29+
cd build-debug
30+
31+
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
32+
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
33+
34+
cmake .. \
35+
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
36+
-DCMAKE_PREFIX_PATH="$PREFIX" \
37+
-DCMAKE_BUILD_TYPE=Debug \
38+
-DZIG_TARGET_TRIPLE="$TARGET" \
39+
-DZIG_TARGET_MCPU="$MCPU" \
40+
-DZIG_STATIC=ON \
41+
-DZIG_NO_LIB=ON \
42+
-GNinja
43+
44+
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
45+
# so that installation and testing do not get affected by them.
46+
unset CC
47+
unset CXX
48+
49+
ninja install
50+
51+
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
52+
stage3-debug/bin/zig build test docs \
53+
--maxrss 68719476736 \
54+
-Dstatic-llvm \
55+
-Dskip-non-native \
56+
-Dtarget=native-native-musl \
57+
--search-prefix "$PREFIX" \
58+
--zig-lib-dir "$PWD/../lib"
59+
60+
stage3-debug/bin/zig build \
61+
--prefix stage4-debug \
62+
-Denable-llvm \
63+
-Dno-lib \
64+
-Dtarget=$TARGET \
65+
-Dcpu=$MCPU \
66+
-Duse-zig-libcxx \
67+
-Dversion-string="$(stage3-debug/bin/zig version)"
68+
69+
stage4-debug/bin/zig test ../test/behavior.zig

ci/riscv64-linux-release.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
3+
# Requires cmake ninja-build
4+
5+
set -x
6+
set -e
7+
8+
ARCH="$(uname -m)"
9+
TARGET="$ARCH-linux-musl"
10+
MCPU="spacemit_x60"
11+
CACHE_BASENAME="zig+llvm+lld+clang-riscv64-linux-musl-0.15.0-dev.929+31e46be74"
12+
PREFIX="$HOME/deps/$CACHE_BASENAME"
13+
ZIG="$PREFIX/bin/zig"
14+
15+
export PATH="$HOME/local/bin:$PATH"
16+
17+
# Make the `zig version` number consistent.
18+
# This will affect the cmake command below.
19+
git fetch --unshallow || true
20+
git fetch --tags
21+
22+
# Override the cache directories because they won't actually help other CI runs
23+
# which will be testing alternate versions of zig, and ultimately would just
24+
# fill up space on the hard drive for no reason.
25+
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
26+
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
27+
28+
mkdir build-release
29+
cd build-release
30+
31+
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
32+
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
33+
34+
cmake .. \
35+
-DCMAKE_INSTALL_PREFIX="stage3-release" \
36+
-DCMAKE_PREFIX_PATH="$PREFIX" \
37+
-DCMAKE_BUILD_TYPE=Release \
38+
-DZIG_TARGET_TRIPLE="$TARGET" \
39+
-DZIG_TARGET_MCPU="$MCPU" \
40+
-DZIG_STATIC=ON \
41+
-DZIG_NO_LIB=ON \
42+
-GNinja
43+
44+
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
45+
# so that installation and testing do not get affected by them.
46+
unset CC
47+
unset CXX
48+
49+
ninja install
50+
51+
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
52+
stage3-release/bin/zig build test docs \
53+
--maxrss 68719476736 \
54+
-Dstatic-llvm \
55+
-Dskip-non-native \
56+
-Dtarget=native-native-musl \
57+
--search-prefix "$PREFIX" \
58+
--zig-lib-dir "$PWD/../lib"
59+
60+
# Ensure that stage3 and stage4 are byte-for-byte identical.
61+
stage3-release/bin/zig build \
62+
--prefix stage4-release \
63+
-Denable-llvm \
64+
-Dno-lib \
65+
-Doptimize=ReleaseFast \
66+
-Dstrip \
67+
-Dtarget=$TARGET \
68+
-Dcpu=$MCPU \
69+
-Duse-zig-libcxx \
70+
-Dversion-string="$(stage3-release/bin/zig version)"
71+
72+
# diff returns an error code if the files differ.
73+
echo "If the following command fails, it means nondeterminism has been"
74+
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
75+
diff stage3-release/bin/zig stage4-release/bin/zig

lib/std/Build/Step/Run.zig

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,9 @@ fn runCommand(
10791079
var interp_argv = std.ArrayList([]const u8).init(b.allocator);
10801080
defer interp_argv.deinit();
10811081

1082-
const result = spawnChildAndCollect(run, argv, has_side_effects, prog_node, fuzz_context) catch |err| term: {
1082+
var env_map = run.env_map orelse &b.graph.env_map;
1083+
1084+
const result = spawnChildAndCollect(run, argv, env_map, has_side_effects, prog_node, fuzz_context) catch |err| term: {
10831085
// InvalidExe: cpu arch mismatch
10841086
// FileNotFound: can happen with a wrong dynamic linker path
10851087
if (err == error.InvalidExe or err == error.FileNotFound) interpret: {
@@ -1112,6 +1114,15 @@ fn runCommand(
11121114
if (b.enable_wine) {
11131115
try interp_argv.append(bin_name);
11141116
try interp_argv.appendSlice(argv);
1117+
1118+
// Wine's excessive stderr logging is only situationally helpful. Disable it by default, but
1119+
// allow the user to override it (e.g. with `WINEDEBUG=err+all`) if desired.
1120+
if (env_map.get("WINEDEBUG") == null) {
1121+
// We don't own `env_map` at this point, so turn it into a copy before modifying it.
1122+
env_map = arena.create(EnvMap) catch @panic("OOM");
1123+
env_map.hash_map = try env_map.hash_map.cloneWithAllocator(arena);
1124+
try env_map.put("WINEDEBUG", "-all");
1125+
}
11151126
} else {
11161127
return failForeign(run, "-fwine", argv[0], exe);
11171128
}
@@ -1207,7 +1218,7 @@ fn runCommand(
12071218

12081219
try Step.handleVerbose2(step.owner, cwd, run.env_map, interp_argv.items);
12091220

1210-
break :term spawnChildAndCollect(run, interp_argv.items, has_side_effects, prog_node, fuzz_context) catch |e| {
1221+
break :term spawnChildAndCollect(run, interp_argv.items, env_map, has_side_effects, prog_node, fuzz_context) catch |e| {
12111222
if (!run.failing_to_execute_foreign_is_an_error) return error.MakeSkipped;
12121223

12131224
return step.fail("unable to spawn interpreter {s}: {s}", .{
@@ -1390,6 +1401,7 @@ const ChildProcResult = struct {
13901401
fn spawnChildAndCollect(
13911402
run: *Run,
13921403
argv: []const []const u8,
1404+
env_map: *EnvMap,
13931405
has_side_effects: bool,
13941406
prog_node: std.Progress.Node,
13951407
fuzz_context: ?FuzzContext,
@@ -1406,7 +1418,7 @@ fn spawnChildAndCollect(
14061418
if (run.cwd) |lazy_cwd| {
14071419
child.cwd = lazy_cwd.getPath2(b, &run.step);
14081420
}
1409-
child.env_map = run.env_map orelse &b.graph.env_map;
1421+
child.env_map = env_map;
14101422
child.request_resource_usage_statistics = true;
14111423

14121424
child.stdin_behavior = switch (run.stdio) {

lib/std/Io.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ pub fn PollFiles(comptime StreamEnum: type) type {
868868

869869
test {
870870
_ = Reader;
871+
_ = Reader.Limited;
871872
_ = Writer;
872873
_ = @import("Io/bit_reader.zig");
873874
_ = @import("Io/bit_writer.zig");

lib/std/Io/Reader.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub const ShortError = error{
9999

100100
pub const failing: Reader = .{
101101
.vtable = &.{
102-
.read = failingStream,
102+
.stream = failingStream,
103103
.discard = failingDiscard,
104104
},
105105
.buffer = &.{},

lib/std/Io/Reader/Limited.zig

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,34 @@ pub fn init(reader: *Reader, limit: Limit, buffer: []u8) Limited {
2525
};
2626
}
2727

28-
fn stream(context: ?*anyopaque, w: *Writer, limit: Limit) Reader.StreamError!usize {
29-
const l: *Limited = @alignCast(@ptrCast(context));
28+
fn stream(r: *Reader, w: *Writer, limit: Limit) Reader.StreamError!usize {
29+
const l: *Limited = @fieldParentPtr("interface", r);
3030
const combined_limit = limit.min(l.remaining);
31-
const n = try l.unlimited_reader.read(w, combined_limit);
31+
const n = try l.unlimited.stream(w, combined_limit);
3232
l.remaining = l.remaining.subtract(n).?;
3333
return n;
3434
}
3535

36-
fn discard(context: ?*anyopaque, limit: Limit) Reader.Error!usize {
37-
const l: *Limited = @alignCast(@ptrCast(context));
36+
test stream {
37+
var orig_buf: [10]u8 = undefined;
38+
@memcpy(&orig_buf, "test bytes");
39+
var fixed: std.Io.Reader = .fixed(&orig_buf);
40+
41+
var limit_buf: [1]u8 = undefined;
42+
var limited: std.Io.Reader.Limited = .init(&fixed, @enumFromInt(4), &limit_buf);
43+
44+
var result_buf: [10]u8 = undefined;
45+
var fixed_writer: std.Io.Writer = .fixed(&result_buf);
46+
const streamed = try limited.interface.stream(&fixed_writer, @enumFromInt(7));
47+
48+
try std.testing.expect(streamed == 4);
49+
try std.testing.expectEqualStrings("test", result_buf[0..streamed]);
50+
}
51+
52+
fn discard(r: *Reader, limit: Limit) Reader.Error!usize {
53+
const l: *Limited = @fieldParentPtr("interface", r);
3854
const combined_limit = limit.min(l.remaining);
39-
const n = try l.unlimited_reader.discard(combined_limit);
55+
const n = try l.unlimited.discard(combined_limit);
4056
l.remaining = l.remaining.subtract(n).?;
4157
return n;
4258
}

test/tests.zig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ const test_targets = blk: {
438438
.os_tag = .linux,
439439
.abi = .none,
440440
},
441-
// https://github.com/ziglang/zig/issues/23696
441+
// https://github.com/ziglang/zig/issues/21646
442442
.skip_modules = &.{"std"},
443443
},
444444
.{
@@ -448,7 +448,7 @@ const test_targets = blk: {
448448
.abi = .musl,
449449
},
450450
.link_libc = true,
451-
// https://github.com/ziglang/zig/issues/23696
451+
// https://github.com/ziglang/zig/issues/21646
452452
.skip_modules = &.{"std"},
453453
},
454454
.{
@@ -459,7 +459,7 @@ const test_targets = blk: {
459459
},
460460
.linkage = .dynamic,
461461
.link_libc = true,
462-
// https://github.com/ziglang/zig/issues/23696
462+
// https://github.com/ziglang/zig/issues/21646
463463
.skip_modules = &.{"std"},
464464
.extra_target = true,
465465
},
@@ -470,7 +470,7 @@ const test_targets = blk: {
470470
.abi = .gnu,
471471
},
472472
.link_libc = true,
473-
// https://github.com/ziglang/zig/issues/23696
473+
// https://github.com/ziglang/zig/issues/21646
474474
.skip_modules = &.{"std"},
475475
},
476476

@@ -2369,6 +2369,11 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
23692369
if (options.skip_single_threaded and test_target.single_threaded == true)
23702370
continue;
23712371

2372+
// https://github.com/ziglang/zig/issues/24405
2373+
if (!builtin.cpu.arch.isLoongArch() and target.cpu.arch.isLoongArch() and
2374+
(mem.eql(u8, options.name, "behavior") or mem.eql(u8, options.name, "std")))
2375+
continue;
2376+
23722377
// TODO get compiler-rt tests passing for self-hosted backends.
23732378
if ((target.cpu.arch != .x86_64 or target.ofmt != .elf) and
23742379
test_target.use_llvm == false and mem.eql(u8, options.name, "compiler-rt"))

0 commit comments

Comments
 (0)