Merge pull request #25268 from alexrp/loongarch

Miscellaneous LoongArch work to prepare for CI
This commit is contained in:
Alex Rønne Petersen 2025-09-19 12:09:48 +02:00 committed by GitHub
commit 97df4ae3ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 339 additions and 46 deletions

View File

@ -576,6 +576,7 @@ pub fn build(b: *std.Build) !void {
enable_macos_sdk,
enable_ios_sdk,
enable_symlinks_windows,
skip_translate_c,
));
test_step.dependOn(tests.addCAbiTests(b, .{
.test_target_filters = test_target_filters,

71
ci/loongarch64-linux-debug.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-debug
cd build-debug
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-debug/bin/zig build test \
--maxrss 60129542144 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Dno-langref \
-Dskip-translate-c
stage3-debug/bin/zig build \
--prefix stage4-debug \
-Denable-llvm \
-Dno-lib \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-debug/bin/zig version)"
stage4-debug/bin/zig test ../test/behavior.zig

77
ci/loongarch64-linux-release.sh Executable file
View File

@ -0,0 +1,77 @@
#!/bin/sh
# Requires cmake ninja-build
set -x
set -e
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.157+7fdd60df1"
PREFIX="$HOME/deps/$CACHE_BASENAME"
ZIG="$PREFIX/bin/zig"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git fetch --unshallow || true
git fetch --tags
# Override the cache directories because they won't actually help other CI runs
# which will be testing alternate versions of zig, and ultimately would just
# fill up space on the hard drive for no reason.
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
mkdir build-release
cd build-release
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-DZIG_NO_LIB=ON \
-GNinja \
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
# https://github.com/ziglang/zig/issues/22213
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
# No -fqemu and -fwasmtime here as they're covered by the x86_64-linux scripts.
stage3-release/bin/zig build test \
--maxrss 60129542144 \
-Dstatic-llvm \
-Dskip-non-native \
-Dtarget=native-native-musl \
--search-prefix "$PREFIX" \
--zig-lib-dir "$PWD/../lib" \
-Dno-langref \
-Dskip-translate-c
# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
-Denable-llvm \
-Dno-lib \
-Doptimize=ReleaseFast \
-Dstrip \
-Dtarget=$TARGET \
-Duse-zig-libcxx \
-Dversion-string="$(stage3-release/bin/zig version)"
# diff returns an error code if the files differ.
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

View File

@ -7,7 +7,7 @@ pub fn main() void {
const y = @shrExact(x, 2);
std.debug.print("value: {}\n", .{y});
if (builtin.cpu.arch.isRISCV() and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
if ((builtin.cpu.arch.isRISCV() or builtin.cpu.arch.isLoongArch()) and builtin.zig_backend == .stage2_llvm) @panic("https://github.com/ziglang/zig/issues/24304");
}
// exe=fail

View File

@ -1903,7 +1903,7 @@ pub const Cpu = struct {
.csky => &csky.cpu.ck810, // gcc/clang do not have a generic csky model.
.hexagon => &hexagon.cpu.hexagonv68, // gcc/clang do not have a generic hexagon model.
.lanai => &lanai.cpu.v11, // clang does not have a generic lanai model.
.loongarch64 => &loongarch.cpu.loongarch64,
.loongarch64 => &loongarch.cpu.la64v1_0,
.m68k => &m68k.cpu.M68000,
.mips, .mipsel => &mips.cpu.mips32r2,
.mips64, .mips64el => &mips.cpu.mips64r2,

View File

@ -159,11 +159,6 @@ pub const all_features = blk: {
};
pub const cpu = struct {
pub const generic: CpuModel = .{
.name = "generic",
.llvm_name = "generic",
.features = featureSet(&[_]Feature{}),
};
pub const generic_la32: CpuModel = .{
.name = "generic_la32",
.llvm_name = "generic-la32",
@ -191,6 +186,30 @@ pub const cpu = struct {
.ual,
}),
};
pub const la64v1_0: CpuModel = .{
.name = "la64v1_0",
.llvm_name = null,
.features = featureSet(&[_]Feature{
.@"64bit",
.lsx,
.ual,
}),
};
pub const la64v1_1: CpuModel = .{
.name = "la64v1_1",
.llvm_name = null,
.features = featureSet(&[_]Feature{
.@"64bit",
.div32,
.frecipe,
.lam_bh,
.lamcas,
.ld_seq_sa,
.lsx,
.scq,
.ual,
}),
};
pub const la664: CpuModel = .{
.name = "la664",
.llvm_name = "la664",
@ -208,13 +227,4 @@ pub const cpu = struct {
.ual,
}),
};
pub const loongarch64: CpuModel = .{
.name = "loongarch64",
.llvm_name = "loongarch64",
.features = featureSet(&[_]Feature{
.@"64bit",
.d,
.ual,
}),
};
};

View File

@ -1722,14 +1722,20 @@ test "Test happy flow" {
// Code to test NIST Known Answer Tests (KAT), see PQCgenKAT.c.
test "NIST KAT test d00.Kyber512" {
if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest;
try testNistKat(d00.Kyber512, "e9c2bd37133fcb40772f81559f14b1f58dccd1c816701be9ba6214d43baf4547");
}
test "NIST KAT test d00.Kyber1024" {
if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest;
try testNistKat(d00.Kyber1024, "89248f2f33f7f4f7051729111f3049c409a933ec904aedadf035f30fa5646cd5");
}
test "NIST KAT test d00.Kyber768" {
if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest;
try testNistKat(d00.Kyber768, "a1e122cad3c24bc51622e4c242d8b8acbcd3f618fee4220400605ca8f9ea02c2");
}

View File

@ -87,6 +87,7 @@ fn ModfTests(comptime T: type) type {
test "vector" {
if (builtin.os.tag == .macos and builtin.cpu.arch == .aarch64) return error.SkipZigTest;
if (builtin.cpu.arch == .s390x) return error.SkipZigTest;
if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159529
const widths = [_]comptime_int{ 1, 2, 3, 4, 8, 16 };

View File

@ -4534,7 +4534,8 @@ pub fn doNotOptimizeAway(val: anytype) void {
} else doNotOptimizeAway(&val);
},
.float => {
if ((t.float.bits == 32 or t.float.bits == 64) and builtin.zig_backend != .stage2_c) {
// https://github.com/llvm/llvm-project/issues/159200
if ((t.float.bits == 32 or t.float.bits == 64) and builtin.zig_backend != .stage2_c and !builtin.cpu.arch.isLoongArch()) {
asm volatile (""
:
: [_] "rm" (val),

View File

@ -468,9 +468,8 @@ fn detectNativeCpuAndFeatures(cpu_arch: Target.Cpu.Arch, os: Target.Os, query: T
// although it is a runtime value, is guaranteed to be one of the architectures in the set
// of the respective switch prong.
switch (builtin.cpu.arch) {
.x86_64, .x86 => {
return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, query);
},
.loongarch32, .loongarch64 => return @import("system/loongarch.zig").detectNativeCpuAndFeatures(cpu_arch, os, query),
.x86_64, .x86 => return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, query),
else => {},
}

View File

@ -0,0 +1,48 @@
const builtin = @import("builtin");
const std = @import("std");
pub fn detectNativeCpuAndFeatures(
arch: std.Target.Cpu.Arch,
os: std.Target.Os,
query: std.Target.Query,
) ?std.Target.Cpu {
_ = os;
_ = query;
// Clearly this code could do better in the future by actually querying specific CPU features
// with the cpucfg instruction like on x86. But with the small number of well-known LoongArch
// models that exist at the moment, simply checking the PRID is plenty.
var cpu: std.Target.Cpu = .{
.arch = arch,
.model = switch (cpucfg(0) & 0xf000) {
else => return null,
0xc000 => &std.Target.loongarch.cpu.la464,
0xd000 => &std.Target.loongarch.cpu.la664,
},
.features = .empty,
};
cpu.features.addFeatureSet(cpu.model.features);
cpu.features.populateDependencies(cpu.arch.allFeaturesList());
return cpu;
}
/// This is a workaround for the C backend until zig has the ability to put
/// C code in inline assembly.
extern fn zig_loongarch_cpucfg(word: u32, result: *u32) callconv(.c) void;
fn cpucfg(word: u32) u32 {
var result: u32 = undefined;
if (builtin.zig_backend == .stage2_c) {
zig_loongarch_cpucfg(word, &result);
} else {
asm ("cpucfg %[result], %[word]"
: [result] "=r" (result),
: [word] "r" (word),
);
}
return result;
}

View File

@ -4195,7 +4195,17 @@ static inline void* zig_x86_64_windows_teb(void) {
#endif
#if defined(zig_x86)
#if defined(zig_loongarch)
static inline void zig_loongarch_cpucfg(uint32_t word, uint32_t* result) {
#if defined(zig_gnuc_asm)
__asm__("cpucfg %[result], %[word]" : [result] "=r" (result) : [word] "r" (word));
#else
*result = 0;
#endif
}
#elif defined(zig_x86)
static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) {
#if defined(zig_msvc)
@ -4206,7 +4216,7 @@ static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax
*ecx = (uint32_t)cpu_info[2];
*edx = (uint32_t)cpu_info[3];
#elif defined(zig_gnuc_asm)
__asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf_id), "c"(subid));
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (leaf_id), "c" (subid));
#else
*eax = 0;
*ebx = 0;
@ -4221,7 +4231,7 @@ static inline uint32_t zig_x86_get_xcr0(void) {
#elif defined(zig_gnuc_asm)
uint32_t eax;
uint32_t edx;
__asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0));
__asm__("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
return eax;
#else
*eax = 0;

View File

@ -4195,7 +4195,17 @@ static inline void* zig_x86_64_windows_teb(void) {
#endif
#if defined(zig_x86)
#if defined(zig_loongarch)
static inline void zig_loongarch_cpucfg(uint32_t word, uint32_t* result) {
#if defined(zig_gnuc_asm)
__asm__("cpucfg %[result], %[word]" : [result] "=r" (result) : [word] "r" (word));
#else
*result = 0;
#endif
}
#elif defined(zig_x86)
static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) {
#if defined(zig_msvc)
@ -4206,7 +4216,7 @@ static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax
*ecx = (uint32_t)cpu_info[2];
*edx = (uint32_t)cpu_info[3];
#elif defined(zig_gnuc_asm)
__asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf_id), "c"(subid));
__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (leaf_id), "c" (subid));
#else
*eax = 0;
*ebx = 0;
@ -4221,7 +4231,7 @@ static inline uint32_t zig_x86_get_xcr0(void) {
#elif defined(zig_gnuc_asm)
uint32_t eax;
uint32_t edx;
__asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0));
__asm__("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
return eax;
#else
*eax = 0;

Binary file not shown.

View File

@ -67,6 +67,7 @@ test "alternative constraints" {
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isLoongArch()) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159200
if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly

View File

@ -111,6 +111,8 @@ test "@clz vectors" {
}
fn testClzVectors() !void {
if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159529
const Vu4 = @Vector(64, u4);
const Vu8 = @Vector(64, u8);
const Vu128 = @Vector(64, u128);
@ -197,6 +199,8 @@ test "@ctz vectors" {
}
fn testCtzVectors() !void {
if (comptime builtin.cpu.has(.loongarch, .lsx)) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/159529
const Vu4 = @Vector(64, u4);
const Vu8 = @Vector(64, u8);
@setEvalBranchQuota(10_000);

View File

@ -1135,6 +1135,7 @@ extern fn c_ret_medium_vec() MediumVec;
test "medium simd vector" {
if (builtin.zig_backend == .stage2_x86_64 and !comptime builtin.cpu.has(.x86, .avx)) return error.SkipZigTest;
if (builtin.cpu.arch.isPowerPC64()) return error.SkipZigTest;
if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
c_medium_vec(.{ 1, 2, 3, 4 });
@ -1155,6 +1156,7 @@ test "big simd vector" {
if (builtin.cpu.arch.isMIPS64() and builtin.mode != .Debug) return error.SkipZigTest;
if (builtin.cpu.arch.isPowerPC64()) return error.SkipZigTest;
if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .x86_64 and builtin.os.tag == .macos and builtin.mode != .Debug) return error.SkipZigTest;
c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });

View File

@ -15,6 +15,7 @@ const Config = struct {
const PerMode = struct {
expect: []const u8,
exclude_arch: []const std.Target.Cpu.Arch = &.{},
exclude_os: []const std.Target.Os.Tag = &.{},
error_tracing: ?bool = null,
};
@ -59,6 +60,7 @@ fn addExpect(
use_llvm: bool,
mode_config: Config.PerMode,
) void {
for (mode_config.exclude_arch) |tag| if (tag == builtin.cpu.arch) return;
for (mode_config.exclude_os) |tag| if (tag == builtin.os.tag) return;
const b = self.b;

View File

@ -792,6 +792,16 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
\\}
,
.Debug = .{
// std.debug.sys_can_stack_trace
.exclude_arch = &.{
.loongarch32,
.loongarch64,
.mips,
.mipsel,
.mips64,
.mips64el,
.s390x,
},
.exclude_os = &.{
.openbsd, // integer overflow
.windows, // TODO intermittent failures

View File

@ -9,6 +9,7 @@ pub fn build(b: *std.Build) void {
const enable_macos_sdk = b.option(bool, "enable_macos_sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse enable_ios_sdk;
const enable_symlinks_windows = b.option(bool, "enable_symlinks_windows", "Run tests requiring presence of symlinks on Windows") orelse false;
const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
const skip_translate_c = b.option(bool, "skip_translate_c", "Test suite skips translate-c tests") orelse false;
const simple_skip_debug = b.option(bool, "simple_skip_debug", "Simple tests skip debug builds") orelse false;
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 {
.skip_release_safe = simple_skip_release_safe,
.skip_release_fast = simple_skip_release_fast,
.skip_release_small = simple_skip_release_small,
.skip_translate_c = skip_translate_c,
});
const simple_dep_step = simple_dep.builder.default_step;
simple_dep_step.name = "standalone_test_cases.simple";
@ -97,9 +99,12 @@ pub fn build(b: *std.Build) void {
pkg.build_zig.requires_macos_sdk;
const requires_symlinks = @hasDecl(pkg.build_zig, "requires_symlinks") and
pkg.build_zig.requires_symlinks;
const requires_translate_c = @hasDecl(pkg.build_zig, "requires_translate_c") and
pkg.build_zig.requires_translate_c;
if ((requires_symlinks and omit_symlinks) or
(requires_macos_sdk and !enable_macos_sdk) or
(requires_ios_sdk and !enable_ios_sdk))
(requires_ios_sdk and !enable_ios_sdk) or
(requires_translate_c and skip_translate_c))
{
continue :add_dep_steps;
}

View File

@ -1,5 +1,7 @@
const std = @import("std");
pub const requires_translate_c = true;
pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it");
b.default_step = test_step;

View File

@ -1,6 +1,8 @@
const std = @import("std");
const builtin = @import("builtin");
pub const requires_translate_c = true;
// To run executables linked against a specific glibc version, the
// run-time glibc version needs to be new enough. Check the host's glibc
// version. Note that this does not allow for translation/vm/emulation

View File

@ -1,5 +1,7 @@
const std = @import("std");
pub const requires_translate_c = true;
pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it");
b.default_step = test_step;

View File

@ -9,6 +9,7 @@ pub fn build(b: *std.Build) void {
const skip_release_safe = b.option(bool, "skip_release_safe", "Skip release-safe builds") orelse false;
const skip_release_fast = b.option(bool, "skip_release_fast", "Skip release-fast builds") orelse false;
const skip_release_small = b.option(bool, "skip_release_small", "Skip release-small builds") orelse false;
const skip_translate_c = b.option(bool, "skip_translate_c", "Test suite skips translate-c tests") orelse false;
var optimize_modes_buf: [4]std.builtin.OptimizeMode = undefined;
var optimize_modes_len: usize = 0;
@ -36,6 +37,7 @@ pub fn build(b: *std.Build) void {
if (case.os_filter) |os_tag| {
if (os_tag != builtin.os.tag) continue;
}
if (case.uses_translate_c and skip_translate_c) continue;
const resolved_target = b.resolveTargetQuery(case.target);
@ -82,6 +84,7 @@ const Case = struct {
is_exe: bool = true,
/// Run only on this OS.
os_filter: ?std.Target.Os.Tag = null,
uses_translate_c: bool = false,
};
const cases = [_]Case{
@ -93,6 +96,7 @@ const cases = [_]Case{
.src_path = "hello_world/hello_libc.zig",
.link_libc = true,
.all_modes = true,
.uses_translate_c = true,
},
.{
.src_path = "cat/main.zig",
@ -108,7 +112,10 @@ const cases = [_]Case{
.os_tag = .freestanding,
},
},
.{ .src_path = "issue_12471/main.zig" },
.{
.src_path = "issue_12471/main.zig",
.uses_translate_c = true,
},
.{ .src_path = "guess_number/main.zig" },
.{ .src_path = "main_return_error/error_u8.zig" },
.{ .src_path = "main_return_error/error_u8_non_zero.zig" },

View File

@ -1,15 +1,11 @@
const c = @cImport({
// See https://github.com/ziglang/zig/issues/515
@cDefine("_NO_CRT_STDIO_INLINE", "1");
@cInclude("stdio.h");
@cInclude("string.h");
});
extern fn printf(format: [*:0]const u8, ...) c_int;
extern fn strlen(str: [*:0]const u8) usize;
const msg = "Hello, world!\n";
pub export fn main(argc: c_int, argv: **u8) c_int {
_ = argv;
_ = argc;
if (c.printf(msg) != @as(c_int, @intCast(c.strlen(msg)))) return -1;
if (printf(msg) != @as(c_int, @intCast(strlen(msg)))) return -1;
return 0;
}

View File

@ -1,12 +1,14 @@
const std = @import("std");
const expect = std.testing.expect;
const c = @cImport(@cInclude("foo.h"));
extern fn add(a: u32, b: u32) u32;
extern var foo: u32;
test "C add" {
const result = c.add(1, 2);
const result = add(1, 2);
try expect(result == 3);
}
test "C extern variable" {
try expect(c.foo == 12345);
try expect(foo == 12345);
}

View File

@ -419,8 +419,6 @@ const test_targets = blk: {
.os_tag = .linux,
.abi = .none,
},
// https://github.com/ziglang/zig/issues/21646
.skip_modules = &.{"std"},
},
.{
.target = .{
@ -429,8 +427,6 @@ const test_targets = blk: {
.abi = .musl,
},
.link_libc = true,
// https://github.com/ziglang/zig/issues/21646
.skip_modules = &.{"std"},
},
.{
.target = .{
@ -440,8 +436,6 @@ const test_targets = blk: {
},
.linkage = .dynamic,
.link_libc = true,
// https://github.com/ziglang/zig/issues/21646
.skip_modules = &.{"std"},
.extra_target = true,
},
.{
@ -451,8 +445,6 @@ const test_targets = blk: {
.abi = .gnu,
},
.link_libc = true,
// https://github.com/ziglang/zig/issues/21646
.skip_modules = &.{"std"},
},
.{
@ -1901,6 +1893,7 @@ pub fn addStandaloneTests(
enable_macos_sdk: bool,
enable_ios_sdk: bool,
enable_symlinks_windows: bool,
skip_translate_c: bool,
) *Step {
const step = b.step("test-standalone", "Run the standalone tests");
if (compilerHasPackageManager(b)) {
@ -1913,6 +1906,7 @@ pub fn addStandaloneTests(
.simple_skip_release_safe = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSafe) == null,
.simple_skip_release_fast = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseFast) == null,
.simple_skip_release_small = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSmall) == null,
.skip_translate_c = skip_translate_c,
});
const test_cases_dep_step = test_cases_dep.builder.default_step;
test_cases_dep_step.name = b.dupe(test_cases_dep_name);

View File

@ -986,6 +986,36 @@ const targets = [_]ArchTarget{
.name = "LoongArch",
.td_name = "LoongArch",
},
.extra_cpus = &.{
.{
.llvm_name = null,
.zig_name = "la64v1_0",
.features = &.{
"64bit",
"lsx",
"ual",
},
},
.{
.llvm_name = null,
.zig_name = "la64v1_1",
.features = &.{
"64bit",
"div32",
"frecipe",
"lam_bh",
"lamcas",
"ld_seq_sa",
"lsx",
"scq",
"ual",
},
},
},
.omit_cpus = &.{
"generic",
"loongarch64",
},
},
.{
.zig_name = "m68k",