authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-19 12:09:48+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-09-19 12:09:48+02:00
log97df4ae3ce34ae2f1ac8298a99faaf990e22ca75
treebc87b057fadd0056e22bb930cd214318ddc77112
parentde489031d873193ca94de1292828c00a02e3b3ea
parentc26c5a3c1b9dc55e157374cc5fab11fe28d53ecf
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #25268 from alexrp/loongarch

Miscellaneous LoongArch work to prepare for CI

28 files changed, 339 insertions(+), 46 deletions(-)

build.zig+1
......@@ -576,6 +576,7 @@ pub fn build(b: *std.Build) !void {
576576 enable_macos_sdk,
577577 enable_ios_sdk,
578578 enable_symlinks_windows,
579 skip_translate_c,
579580 ));
580581 test_step.dependOn(tests.addCAbiTests(b, .{
581582 .test_target_filters = test_target_filters,
ci/loongarch64-linux-debug.sh created+71
......@@ -0,0 +1,71 @@
1#!/bin/sh
2
3# Requires cmake ninja-build
4
5set -x
6set -e
7
8ARCH="$(uname -m)"
9TARGET="$ARCH-linux-musl"
10MCPU="baseline"
11CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
12PREFIX="$HOME/deps/$CACHE_BASENAME"
13ZIG="$PREFIX/bin/zig"
14
15# Make the `zig version` number consistent.
16# This will affect the cmake command below.
17git fetch --unshallow || true
18git fetch --tags
19
20# Override the cache directories because they won't actually help other CI runs
21# which will be testing alternate versions of zig, and ultimately would just
22# fill up space on the hard drive for no reason.
23export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
24export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
25
26mkdir build-debug
27cd build-debug
28
29export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
30export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
31
32cmake .. \
33 -DCMAKE_INSTALL_PREFIX="stage3-debug" \
34 -DCMAKE_PREFIX_PATH="$PREFIX" \
35 -DCMAKE_BUILD_TYPE=Debug \
36 -DZIG_TARGET_TRIPLE="$TARGET" \
37 -DZIG_TARGET_MCPU="$MCPU" \
38 -DZIG_STATIC=ON \
39 -DZIG_NO_LIB=ON \
40 -GNinja \
41 -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
42 -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
43# https://github.com/ziglang/zig/issues/22213
44
45# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
46# so that installation and testing do not get affected by them.
47unset CC
48unset CXX
49
50ninja install
51
52# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
53stage3-debug/bin/zig build test \
54 --maxrss 60129542144 \
55 -Dstatic-llvm \
56 -Dskip-non-native \
57 -Dtarget=native-native-musl \
58 --search-prefix "$PREFIX" \
59 --zig-lib-dir "$PWD/../lib" \
60 -Dno-langref \
61 -Dskip-translate-c
62
63stage3-debug/bin/zig build \
64 --prefix stage4-debug \
65 -Denable-llvm \
66 -Dno-lib \
67 -Dtarget=$TARGET \
68 -Duse-zig-libcxx \
69 -Dversion-string="$(stage3-debug/bin/zig version)"
70
71stage4-debug/bin/zig test ../test/behavior.zig
ci/loongarch64-linux-release.sh created+77
......@@ -0,0 +1,77 @@
1#!/bin/sh
2
3# Requires cmake ninja-build
4
5set -x
6set -e
7
8ARCH="$(uname -m)"
9TARGET="$ARCH-linux-musl"
10MCPU="baseline"
11CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
12PREFIX="$HOME/deps/$CACHE_BASENAME"
13ZIG="$PREFIX/bin/zig"
14
15# Make the `zig version` number consistent.
16# This will affect the cmake command below.
17git fetch --unshallow || true
18git fetch --tags
19
20# Override the cache directories because they won't actually help other CI runs
21# which will be testing alternate versions of zig, and ultimately would just
22# fill up space on the hard drive for no reason.
23export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
24export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
25
26mkdir build-release
27cd build-release
28
29export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
30export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
31
32cmake .. \
33 -DCMAKE_INSTALL_PREFIX="stage3-release" \
34 -DCMAKE_PREFIX_PATH="$PREFIX" \
35 -DCMAKE_BUILD_TYPE=Release \
36 -DZIG_TARGET_TRIPLE="$TARGET" \
37 -DZIG_TARGET_MCPU="$MCPU" \
38 -DZIG_STATIC=ON \
39 -DZIG_NO_LIB=ON \
40 -GNinja \
41 -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
42 -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
43# https://github.com/ziglang/zig/issues/22213
44
45# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
46# so that installation and testing do not get affected by them.
47unset CC
48unset CXX
49
50ninja install
51
52# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
53stage3-release/bin/zig build test \
54 --maxrss 60129542144 \
55 -Dstatic-llvm \
56 -Dskip-non-native \
57 -Dtarget=native-native-musl \
58 --search-prefix "$PREFIX" \
59 --zig-lib-dir "$PWD/../lib" \
60 -Dno-langref \
61 -Dskip-translate-c
62
63# Ensure that stage3 and stage4 are byte-for-byte identical.
64stage3-release/bin/zig build \
65 --prefix stage4-release \
66 -Denable-llvm \
67 -Dno-lib \
68 -Doptimize=ReleaseFast \
69 -Dstrip \
70 -Dtarget=$TARGET \
71 -Duse-zig-libcxx \
72 -Dversion-string="$(stage3-release/bin/zig version)"
73
74# diff returns an error code if the files differ.
75echo "If the following command fails, it means nondeterminism has been"
76echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
77diff stage3-release/bin/zig stage4-release/bin/zig
doc/langref/runtime_shrExact_overflow.zig+1-1
......@@ -7,7 +7,7 @@ pub fn main() void {
77 const y = @shrExact(x, 2);
88 std.debug.print("value: {}\n", .{y});
99
10 if (builtin.cpu.arch.isRISCV() and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
10 if ((builtin.cpu.arch.isRISCV() or builtin.cpu.arch.isLoongArch()) and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
1111}
1212
1313// exe=fail
lib/std/Target.zig+1-1
......@@ -1903,7 +1903,7 @@ pub const Cpu = struct {
19031903 .csky => &csky.cpu.ck810, // gcc/clang do not have a generic csky model.
19041904 .hexagon => &hexagon.cpu.hexagonv68, // gcc/clang do not have a generic hexagon model.
19051905 .lanai => &lanai.cpu.v11, // clang does not have a generic lanai model.
1906 .loongarch64 => &loongarch.cpu.loongarch64,
1906 .loongarch64 => &loongarch.cpu.la64v1_0,
19071907 .m68k => &m68k.cpu.M68000,
19081908 .mips, .mipsel => &mips.cpu.mips32r2,
19091909 .mips64, .mips64el => &mips.cpu.mips64r2,
lib/std/Target/loongarch.zig+24-14
......@@ -159,11 +159,6 @@ pub const all_features = blk: {
159159};
160160
161161pub const cpu = struct {
162 pub const generic: CpuModel = .{
163 .name = "generic",
164 .llvm_name = "generic",
165 .features = featureSet(&[_]Feature{}),
166 };
167162 pub const generic_la32: CpuModel = .{
168163 .name = "generic_la32",
169164 .llvm_name = "generic-la32",
......@@ -191,6 +186,30 @@ pub const cpu = struct {
191186 .ual,
192187 }),
193188 };
189 pub const la64v1_0: CpuModel = .{
190 .name = "la64v1_0",
191 .llvm_name = null,
192 .features = featureSet(&[_]Feature{
193 .@"64bit",
194 .lsx,
195 .ual,
196 }),
197 };
198 pub const la64v1_1: CpuModel = .{
199 .name = "la64v1_1",
200 .llvm_name = null,
201 .features = featureSet(&[_]Feature{
202 .@"64bit",
203 .div32,
204 .frecipe,
205 .lam_bh,
206 .lamcas,
207 .ld_seq_sa,
208 .lsx,
209 .scq,
210 .ual,
211 }),
212 };
194213 pub const la664: CpuModel = .{
195214 .name = "la664",
196215 .llvm_name = "la664",
......@@ -208,13 +227,4 @@ pub const cpu = struct {
208227 .ual,
209228 }),
210229 };
211 pub const loongarch64: CpuModel = .{
212 .name = "loongarch64",
213 .llvm_name = "loongarch64",
214 .features = featureSet(&[_]Feature{
215 .@"64bit",
216 .d,
217 .ual,
218 }),
219 };
220230};
lib/std/crypto/ml_kem.zig+6
......@@ -1722,14 +1722,20 @@ test "Test happy flow" {
17221722// Code to test NIST Known Answer Tests (KAT), see PQCgenKAT.c.
17231723
17241724test "NIST KAT test d00.Kyber512" {
1725 if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest;
1726
17251727 try testNistKat(d00.Kyber512, "e9c2bd37133fcb40772f81559f14b1f58dccd1c816701be9ba6214d43baf4547");
17261728}
17271729
17281730test "NIST KAT test d00.Kyber1024" {
1731 if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest;
1732
17291733 try testNistKat(d00.Kyber1024, "89248f2f33f7f4f7051729111f3049c409a933ec904aedadf035f30fa5646cd5");
17301734}
17311735
17321736test "NIST KAT test d00.Kyber768" {
1737 if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest;
1738
17331739 try testNistKat(d00.Kyber768, "a1e122cad3c24bc51622e4c242d8b8acbcd3f618fee4220400605ca8f9ea02c2");
17341740}
17351741
lib/std/math/modf.zig+1
......@@ -87,6 +87,7 @@ fn ModfTests(comptime T: type) type {
8787 test "vector" {
8888 if (builtin.os.tag == .macos and builtin.cpu.arch == .aarch64) return error.SkipZigTest;
8989 if (builtin.cpu.arch == .s390x) return error.SkipZigTest;
90 if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159529
9091
9192 const widths = [_]comptime_int{ 1, 2, 3, 4, 8, 16 };
9293
lib/std/mem.zig+2-1
......@@ -4534,7 +4534,8 @@ pub fn doNotOptimizeAway(val: anytype) void {
45344534 } else doNotOptimizeAway(&val);
45354535 },
45364536 .float => {
4537 if ((t.float.bits == 32 or t.float.bits == 64) and builtin.zig_backend != .stage2_c) {
4537 // https://github.com/llvm/llvm-project/issues/159200
4538 if ((t.float.bits == 32 or t.float.bits == 64) and builtin.zig_backend != .stage2_c and !builtin.cpu.arch.isLoongArch()) {
45384539 asm volatile (""
45394540 :
45404541 : [_] "rm" (val),
lib/std/zig/system.zig+2-3
......@@ -468,9 +468,8 @@ fn detectNativeCpuAndFeatures(cpu_arch: Target.Cpu.Arch, os: Target.Os, query: T
468468 // although it is a runtime value, is guaranteed to be one of the architectures in the set
469469 // of the respective switch prong.
470470 switch (builtin.cpu.arch) {
471 .x86_64, .x86 => {
472 return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, query);
473 },
471 .loongarch32, .loongarch64 => return @import("system/loongarch.zig").detectNativeCpuAndFeatures(cpu_arch, os, query),
472 .x86_64, .x86 => return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, query),
474473 else => {},
475474 }
476475
lib/std/zig/system/loongarch.zig created+48
......@@ -0,0 +1,48 @@
1const builtin = @import("builtin");
2const std = @import("std");
3
4pub fn detectNativeCpuAndFeatures(
5 arch: std.Target.Cpu.Arch,
6 os: std.Target.Os,
7 query: std.Target.Query,
8) ?std.Target.Cpu {
9 _ = os;
10 _ = query;
11
12 // Clearly this code could do better in the future by actually querying specific CPU features
13 // with the cpucfg instruction like on x86. But with the small number of well-known LoongArch
14 // models that exist at the moment, simply checking the PRID is plenty.
15 var cpu: std.Target.Cpu = .{
16 .arch = arch,
17 .model = switch (cpucfg(0) & 0xf000) {
18 else => return null,
19 0xc000 => &std.Target.loongarch.cpu.la464,
20 0xd000 => &std.Target.loongarch.cpu.la664,
21 },
22 .features = .empty,
23 };
24
25 cpu.features.addFeatureSet(cpu.model.features);
26 cpu.features.populateDependencies(cpu.arch.allFeaturesList());
27
28 return cpu;
29}
30
31/// This is a workaround for the C backend until zig has the ability to put
32/// C code in inline assembly.
33extern fn zig_loongarch_cpucfg(word: u32, result: *u32) callconv(.c) void;
34
35fn cpucfg(word: u32) u32 {
36 var result: u32 = undefined;
37
38 if (builtin.zig_backend == .stage2_c) {
39 zig_loongarch_cpucfg(word, &result);
40 } else {
41 asm ("cpucfg %[result], %[word]"
42 : [result] "=r" (result),
43 : [word] "r" (word),
44 );
45 }
46
47 return result;
48}
lib/zig.h+13-3
......@@ -4195,7 +4195,17 @@ static inline void* zig_x86_64_windows_teb(void) {
41954195
41964196#endif
41974197
4198#if defined(zig_x86)
4198#if defined(zig_loongarch)
4199
4200static inline void zig_loongarch_cpucfg(uint32_t word, uint32_t* result) {
4201#if defined(zig_gnuc_asm)
4202 __asm__("cpucfg %[result], %[word]" : [result] "=r" (result) : [word] "r" (word));
4203#else
4204 *result = 0;
4205#endif
4206}
4207
4208#elif defined(zig_x86)
41994209
42004210static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) {
42014211#if defined(zig_msvc)
......@@ -4206,7 +4216,7 @@ static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax
42064216 *ecx = (uint32_t)cpu_info[2];
42074217 *edx = (uint32_t)cpu_info[3];
42084218#elif defined(zig_gnuc_asm)
4209 __asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf_id), "c"(subid));
4219 __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (leaf_id), "c" (subid));
42104220#else
42114221 *eax = 0;
42124222 *ebx = 0;
......@@ -4221,7 +4231,7 @@ static inline uint32_t zig_x86_get_xcr0(void) {
42214231#elif defined(zig_gnuc_asm)
42224232 uint32_t eax;
42234233 uint32_t edx;
4224 __asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0));
4234 __asm__("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
42254235 return eax;
42264236#else
42274237 *eax = 0;
stage1/zig.h+13-3
......@@ -4195,7 +4195,17 @@ static inline void* zig_x86_64_windows_teb(void) {
41954195
41964196#endif
41974197
4198#if defined(zig_x86)
4198#if defined(zig_loongarch)
4199
4200static inline void zig_loongarch_cpucfg(uint32_t word, uint32_t* result) {
4201#if defined(zig_gnuc_asm)
4202 __asm__("cpucfg %[result], %[word]" : [result] "=r" (result) : [word] "r" (word));
4203#else
4204 *result = 0;
4205#endif
4206}
4207
4208#elif defined(zig_x86)
41994209
42004210static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) {
42014211#if defined(zig_msvc)
......@@ -4206,7 +4216,7 @@ static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax
42064216 *ecx = (uint32_t)cpu_info[2];
42074217 *edx = (uint32_t)cpu_info[3];
42084218#elif defined(zig_gnuc_asm)
4209 __asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf_id), "c"(subid));
4219 __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (leaf_id), "c" (subid));
42104220#else
42114221 *eax = 0;
42124222 *ebx = 0;
......@@ -4221,7 +4231,7 @@ static inline uint32_t zig_x86_get_xcr0(void) {
42214231#elif defined(zig_gnuc_asm)
42224232 uint32_t eax;
42234233 uint32_t edx;
4224 __asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0));
4234 __asm__("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
42254235 return eax;
42264236#else
42274237 *eax = 0;
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior/asm.zig+1
......@@ -67,6 +67,7 @@ test "alternative constraints" {
6767 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
6868 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
6969 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
70 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isLoongArch()) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159200
7071
7172 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly
7273
test/behavior/math.zig+4
......@@ -111,6 +111,8 @@ test "@clz vectors" {
111111}
112112
113113fn testClzVectors() !void {
114 if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159529
115
114116 const Vu4 = @Vector(64, u4);
115117 const Vu8 = @Vector(64, u8);
116118 const Vu128 = @Vector(64, u128);
......@@ -197,6 +199,8 @@ test "@ctz vectors" {
197199}
198200
199201fn testCtzVectors() !void {
202 if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159529
203
200204 const Vu4 = @Vector(64, u4);
201205 const Vu8 = @Vector(64, u8);
202206 @setEvalBranchQuota(10_000);
test/c_abi/main.zig+2
......@@ -1135,6 +1135,7 @@ extern fn c_ret_medium_vec() MediumVec;
11351135test "medium simd vector" {
11361136 if (builtin.zig_backend == .stage2_x86_64 and !comptime builtin.cpu.has(.x86, .avx)) return error.SkipZigTest;
11371137 if (builtin.cpu.arch.isPowerPC64()) return error.SkipZigTest;
1138 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
11381139
11391140 c_medium_vec(.{ 1, 2, 3, 4 });
11401141
......@@ -1155,6 +1156,7 @@ test "big simd vector" {
11551156
11561157 if (builtin.cpu.arch.isMIPS64() and builtin.mode != .Debug) return error.SkipZigTest;
11571158 if (builtin.cpu.arch.isPowerPC64()) return error.SkipZigTest;
1159 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
11581160 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .x86_64 and builtin.os.tag == .macos and builtin.mode != .Debug) return error.SkipZigTest;
11591161
11601162 c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });
test/src/StackTrace.zig+2
......@@ -15,6 +15,7 @@ const Config = struct {
1515
1616 const PerMode = struct {
1717 expect: []const u8,
18 exclude_arch: []const std.Target.Cpu.Arch = &.{},
1819 exclude_os: []const std.Target.Os.Tag = &.{},
1920 error_tracing: ?bool = null,
2021 };
......@@ -59,6 +60,7 @@ fn addExpect(
5960 use_llvm: bool,
6061 mode_config: Config.PerMode,
6162) void {
63 for (mode_config.exclude_arch) |tag| if (tag == builtin.cpu.arch) return;
6264 for (mode_config.exclude_os) |tag| if (tag == builtin.os.tag) return;
6365
6466 const b = self.b;
test/stack_traces.zig+10
......@@ -792,6 +792,16 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
792792 \\}
793793 ,
794794 .Debug = .{
795 // std.debug.sys_can_stack_trace
796 .exclude_arch = &.{
797 .loongarch32,
798 .loongarch64,
799 .mips,
800 .mipsel,
801 .mips64,
802 .mips64el,
803 .s390x,
804 },
795805 .exclude_os = &.{
796806 .openbsd, // integer overflow
797807 .windows, // TODO intermittent failures
test/standalone/build.zig+6-1
......@@ -9,6 +9,7 @@ pub fn build(b: *std.Build) void {
99 const enable_macos_sdk = b.option(bool, "enable_macos_sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse enable_ios_sdk;
1010 const enable_symlinks_windows = b.option(bool, "enable_symlinks_windows", "Run tests requiring presence of symlinks on Windows") orelse false;
1111 const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
12 const skip_translate_c = b.option(bool, "skip_translate_c", "Test suite skips translate-c tests") orelse false;
1213
1314 const simple_skip_debug = b.option(bool, "simple_skip_debug", "Simple tests skip debug builds") orelse false;
1415 const simple_skip_release_safe = b.option(bool, "simple_skip_release_safe", "Simple tests skip release-safe builds") orelse false;
......@@ -20,6 +21,7 @@ pub fn build(b: *std.Build) void {
2021 .skip_release_safe = simple_skip_release_safe,
2122 .skip_release_fast = simple_skip_release_fast,
2223 .skip_release_small = simple_skip_release_small,
24 .skip_translate_c = skip_translate_c,
2325 });
2426 const simple_dep_step = simple_dep.builder.default_step;
2527 simple_dep_step.name = "standalone_test_cases.simple";
......@@ -97,9 +99,12 @@ pub fn build(b: *std.Build) void {
9799 pkg.build_zig.requires_macos_sdk;
98100 const requires_symlinks = @hasDecl(pkg.build_zig, "requires_symlinks") and
99101 pkg.build_zig.requires_symlinks;
102 const requires_translate_c = @hasDecl(pkg.build_zig, "requires_translate_c") and
103 pkg.build_zig.requires_translate_c;
100104 if ((requires_symlinks and omit_symlinks) or
101105 (requires_macos_sdk and !enable_macos_sdk) or
102 (requires_ios_sdk and !enable_ios_sdk))
106 (requires_ios_sdk and !enable_ios_sdk) or
107 (requires_translate_c and skip_translate_c))
103108 {
104109 continue :add_dep_steps;
105110 }
test/standalone/dep_lazypath/build.zig+2
......@@ -1,5 +1,7 @@
11const std = @import("std");
22
3pub const requires_translate_c = true;
4
35pub fn build(b: *std.Build) void {
46 const test_step = b.step("test", "Test it");
57 b.default_step = test_step;
test/standalone/glibc_compat/build.zig+2
......@@ -1,6 +1,8 @@
11const std = @import("std");
22const builtin = @import("builtin");
33
4pub const requires_translate_c = true;
5
46// To run executables linked against a specific glibc version, the
57// run-time glibc version needs to be new enough. Check the host's glibc
68// version. Note that this does not allow for translation/vm/emulation
test/standalone/issue_794/build.zig+2
......@@ -1,5 +1,7 @@
11const std = @import("std");
22
3pub const requires_translate_c = true;
4
35pub fn build(b: *std.Build) void {
46 const test_step = b.step("test", "Test it");
57 b.default_step = test_step;
test/standalone/simple/build.zig+8-1
......@@ -9,6 +9,7 @@ pub fn build(b: *std.Build) void {
99 const skip_release_safe = b.option(bool, "skip_release_safe", "Skip release-safe builds") orelse false;
1010 const skip_release_fast = b.option(bool, "skip_release_fast", "Skip release-fast builds") orelse false;
1111 const skip_release_small = b.option(bool, "skip_release_small", "Skip release-small builds") orelse false;
12 const skip_translate_c = b.option(bool, "skip_translate_c", "Test suite skips translate-c tests") orelse false;
1213
1314 var optimize_modes_buf: [4]std.builtin.OptimizeMode = undefined;
1415 var optimize_modes_len: usize = 0;
......@@ -36,6 +37,7 @@ pub fn build(b: *std.Build) void {
3637 if (case.os_filter) |os_tag| {
3738 if (os_tag != builtin.os.tag) continue;
3839 }
40 if (case.uses_translate_c and skip_translate_c) continue;
3941
4042 const resolved_target = b.resolveTargetQuery(case.target);
4143
......@@ -82,6 +84,7 @@ const Case = struct {
8284 is_exe: bool = true,
8385 /// Run only on this OS.
8486 os_filter: ?std.Target.Os.Tag = null,
87 uses_translate_c: bool = false,
8588};
8689
8790const cases = [_]Case{
......@@ -93,6 +96,7 @@ const cases = [_]Case{
9396 .src_path = "hello_world/hello_libc.zig",
9497 .link_libc = true,
9598 .all_modes = true,
99 .uses_translate_c = true,
96100 },
97101 .{
98102 .src_path = "cat/main.zig",
......@@ -108,7 +112,10 @@ const cases = [_]Case{
108112 .os_tag = .freestanding,
109113 },
110114 },
111 .{ .src_path = "issue_12471/main.zig" },
115 .{
116 .src_path = "issue_12471/main.zig",
117 .uses_translate_c = true,
118 },
112119 .{ .src_path = "guess_number/main.zig" },
113120 .{ .src_path = "main_return_error/error_u8.zig" },
114121 .{ .src_path = "main_return_error/error_u8_non_zero.zig" },
test/standalone/simple/hello_world/hello_libc.zig+3-7
......@@ -1,15 +1,11 @@
1const c = @cImport({
2 // See https://github.com/ziglang/zig/issues/515
3 @cDefine("_NO_CRT_STDIO_INLINE", "1");
4 @cInclude("stdio.h");
5 @cInclude("string.h");
6});
1extern fn printf(format: [*:0]const u8, ...) c_int;
2extern fn strlen(str: [*:0]const u8) usize;
73
84const msg = "Hello, world!\n";
95
106pub export fn main(argc: c_int, argv: **u8) c_int {
117 _ = argv;
128 _ = argc;
13 if (c.printf(msg) != @as(c_int, @intCast(c.strlen(msg)))) return -1;
9 if (printf(msg) != @as(c_int, @intCast(strlen(msg)))) return -1;
1410 return 0;
1511}
test/standalone/static_c_lib/foo.zig+5-3
......@@ -1,12 +1,14 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const c = @cImport(@cInclude("foo.h"));
3
4extern fn add(a: u32, b: u32) u32;
5extern var foo: u32;
46
57test "C add" {
6 const result = c.add(1, 2);
8 const result = add(1, 2);
79 try expect(result == 3);
810}
911
1012test "C extern variable" {
11 try expect(c.foo == 12345);
13 try expect(foo == 12345);
1214}
test/tests.zig+2-8
......@@ -419,8 +419,6 @@ const test_targets = blk: {
419419 .os_tag = .linux,
420420 .abi = .none,
421421 },
422 // https://github.com/ziglang/zig/issues/21646
423 .skip_modules = &.{"std"},
424422 },
425423 .{
426424 .target = .{
......@@ -429,8 +427,6 @@ const test_targets = blk: {
429427 .abi = .musl,
430428 },
431429 .link_libc = true,
432 // https://github.com/ziglang/zig/issues/21646
433 .skip_modules = &.{"std"},
434430 },
435431 .{
436432 .target = .{
......@@ -440,8 +436,6 @@ const test_targets = blk: {
440436 },
441437 .linkage = .dynamic,
442438 .link_libc = true,
443 // https://github.com/ziglang/zig/issues/21646
444 .skip_modules = &.{"std"},
445439 .extra_target = true,
446440 },
447441 .{
......@@ -451,8 +445,6 @@ const test_targets = blk: {
451445 .abi = .gnu,
452446 },
453447 .link_libc = true,
454 // https://github.com/ziglang/zig/issues/21646
455 .skip_modules = &.{"std"},
456448 },
457449
458450 .{
......@@ -1901,6 +1893,7 @@ pub fn addStandaloneTests(
19011893 enable_macos_sdk: bool,
19021894 enable_ios_sdk: bool,
19031895 enable_symlinks_windows: bool,
1896 skip_translate_c: bool,
19041897) *Step {
19051898 const step = b.step("test-standalone", "Run the standalone tests");
19061899 if (compilerHasPackageManager(b)) {
......@@ -1913,6 +1906,7 @@ pub fn addStandaloneTests(
19131906 .simple_skip_release_safe = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSafe) == null,
19141907 .simple_skip_release_fast = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseFast) == null,
19151908 .simple_skip_release_small = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSmall) == null,
1909 .skip_translate_c = skip_translate_c,
19161910 });
19171911 const test_cases_dep_step = test_cases_dep.builder.default_step;
19181912 test_cases_dep_step.name = b.dupe(test_cases_dep_name);
tools/update_cpu_features.zig+30
......@@ -986,6 +986,36 @@ const targets = [_]ArchTarget{
986986 .name = "LoongArch",
987987 .td_name = "LoongArch",
988988 },
989 .extra_cpus = &.{
990 .{
991 .llvm_name = null,
992 .zig_name = "la64v1_0",
993 .features = &.{
994 "64bit",
995 "lsx",
996 "ual",
997 },
998 },
999 .{
1000 .llvm_name = null,
1001 .zig_name = "la64v1_1",
1002 .features = &.{
1003 "64bit",
1004 "div32",
1005 "frecipe",
1006 "lam_bh",
1007 "lamcas",
1008 "ld_seq_sa",
1009 "lsx",
1010 "scq",
1011 "ual",
1012 },
1013 },
1014 },
1015 .omit_cpus = &.{
1016 "generic",
1017 "loongarch64",
1018 },
9891019 },
9901020 .{
9911021 .zig_name = "m68k",