mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-26 13:01:34 +03:00
@@ -1,13 +0,0 @@
|
||||
const b = @cDefine("foo", "1");
|
||||
const c = @cImport({
|
||||
_ = @TypeOf(@cDefine("foo", "1"));
|
||||
});
|
||||
const d = @cImport({
|
||||
_ = @cImport(@cDefine("foo", "1"));
|
||||
});
|
||||
|
||||
// error
|
||||
//
|
||||
// :1:11: error: C define valid only inside C import block
|
||||
// :3:17: error: C define valid only inside C import block
|
||||
// :6:9: error: cannot nest @cImport
|
||||
@@ -1,13 +0,0 @@
|
||||
const c = @cImport({
|
||||
if (foo == 0) {}
|
||||
});
|
||||
extern var foo: i32;
|
||||
export fn entry() void {
|
||||
_ = c;
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :2:13: error: unable to evaluate comptime expression
|
||||
// :2:9: note: operation is runtime due to this operand
|
||||
// :1:11: note: operand to '@cImport' is evaluated at comptime
|
||||
@@ -36,9 +36,6 @@
|
||||
.compile_asm = .{
|
||||
.path = "compile_asm",
|
||||
},
|
||||
.issue_794 = .{
|
||||
.path = "issue_794",
|
||||
},
|
||||
.issue_5825 = .{
|
||||
.path = "issue_5825",
|
||||
},
|
||||
@@ -84,9 +81,6 @@
|
||||
.dep_shared_builtin = .{
|
||||
.path = "dep_shared_builtin",
|
||||
},
|
||||
.dep_lazypath = .{
|
||||
.path = "dep_lazypath",
|
||||
},
|
||||
.dirname = .{
|
||||
.path = "dirname",
|
||||
},
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const test_step = b.step("test", "Test it");
|
||||
b.default_step = test_step;
|
||||
|
||||
const optimize: std.builtin.OptimizeMode = .Debug;
|
||||
|
||||
{
|
||||
const write_files = b.addWriteFiles();
|
||||
const generated_main_c = write_files.add("main.c", "");
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "test",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = null,
|
||||
.target = b.graph.host,
|
||||
.optimize = optimize,
|
||||
}),
|
||||
});
|
||||
exe.root_module.addCSourceFiles(.{
|
||||
.root = generated_main_c.dirname(),
|
||||
.files = &.{"main.c"},
|
||||
});
|
||||
b.step("csourcefiles", "").dependOn(&exe.step);
|
||||
test_step.dependOn(&exe.step);
|
||||
}
|
||||
{
|
||||
const write_files = b.addWriteFiles();
|
||||
const dir = write_files.addCopyDirectory(b.path("inc"), "", .{});
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "test",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("inctest.zig"),
|
||||
.target = b.graph.host,
|
||||
.optimize = optimize,
|
||||
}),
|
||||
});
|
||||
exe.root_module.addIncludePath(dir);
|
||||
b.step("copydir", "").dependOn(&exe.step);
|
||||
test_step.dependOn(&exe.step);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
#define foo_value 42
|
||||
@@ -1,8 +0,0 @@
|
||||
const std = @import("std");
|
||||
const c = @cImport({
|
||||
@cInclude("foo.h");
|
||||
});
|
||||
comptime {
|
||||
std.debug.assert(c.foo_value == 42);
|
||||
}
|
||||
pub fn main() void {}
|
||||
@@ -180,12 +180,44 @@ pub fn build(b: *std.Build) void {
|
||||
}
|
||||
}
|
||||
|
||||
const malloc_translation = b.addTranslateC(.{
|
||||
.root_source_file = b.path("include_malloc.h"),
|
||||
.target = target,
|
||||
.optimize = .Debug,
|
||||
.link_libc = true,
|
||||
});
|
||||
const stdlib_translation = b.addTranslateC(.{
|
||||
.root_source_file = b.path("include_stdlib.h"),
|
||||
.target = target,
|
||||
.optimize = .Debug,
|
||||
.link_libc = true,
|
||||
});
|
||||
const string_translation = b.addTranslateC(.{
|
||||
.root_source_file = b.path("include_string.h"),
|
||||
.target = target,
|
||||
.optimize = .Debug,
|
||||
.link_libc = true,
|
||||
});
|
||||
const exe = b.addExecutable(.{
|
||||
.name = t,
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("glibc_runtime_check.zig"),
|
||||
.target = target,
|
||||
.link_libc = true,
|
||||
.imports = &.{
|
||||
.{
|
||||
.name = "malloc.h",
|
||||
.module = malloc_translation.createModule(),
|
||||
},
|
||||
.{
|
||||
.name = "stdlib.h",
|
||||
.module = stdlib_translation.createModule(),
|
||||
},
|
||||
.{
|
||||
.name = "string.h",
|
||||
.module = string_translation.createModule(),
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
// We disable UBSAN for these tests as the libc being tested here is
|
||||
|
||||
@@ -8,17 +8,9 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const c_malloc = @cImport(
|
||||
@cInclude("malloc.h"), // for reallocarray
|
||||
);
|
||||
|
||||
const c_stdlib = @cImport(
|
||||
@cInclude("stdlib.h"), // for atexit
|
||||
);
|
||||
|
||||
const c_string = @cImport(
|
||||
@cInclude("string.h"), // for strlcpy
|
||||
);
|
||||
const c_malloc = @import("malloc.h"); // for reallocarray
|
||||
const c_stdlib = @import("stdlib.h"); // for atexit
|
||||
const c_string = @import("string.h"); // for strlcpy
|
||||
|
||||
// Version of glibc this test is being built to run against
|
||||
const glibc_ver = builtin.os.versionRange().gnuLibCVersion().?;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#include <malloc.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <stdlib.h>
|
||||
@@ -0,0 +1 @@
|
||||
#include <string.h>
|
||||
@@ -1 +0,0 @@
|
||||
#define NUMBER 1234
|
||||
@@ -1,17 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const test_step = b.step("test", "Test it");
|
||||
b.default_step = test_step;
|
||||
|
||||
const test_artifact = b.addTest(.{ .root_module = b.createModule(.{
|
||||
.root_source_file = b.path("main.zig"),
|
||||
.target = b.graph.host,
|
||||
}) });
|
||||
test_artifact.root_module.addIncludePath(b.path("a_directory"));
|
||||
|
||||
// TODO: actually check the output
|
||||
_ = test_artifact.getEmittedBin();
|
||||
|
||||
test_step.dependOn(&test_artifact.step);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
const c = @cImport(@cInclude("foo.h"));
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
|
||||
test "c import" {
|
||||
try comptime testing.expect(c.NUMBER == 1234);
|
||||
}
|
||||
@@ -108,7 +108,6 @@ const cases = [_]Case{
|
||||
.os_tag = .freestanding,
|
||||
},
|
||||
},
|
||||
.{ .src_path = "issue_12471/main.zig" },
|
||||
.{ .src_path = "guess_number/main.zig" },
|
||||
.{ .src_path = "main_return_error/error_u8.zig" },
|
||||
.{ .src_path = "main_return_error/error_u8_non_zero.zig" },
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
const c = @cImport({
|
||||
@cDefine("FOO", "FOO");
|
||||
@cDefine("BAR", "FOO");
|
||||
|
||||
@cDefine("BAZ", "QUX");
|
||||
@cDefine("QUX", "QUX");
|
||||
});
|
||||
|
||||
pub fn main() u8 {
|
||||
_ = c;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user