Merge pull request #13251 from Vexu/c-abi

implement ARM C ABI, separate C ABI tests from standalone tests
This commit is contained in:
Andrew Kelley
2022-10-23 12:16:58 -07:00
committed by GitHub
13 changed files with 696 additions and 203 deletions
-22
View File
@@ -1,22 +0,0 @@
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const rel_opts = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
const c_obj = b.addObject("cfuncs", null);
c_obj.addCSourceFile("cfuncs.c", &[_][]const u8{"-std=c99"});
c_obj.setBuildMode(rel_opts);
c_obj.linkSystemLibrary("c");
c_obj.target = target;
const main = b.addTest("main.zig");
main.setBuildMode(rel_opts);
main.addObject(c_obj);
main.target = target;
const test_step = b.step("test", "Test the program");
test_step.dependOn(&main.step);
b.default_step.dependOn(test_step);
}
-24
View File
@@ -1,24 +0,0 @@
const std = @import("std");
const Builder = std.build.Builder;
pub fn build(b: *Builder) void {
const rel_opts = b.standardReleaseOptions();
const target: std.zig.CrossTarget = .{ .cpu_arch = .wasm32, .os_tag = .wasi };
b.use_stage1 = false;
const c_obj = b.addObject("cfuncs", null);
c_obj.addCSourceFile("cfuncs.c", &[_][]const u8{"-std=c99"});
c_obj.setBuildMode(rel_opts);
c_obj.linkSystemLibrary("c");
c_obj.setTarget(target);
const main = b.addTest("main.zig");
main.setBuildMode(rel_opts);
main.addObject(c_obj);
main.setTarget(target);
const test_step = b.step("test", "Test the program");
test_step.dependOn(&main.step);
b.default_step.dependOn(test_step);
}
+86 -17
View File
@@ -1,8 +1,8 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <complex.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
void zig_panic();
@@ -12,6 +12,14 @@ static void assert_or_panic(bool ok) {
}
}
#if defined __powerpc__ && !defined _ARCH_PPC64
# define ZIG_PPC32
#endif
#if defined __riscv && defined _ILP32
# define ZIG_RISCV32
#endif
#ifdef __i386__
# define ZIG_NO_I128
#endif
@@ -24,6 +32,14 @@ static void assert_or_panic(bool ok) {
# define ZIG_NO_I128
#endif
#ifdef ZIG_PPC32
# define ZIG_NO_I128
#endif
#ifdef ZIG_RISCV32
# define ZIG_NO_I128
#endif
#ifdef __i386__
# define ZIG_NO_COMPLEX
#endif
@@ -32,6 +48,18 @@ static void assert_or_panic(bool ok) {
# define ZIG_NO_COMPLEX
#endif
#ifdef __arm__
# define ZIG_NO_COMPLEX
#endif
#ifdef __powerpc__
# define ZIG_NO_COMPLEX
#endif
#ifdef __riscv
# define ZIG_NO_COMPLEX
#endif
#ifndef ZIG_NO_I128
struct i128 {
__int128 value;
@@ -206,7 +234,7 @@ void run_c_tests(void) {
zig_longdouble(12.34l);
zig_five_floats(1.0f, 2.0f, 3.0f, 4.0f, 5.0f);
zig_ptr((void*)0xdeadbeefL);
zig_ptr((void *)0xdeadbeefL);
zig_bool(true);
@@ -249,14 +277,15 @@ void run_c_tests(void) {
}
#endif
#if !defined __mips__ && !defined __riscv
#if !defined __mips__ && !defined ZIG_PPC32
{
struct BigStruct s = {1, 2, 3, 4, 5};
zig_big_struct(s);
}
#endif
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
!defined ZIG_PPC32 && !defined _ARCH_PPC64
{
struct SmallStructInts s = {1, 2, 3, 4};
zig_small_struct_ints(s);
@@ -281,28 +310,30 @@ void run_c_tests(void) {
zig_small_packed_struct(s);
}
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
!defined ZIG_PPC32 && !defined _ARCH_PPC64
{
struct SplitStructInts s = {1234, 100, 1337};
zig_split_struct_ints(s);
}
#endif
#if !defined __arm__ && !defined __riscv
#if !defined __arm__ && !defined ZIG_PPC32 && !defined _ARCH_PPC64
{
struct MedStructMixed s = {1234, 100.0f, 1337.0f};
zig_med_struct_mixed(s);
}
#endif
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && !defined __riscv
#if !defined __i386__ && !defined __arm__ && !defined __mips__ && \
!defined ZIG_PPC32 && !defined _ARCH_PPC64
{
struct SplitStructMixed s = {1234, 100, 1337.0f};
zig_split_struct_mixed(s);
}
#endif
#if !defined __mips__ && !defined __riscv
#if !defined __mips__ && !defined ZIG_PPC32
{
struct BigStruct s = {30, 31, 32, 33, 34};
struct BigStruct res = zig_big_struct_both(s);
@@ -314,7 +345,7 @@ void run_c_tests(void) {
}
#endif
#ifndef __riscv
#if !defined ZIG_PPC32 && !defined _ARCH_PPC64
{
struct Rect r1 = {1, 21, 16, 4};
struct Rect r2 = {178, 189, 21, 15};
@@ -322,7 +353,7 @@ void run_c_tests(void) {
}
#endif
#if !defined __mips__ && !defined __riscv
#if !defined __mips__ && !defined ZIG_PPC32
{
struct FloatRect r1 = {1, 21, 16, 4};
struct FloatRect r2 = {178, 189, 21, 15};
@@ -335,9 +366,7 @@ void run_c_tests(void) {
assert_or_panic(zig_ret_u8() == 0xff);
assert_or_panic(zig_ret_u16() == 0xffff);
#ifndef __riscv
assert_or_panic(zig_ret_u32() == 0xffffffff);
#endif
assert_or_panic(zig_ret_u64() == 0xffffffffffffffff);
assert_or_panic(zig_ret_i8() == -1);
@@ -404,7 +433,7 @@ void c_long_double(long double x) {
}
void c_ptr(void *x) {
assert_or_panic(x == (void*)0xdeadbeefL);
assert_or_panic(x == (void *)0xdeadbeefL);
}
void c_bool(bool x) {
@@ -672,7 +701,7 @@ void c_struct_with_array(StructWithArray x) {
}
StructWithArray c_ret_struct_with_array() {
return (StructWithArray) { 4, {}, 155 };
return (StructWithArray){4, {}, 155};
}
typedef struct {
@@ -701,3 +730,43 @@ FloatArrayStruct c_ret_float_array_struct() {
x.size.height = 4;
return x;
}
typedef uint32_t SmallVec __attribute__((vector_size(2 * sizeof(uint32_t))));
void c_small_vec(SmallVec vec) {
assert_or_panic(vec[0] == 1);
assert_or_panic(vec[1] == 2);
}
SmallVec c_ret_small_vec(void) {
return (SmallVec){3, 4};
}
typedef size_t BigVec __attribute__((vector_size(8 * sizeof(size_t))));
void c_big_vec(BigVec vec) {
assert_or_panic(vec[0] == 1);
assert_or_panic(vec[1] == 2);
assert_or_panic(vec[2] == 3);
assert_or_panic(vec[3] == 4);
assert_or_panic(vec[4] == 5);
assert_or_panic(vec[5] == 6);
assert_or_panic(vec[6] == 7);
assert_or_panic(vec[7] == 8);
}
BigVec c_ret_big_vec(void) {
return (BigVec){9, 10, 11, 12, 13, 14, 15, 16};
}
typedef struct {
float x, y;
} Vector2;
void c_ptr_size_float_struct(Vector2 vec) {
assert_or_panic(vec.x == 1);
assert_or_panic(vec.y == 2);
}
Vector2 c_ret_ptr_size_float_struct(void) {
return (Vector2){3, 4};
}
+104 -44
View File
@@ -3,7 +3,7 @@ const builtin = @import("builtin");
const print = std.debug.print;
const expect = std.testing.expect;
const has_i128 = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isARM() and
!builtin.cpu.arch.isMIPS();
!builtin.cpu.arch.isMIPS() and !builtin.cpu.arch.isPPC();
extern fn run_c_tests() void;
@@ -112,6 +112,9 @@ test "C ABI floats" {
}
test "C ABI long double" {
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
c_long_double(12.34);
}
@@ -167,7 +170,8 @@ extern fn c_cmultd_comp(a_r: f64, a_i: f64, b_r: f64, b_i: f64) ComplexDouble;
extern fn c_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat;
extern fn c_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble;
const complex_abi_compatible = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isMIPS();
const complex_abi_compatible = builtin.cpu.arch != .i386 and !builtin.cpu.arch.isMIPS() and
!builtin.cpu.arch.isARM() and !builtin.cpu.arch.isPPC() and !builtin.cpu.arch.isRISCV();
test "C ABI complex float" {
if (!complex_abi_compatible) return error.SkipZigTest;
@@ -177,8 +181,8 @@ test "C ABI complex float" {
const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };
const z = c_cmultf(a, b);
expect(z.real == 1.5) catch @panic("test failure: zig_complex_float 1");
expect(z.imag == 13.5) catch @panic("test failure: zig_complex_float 2");
try expect(z.real == 1.5);
try expect(z.imag == 13.5);
}
test "C ABI complex float by component" {
@@ -188,8 +192,8 @@ test "C ABI complex float by component" {
const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };
const z2 = c_cmultf_comp(a.real, a.imag, b.real, b.imag);
expect(z2.real == 1.5) catch @panic("test failure: zig_complex_float 3");
expect(z2.imag == 13.5) catch @panic("test failure: zig_complex_float 4");
try expect(z2.real == 1.5);
try expect(z2.imag == 13.5);
}
test "C ABI complex double" {
@@ -199,8 +203,8 @@ test "C ABI complex double" {
const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };
const z = c_cmultd(a, b);
expect(z.real == 1.5) catch @panic("test failure: zig_complex_double 1");
expect(z.imag == 13.5) catch @panic("test failure: zig_complex_double 2");
try expect(z.real == 1.5);
try expect(z.imag == 13.5);
}
test "C ABI complex double by component" {
@@ -210,8 +214,8 @@ test "C ABI complex double by component" {
const b = ComplexDouble{ .real = 11.3, .imag = -1.5 };
const z = c_cmultd_comp(a.real, a.imag, b.real, b.imag);
expect(z.real == 1.5) catch @panic("test failure: zig_complex_double 3");
expect(z.imag == 13.5) catch @panic("test failure: zig_complex_double 4");
try expect(z.real == 1.5);
try expect(z.imag == 13.5);
}
export fn zig_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat {
@@ -261,7 +265,7 @@ extern fn c_big_struct(BigStruct) void;
test "C ABI big struct" {
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
var s = BigStruct{
.a = 1,
@@ -287,7 +291,7 @@ const BigUnion = extern union {
extern fn c_big_union(BigUnion) void;
test "C ABI big union" {
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
var x = BigUnion{
.a = BigStruct{
@@ -320,9 +324,9 @@ extern fn c_ret_med_struct_mixed() MedStructMixed;
test "C ABI medium struct of ints and floats" {
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
var s = MedStructMixed{
.a = 1234,
@@ -331,9 +335,9 @@ test "C ABI medium struct of ints and floats" {
};
c_med_struct_mixed(s);
var s2 = c_ret_med_struct_mixed();
expect(s2.a == 1234) catch @panic("test failure");
expect(s2.b == 100.0) catch @panic("test failure");
expect(s2.c == 1337.0) catch @panic("test failure");
try expect(s2.a == 1234);
try expect(s2.b == 100.0);
try expect(s2.c == 1337.0);
}
export fn zig_med_struct_mixed(x: MedStructMixed) void {
@@ -353,9 +357,9 @@ extern fn c_ret_small_struct_ints() SmallStructInts;
test "C ABI small struct of ints" {
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
var s = SmallStructInts{
.a = 1,
@@ -365,10 +369,10 @@ test "C ABI small struct of ints" {
};
c_small_struct_ints(s);
var s2 = c_ret_small_struct_ints();
expect(s2.a == 1) catch @panic("test failure");
expect(s2.b == 2) catch @panic("test failure");
expect(s2.c == 3) catch @panic("test failure");
expect(s2.d == 4) catch @panic("test failure");
try expect(s2.a == 1);
try expect(s2.b == 2);
try expect(s2.c == 3);
try expect(s2.d == 4);
}
export fn zig_small_struct_ints(x: SmallStructInts) void {
@@ -435,9 +439,9 @@ extern fn c_split_struct_ints(SplitStructInt) void;
test "C ABI split struct of ints" {
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
var s = SplitStructInt{
.a = 1234,
@@ -463,9 +467,9 @@ extern fn c_ret_split_struct_mixed() SplitStructMixed;
test "C ABI split struct of ints and floats" {
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
var s = SplitStructMixed{
.a = 1234,
@@ -474,9 +478,9 @@ test "C ABI split struct of ints and floats" {
};
c_split_struct_mixed(s);
var s2 = c_ret_split_struct_mixed();
expect(s2.a == 1234) catch @panic("test failure");
expect(s2.b == 100) catch @panic("test failure");
expect(s2.c == 1337.0) catch @panic("test failure");
try expect(s2.a == 1234);
try expect(s2.b == 100);
try expect(s2.c == 1337.0);
}
export fn zig_split_struct_mixed(x: SplitStructMixed) void {
@@ -492,7 +496,7 @@ extern fn c_multiple_struct_floats(FloatRect, FloatRect) void;
test "C ABI sret and byval together" {
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
var s = BigStruct{
.a = 1,
@@ -543,9 +547,9 @@ const Vector5 = extern struct {
extern fn c_big_struct_floats(Vector5) void;
test "C ABI structs of floats as parameter" {
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
var v3 = Vector3{
.x = 3.0,
@@ -584,7 +588,8 @@ export fn zig_multiple_struct_ints(x: Rect, y: Rect) void {
}
test "C ABI structs of ints as multiple parameters" {
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
var r1 = Rect{
.left = 1,
@@ -621,7 +626,7 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
test "C ABI structs of floats as multiple parameters" {
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
var r1 = FloatRect{
.left = 1,
@@ -725,15 +730,15 @@ extern fn c_ret_struct_with_array() StructWithArray;
test "Struct with array as padding." {
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isARM()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });
var x = c_ret_struct_with_array();
try std.testing.expect(x.a == 4);
try std.testing.expect(x.b == 155);
try expect(x.a == 4);
try expect(x.b == 155);
}
const FloatArrayStruct = extern struct {
@@ -752,7 +757,7 @@ extern fn c_ret_float_array_struct() FloatArrayStruct;
test "Float array like struct" {
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
c_float_array_struct(.{
.origin = .{
@@ -766,8 +771,63 @@ test "Float array like struct" {
});
var x = c_ret_float_array_struct();
try std.testing.expect(x.origin.x == 1);
try std.testing.expect(x.origin.y == 2);
try std.testing.expect(x.size.width == 3);
try std.testing.expect(x.size.height == 4);
try expect(x.origin.x == 1);
try expect(x.origin.y == 2);
try expect(x.size.width == 3);
try expect(x.size.height == 4);
}
const SmallVec = @Vector(2, u32);
extern fn c_small_vec(SmallVec) void;
extern fn c_ret_small_vec() SmallVec;
test "small simd vector" {
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
c_small_vec(.{ 1, 2 });
var x = c_ret_small_vec();
try expect(x[0] == 3);
try expect(x[1] == 4);
}
const BigVec = @Vector(8, usize);
extern fn c_big_vec(BigVec) void;
extern fn c_ret_big_vec() BigVec;
test "big simd vector" {
if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
c_big_vec(.{ 1, 2, 3, 4, 5, 6, 7, 8 });
var x = c_ret_big_vec();
try expect(x[0] == 9);
try expect(x[1] == 10);
try expect(x[2] == 11);
try expect(x[3] == 12);
try expect(x[4] == 13);
try expect(x[5] == 14);
try expect(x[6] == 15);
try expect(x[7] == 16);
}
const Vector2 = extern struct { x: f32, y: f32 };
extern fn c_ptr_size_float_struct(Vector2) void;
extern fn c_ret_ptr_size_float_struct() Vector2;
test "C ABI pointer sized float struct" {
if (builtin.cpu.arch == .i386) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
c_ptr_size_float_struct(.{ .x = 1, .y = 2 });
var x = c_ret_ptr_size_float_struct();
try expect(x.x == 3);
try expect(x.y == 4);
}
-17
View File
@@ -44,23 +44,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
if (builtin.os.tag != .wasi) {
cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{});
}
// C ABI compatibility issue: https://github.com/ziglang/zig/issues/1481
if (builtin.cpu.arch == .x86_64) {
if (builtin.zig_backend == .stage1 or builtin.zig_backend == .stage2_llvm) {
cases.addBuildFile("test/c_abi/build.zig", .{});
}
}
if (builtin.cpu.arch.isAARCH64() and builtin.zig_backend == .stage2_llvm) {
cases.addBuildFile("test/c_abi/build.zig", .{});
}
if (builtin.cpu.arch == .i386 and builtin.zig_backend == .stage2_llvm) {
cases.addBuildFile("test/c_abi/build.zig", .{});
}
// C ABI tests only pass for the Wasm target when using stage2
cases.addBuildFile("test/c_abi/build_wasm.zig", .{
.requires_stage2 = true,
.use_emulation = true,
});
cases.addBuildFile("test/standalone/c_compiler/build.zig", .{
.build_modes = true,
+79
View File
@@ -1268,3 +1268,82 @@ fn printInvocation(args: []const []const u8) void {
}
std.debug.print("\n", .{});
}
const c_abi_targets = [_]CrossTarget{
.{},
.{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .i386,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .aarch64,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .arm,
.os_tag = .linux,
.abi = .musleabihf,
},
.{
.cpu_arch = .mips,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .riscv64,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .wasm32,
.os_tag = .wasi,
.abi = .musl,
},
.{
.cpu_arch = .powerpc,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .powerpc64le,
.os_tag = .linux,
.abi = .musl,
},
};
pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool) *build.Step {
const step = b.step("test-c-abi", "Run the C ABI tests");
for (c_abi_targets) |c_abi_target| {
if (skip_non_native and !c_abi_target.isNative())
continue;
const test_step = b.addTest("test/c_abi/main.zig");
test_step.setTarget(c_abi_target);
if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) {
// TODO NativeTargetInfo insists on dynamically linking musl
// for some reason?
test_step.target_info.dynamic_linker.max_byte = null;
}
test_step.linkLibC();
test_step.addCSourceFile("test/c_abi/cfuncs.c", &.{"-std=c99"});
const triple_prefix = c_abi_target.zigTriple(b.allocator) catch unreachable;
test_step.setNamePrefix(b.fmt("{s}-{s} ", .{
"test-c-abi",
triple_prefix,
}));
test_step.use_stage1 = false;
step.dependOn(&test_step.step);
}
return step;
}