allo system compiler
This commit is contained in:
55
build.zig
55
build.zig
@@ -1,20 +1,8 @@
|
||||
const std = @import("std");
|
||||
|
||||
const c_lib = &[_][]const u8{ "tokenizer.c", "ast.c", "zig1.c" };
|
||||
const all_c_files = c_lib ++ &[_][]const u8{"main.c"};
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "tokenizer",
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
lib.addCSourceFiles(.{
|
||||
.files = c_lib,
|
||||
.flags = &[_][]const u8{
|
||||
const c_lib_files = &[_][]const u8{ "tokenizer.c", "ast.c", "zig1.c" };
|
||||
const all_c_files = c_lib_files ++ &[_][]const u8{"main.c"};
|
||||
const cflags = &[_][]const u8{
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wvla",
|
||||
@@ -32,9 +20,42 @@ pub fn build(b: *std.Build) void {
|
||||
"-fstack-protector-all",
|
||||
"-Wimplicit-fallthrough",
|
||||
//"-D_FORTIFY_SOURCE=2", // consider when optimization flags are enabled
|
||||
},
|
||||
};
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "tokenizer",
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
lib.addIncludePath(b.path("."));
|
||||
|
||||
const cc = b.option([]const u8, "cc", "C compiler") orelse "zig";
|
||||
|
||||
if (std.mem.eql(u8, cc, "zig"))
|
||||
lib.addCSourceFiles(.{ .files = c_lib_files, .flags = cflags })
|
||||
else for (c_lib_files) |cfile| {
|
||||
const objfile = try std.fmt.allocPrint(
|
||||
b.allocator,
|
||||
"{s}.o",
|
||||
.{cfile[0 .. cfile.len - 2]},
|
||||
);
|
||||
const cc1 = b.addSystemCommand(&.{cc});
|
||||
cc1.addArgs(cflags);
|
||||
cc1.addArg("-g");
|
||||
cc1.addArgs(switch (optimize) {
|
||||
.Debug => &.{"-O0"},
|
||||
.ReleaseFast, .ReleaseSafe => &.{"-O3"}, // TODO ubsan?
|
||||
.ReleaseSmall => &.{"-Os"},
|
||||
});
|
||||
cc1.addArg("-c");
|
||||
cc1.addFileArg(b.path(cfile));
|
||||
cc1.addArg("-o");
|
||||
const obj = cc1.addOutputFileArg(objfile);
|
||||
lib.addObjectFile(obj);
|
||||
}
|
||||
lib.linkLibC();
|
||||
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
|
||||
Reference in New Issue
Block a user