diff --git a/GitRepoStep.zig b/GitRepoStep.zig index f7fe895..c7dac03 100644 --- a/GitRepoStep.zig +++ b/GitRepoStep.zig @@ -57,7 +57,7 @@ pub fn create(b: *std.build.Builder, opt: struct { .branch = opt.branch, .sha = opt.sha, .path = if (opt.path) |p| (b.allocator.dupe(u8, p) catch @panic("memory")) else (std.fs.path.resolve(b.allocator, &[_][]const u8{ - b.build_root, + b.build_root.path.?, "dep", name, })) catch @panic("memory"), @@ -140,7 +140,7 @@ fn checkSha(self: GitRepoStep) !void { "rev-parse", "HEAD", }, - .cwd = self.builder.build_root, + .cwd = self.builder.build_root.path.?, .env_map = self.builder.env_map, }) catch |e| break :blk .{ .failed = e }; try std.io.getStdErr().writer().writeAll(result.stderr); @@ -183,7 +183,7 @@ fn run(builder: *std.build.Builder, argv: []const []const u8) !void { child.stdin_behavior = .Ignore; child.stdout_behavior = .Inherit; child.stderr_behavior = .Inherit; - child.cwd = builder.build_root; + child.cwd = builder.build_root.path.?; child.env_map = builder.env_map; try child.spawn(); diff --git a/awkbuild.zig b/awkbuild.zig index 03b9cb6..9992f3c 100644 --- a/awkbuild.zig +++ b/awkbuild.zig @@ -15,32 +15,30 @@ pub fn addAwk( .branch = null, }); -// const config_step = b.addWriteFile( -// b.pathJoin(&.{repo.path, "src", "config.h"}), -// "#define VERSION \"1.0\"", -// ); -// config_step.step.dependOn(&repo.step); + // const config_step = b.addWriteFile( + // b.pathJoin(&.{repo.path, "src", "config.h"}), + // "#define VERSION \"1.0\"", + // ); + // config_step.step.dependOn(&repo.step); - const exe = b.addExecutable("awk", null); - exe.setTarget(target); - exe.setBuildMode(mode); + const exe = b.addExecutable(.{ .name = "awk", .target = target, .optimize = mode }); _ = b.addInstallArtifact(exe); //exe.install(); exe.step.dependOn(&repo.step); -// exe.step.dependOn(&config_step.step); + // exe.step.dependOn(&config_step.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - const sources = [_][]const u8 { -// "main.c", "cmph.c", "hash.c", "chm.c", "bmz.c", "bmz8.c", "brz.c", "fch.c", -// "bdz.c", "bdz_ph.c", "chd_ph.c", "chd.c", "jenkins_hash.c", "graph.c", "vqueue.c", -// "buffer_manager.c", "fch_buckets.c", "miller_rabin.c", "compressed_seq.c", -// "compressed_rank.c", "buffer_entry.c", "select.c", "cmph_structs.c", + const sources = [_][]const u8{ + // "main.c", "cmph.c", "hash.c", "chm.c", "bmz.c", "bmz8.c", "brz.c", "fch.c", + // "bdz.c", "bdz_ph.c", "chd_ph.c", "chd.c", "jenkins_hash.c", "graph.c", "vqueue.c", + // "buffer_manager.c", "fch_buckets.c", "miller_rabin.c", "compressed_seq.c", + // "compressed_rank.c", "buffer_entry.c", "select.c", "cmph_structs.c", }; for (sources) |src| { - files.append(b.pathJoin(&.{repo_path, "src", src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, "src", src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c11", }); @@ -61,4 +59,3 @@ pub fn addAwk( return exe; } - diff --git a/build.zig b/build.zig index 9f0f3f8..c93e366 100644 --- a/build.zig +++ b/build.zig @@ -5,22 +5,23 @@ const luabuild = @import("luabuild.zig"); const awkbuild = @import("awkbuild.zig"); const gnumakebuild = @import("gnumakebuild.zig"); -pub fn build(b: *std.build.Builder) void { +pub fn build(b: *std.Build) void { const trace_enabled = b.option(bool, "trace", "enable libc tracing") orelse false; { - const exe = b.addExecutable("genheaders", "src" ++ std.fs.path.sep_str ++ "genheaders.zig"); + const exe = b.addExecutable(.{ + .name = "genheaders", + .root_source_file = .{ .path = "src" ++ std.fs.path.sep_str ++ "genheaders.zig" }, + }); const run = exe.run(); run.addArg(b.pathFromRoot("capi.txt")); b.step("genheaders", "Generate C Headers").dependOn(&run.step); } const target = b.standardTargetOptions(.{}); - const mode = b.standardReleaseOptions(); + const mode = b.standardOptimizeOption(.{}); - const zig_start = libcbuild.addZigStart(b); - zig_start.setTarget(target); - zig_start.setBuildMode(mode); + const zig_start = libcbuild.addZigStart(b, target, mode); zig_start.install(); b.step("start", "").dependOn(&zig_start.install_step.?.step); @@ -30,9 +31,8 @@ pub fn build(b: *std.build.Builder) void { .start = .ziglibc, .trace = trace_enabled, .target = target, + .optimize = mode, }); - libc_full_static.setTarget(target); - libc_full_static.setBuildMode(mode); libc_full_static.install(); const libc_full_shared = libcbuild.addLibc(b, .{ .variant = .full, @@ -40,9 +40,8 @@ pub fn build(b: *std.build.Builder) void { .start = .ziglibc, .trace = trace_enabled, .target = target, + .optimize = mode, }); - libc_full_shared.setTarget(target); - libc_full_shared.setBuildMode(mode); libc_full_shared.install(); b.step("libc-full-shared", "").dependOn(&libc_full_shared.install_step.?.step); // TODO: create a specs file? @@ -54,9 +53,8 @@ pub fn build(b: *std.build.Builder) void { .start = .ziglibc, .trace = trace_enabled, .target = target, + .optimize = mode, }); - libc_only_std_static.setTarget(target); - libc_only_std_static.setBuildMode(mode); libc_only_std_static.install(); const libc_only_std_shared = libcbuild.addLibc(b, .{ .variant = .only_std, @@ -64,9 +62,8 @@ pub fn build(b: *std.build.Builder) void { .start = .ziglibc, .trace = trace_enabled, .target = target, + .optimize = mode, }); - libc_only_std_shared.setTarget(target); - libc_only_std_shared.setBuildMode(mode); libc_only_std_shared.install(); const libc_only_posix = libcbuild.addLibc(b, .{ @@ -75,9 +72,8 @@ pub fn build(b: *std.build.Builder) void { .start = .ziglibc, .trace = trace_enabled, .target = target, + .optimize = mode, }); - libc_only_posix.setTarget(target); - libc_only_posix.setBuildMode(mode); libc_only_posix.install(); const libc_only_linux = libcbuild.addLibc(b, .{ @@ -86,9 +82,8 @@ pub fn build(b: *std.build.Builder) void { .start = .ziglibc, .trace = trace_enabled, .target = target, + .optimize = mode, }); - libc_only_linux.setTarget(target); - libc_only_linux.setBuildMode(mode); libc_only_linux.install(); const libc_only_gnu = libcbuild.addLibc(b, .{ @@ -97,16 +92,18 @@ pub fn build(b: *std.build.Builder) void { .start = .ziglibc, .trace = trace_enabled, .target = target, + .optimize = mode, }); - libc_only_gnu.setTarget(target); - libc_only_gnu.setBuildMode(mode); libc_only_gnu.install(); const test_step = b.step("test", "Run unit tests"); - const test_env_exe = b.addExecutable("testenv", "test" ++ std.fs.path.sep_str ++ "testenv.zig"); - test_env_exe.setTarget(target); - test_env_exe.setBuildMode(mode); + const test_env_exe = b.addExecutable(.{ + .name = "testenv", + .root_source_file = .{ .path = "test" ++ std.fs.path.sep_str ++ "testenv.zig" }, + .target = target, + .optimize = mode, + }); { const exe = addTest("hello", b, target, mode, libc_only_std_static, zig_start); @@ -177,7 +174,7 @@ pub fn build(b: *std.build.Builder) void { } { const run = exe.run(); - run.addArgs(&.{ "-a" }); + run.addArgs(&.{"-a"}); run.stdout_action = .{ .expect_exact = "aflag=1, c_arg='(null)'\n" }; test_step.dependOn(&run.step); } @@ -226,14 +223,17 @@ fn addTest( libc_only_std_static: *std.build.LibExeObjStep, zig_start: *std.build.LibExeObjStep, ) *std.build.LibExeObjStep { - const exe = b.addExecutable(name, "test" ++ std.fs.path.sep_str ++ name ++ ".c"); - exe.addCSourceFiles(&.{"test" ++ std.fs.path.sep_str ++ "expect.c"}, &[_][]const u8 { }); + const exe = b.addExecutable(.{ + .name = name, + .root_source_file = .{ .path = "test" ++ std.fs.path.sep_str ++ name ++ ".c" }, + .target = target, + .optimize = mode, + }); + exe.addCSourceFiles(&.{"test" ++ std.fs.path.sep_str ++ "expect.c"}, &[_][]const u8{}); exe.addIncludePath("inc" ++ std.fs.path.sep_str ++ "libc"); exe.addIncludePath("inc" ++ std.fs.path.sep_str ++ "posix"); exe.linkLibrary(libc_only_std_static); exe.linkLibrary(zig_start); - exe.setTarget(target); - exe.setBuildMode(mode); // TODO: should libc_only_std_static and zig_start be able to add library dependencies? if (target.getOs().tag == .windows) { exe.linkSystemLibrary("ntdll"); @@ -259,26 +259,32 @@ fn addLibcTest( const libc_test_step = b.step("libc-test", "run tests from the libc-test project"); // inttypes - inline for (.{ "assert", "ctype", "errno", "main", "stdbool", "stddef", "string" } ) |name| { - const lib = b.addObject("libc-test-api-" ++ name, b.pathJoin(&.{libc_test_path, "src", "api", name ++ ".c"})); - lib.setTarget(target); - lib.setBuildMode(mode); + inline for (.{ "assert", "ctype", "errno", "main", "stdbool", "stddef", "string" }) |name| { + const lib = b.addObject(.{ + .name = "libc-test-api-" ++ name, + .root_source_file = .{ .path = b.pathJoin(&.{ libc_test_path, "src", "api", name ++ ".c" }) }, + .target = target, + .optimize = mode, + }); lib.addIncludePath("inc" ++ std.fs.path.sep_str ++ "libc"); lib.step.dependOn(&libc_test_repo.step); libc_test_step.dependOn(&lib.step); } - const libc_inc_path = b.pathJoin(&.{libc_test_path, "src", "common"}); - const common_src = &[_][]const u8 { - b.pathJoin(&.{libc_test_path, "src", "common", "print.c"}), + const libc_inc_path = b.pathJoin(&.{ libc_test_path, "src", "common" }); + const common_src = &[_][]const u8{ + b.pathJoin(&.{ libc_test_path, "src", "common", "print.c" }), }; // strtol, it seems there might be some disagreement between libc-test/glibc // about how strtoul interprets negative numbers, so leaving out strtol for now - inline for (.{ "argv", "basename", "clock_gettime", "string" } ) |name| { - const exe = b.addExecutable("libc-test-functional-" ++ name, b.pathJoin(&.{libc_test_path, "src", "functional", name ++ ".c"})); - exe.addCSourceFiles(common_src, &[_][]const u8 {}); - exe.setTarget(target); - exe.setBuildMode(mode); + inline for (.{ "argv", "basename", "clock_gettime", "string" }) |name| { + const exe = b.addExecutable(.{ + .name = "libc-test-functional-" ++ name, + .root_source_file = .{ .path = b.pathJoin(&.{ libc_test_path, "src", "functional", name ++ ".c" }) }, + .target = target, + .optimize = mode, + }); + exe.addCSourceFiles(common_src, &[_][]const u8{}); exe.step.dependOn(&libc_test_repo.step); exe.addIncludePath(libc_inc_path); exe.addIncludePath("inc" ++ std.fs.path.sep_str ++ "libc"); @@ -310,22 +316,24 @@ fn addTinyRegexCTests( }); const re_step = b.step("re-tests", "run the tiny-regex-c tests"); - inline for (&[_][]const u8 { "test1", "test3" }) |test_name| { - const exe = b.addExecutable("re" ++ test_name, null); - exe.setTarget(target); - exe.setBuildMode(mode); + inline for (&[_][]const u8{ "test1", "test3" }) |test_name| { + const exe = b.addExecutable(.{ + .name = "re" ++ test_name, + .target = target, + .optimize = mode, + }); //exe.install(); exe.step.dependOn(&repo.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - const sources = [_][]const u8 { + const sources = [_][]const u8{ "re.c", "tests" ++ std.fs.path.sep_str ++ test_name ++ ".c", }; for (sources) |src| { - files.append(b.pathJoin(&.{repo_path, src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c99", }); exe.addIncludePath(repo_path); @@ -361,9 +369,11 @@ fn addLua( .sha = "5d708c3f9cae12820e415d4f89c9eacbe2ab964b", .branch = "v5.4.4", }); - const lua_exe = b.addExecutable("lua", null); - lua_exe.setTarget(target); - lua_exe.setBuildMode(mode); + const lua_exe = b.addExecutable(.{ + .name = "lua", + .target = target, + .optimize = mode, + }); lua_exe.step.dependOn(&lua_repo.step); lua_exe.install(); const lua_repo_path = lua_repo.getPath(&lua_exe.step); @@ -426,30 +436,31 @@ fn addCmph( }); const config_step = b.addWriteFile( - b.pathJoin(&.{repo.path, "src", "config.h"}), + b.pathJoin(&.{ repo.path, "src", "config.h" }), "#define VERSION \"1.0\"", ); config_step.step.dependOn(&repo.step); - const exe = b.addExecutable("cmph", null); - exe.setTarget(target); - exe.setBuildMode(mode); + const exe = b.addExecutable(.{ + .name = "cmph", + .target = target, + .optimize = mode, + }); exe.install(); exe.step.dependOn(&repo.step); exe.step.dependOn(&config_step.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - const sources = [_][]const u8 { - "main.c", "cmph.c", "hash.c", "chm.c", "bmz.c", "bmz8.c", "brz.c", "fch.c", - "bdz.c", "bdz_ph.c", "chd_ph.c", "chd.c", "jenkins_hash.c", "graph.c", "vqueue.c", - "buffer_manager.c", "fch_buckets.c", "miller_rabin.c", "compressed_seq.c", - "compressed_rank.c", "buffer_entry.c", "select.c", "cmph_structs.c", + const sources = [_][]const u8{ + "main.c", "cmph.c", "hash.c", "chm.c", "bmz.c", "bmz8.c", "brz.c", "fch.c", + "bdz.c", "bdz_ph.c", "chd_ph.c", "chd.c", "jenkins_hash.c", "graph.c", "vqueue.c", "buffer_manager.c", + "fch_buckets.c", "miller_rabin.c", "compressed_seq.c", "compressed_rank.c", "buffer_entry.c", "select.c", "cmph_structs.c", }; for (sources) |src| { - files.append(b.pathJoin(&.{repo_path, "src", src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, "src", src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c11", }); @@ -485,8 +496,7 @@ fn addYacc( .branch = null, }); - const config_step = b.addWriteFile( - b.pathJoin(&.{repo.path, "config.h"}), + const config_step = b.addWriteFile(b.pathJoin(&.{ repo.path, "config.h" }), \\// for simplicity just don't supported __unused \\#define __unused \\// for simplicity we're just not supporting noreturn @@ -499,32 +509,33 @@ fn addYacc( \\ ); config_step.step.dependOn(&repo.step); - const gen_progname_step = b.addWriteFile( - b.pathJoin(&.{repo.path, "progname.c"}), + const gen_progname_step = b.addWriteFile(b.pathJoin(&.{ repo.path, "progname.c" }), \\// workaround __progname not defined, https://github.com/ibara/yacc/pull/1 \\char *__progname; \\ ); gen_progname_step.step.dependOn(&repo.step); - const exe = b.addExecutable("yacc", null); - exe.setTarget(target); - exe.setBuildMode(mode); + const exe = b.addExecutable(.{ + .name = "yacc", + .target = target, + .optimize = mode, + }); exe.install(); exe.step.dependOn(&repo.step); exe.step.dependOn(&config_step.step); exe.step.dependOn(&gen_progname_step.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - const sources = [_][]const u8 { - "closure.c", "error.c", "lalr.c", "lr0.c", "main.c", "mkpar.c", "output.c", "reader.c", + const sources = [_][]const u8{ + "closure.c", "error.c", "lalr.c", "lr0.c", "main.c", "mkpar.c", "output.c", "reader.c", "skeleton.c", "symtab.c", "verbose.c", "warshall.c", "portable.c", "progname.c", }; for (sources) |src| { - files.append(b.pathJoin(&.{repo_path, src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c90", }); @@ -560,20 +571,22 @@ fn addYabfc( .branch = null, }); - const exe = b.addExecutable("yabfc", null); - exe.setTarget(target); - exe.setBuildMode(mode); + const exe = b.addExecutable(.{ + .name = "yabfc", + .target = target, + .optimize = mode, + }); exe.install(); exe.step.dependOn(&repo.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - const sources = [_][]const u8 { + const sources = [_][]const u8{ "assembly.c", "elfHelper.c", "helpers.c", "optimize.c", "yabfc.c", }; for (sources) |src| { - files.append(b.pathJoin(&.{repo_path, src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c99", }); @@ -612,21 +625,23 @@ fn addSecretGame( .branch = null, }); - const exe = b.addExecutable("secret", null); - exe.setTarget(target); - exe.setBuildMode(mode); + const exe = b.addExecutable(.{ + .name = "secret", + .target = target, + .optimize = mode, + }); //exe.install(); _ = b.addInstallArtifact(exe); exe.step.dependOn(&repo.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - const sources = [_][]const u8 { + const sources = [_][]const u8{ "main.c", "inter.c", "input.c", "items.c", "rooms.c", "linenoise/linenoise.c", }; for (sources) |src| { - files.append(b.pathJoin(&.{repo_path, src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c90", }); diff --git a/busybox/build.zig b/busybox/build.zig index 2ddbf03..7a4d901 100644 --- a/busybox/build.zig +++ b/busybox/build.zig @@ -20,7 +20,7 @@ const BusyboxPrepStep = struct { const b = self.builder; std.log.warn("TODO: check config file timestamp to prevent unnecessary copy", .{}); - var src_dir = try std.fs.cwd().openDir(b.pathJoin(&.{ b.build_root, "busybox"}), .{}); + var src_dir = try std.fs.cwd().openDir(b.pathJoin(&.{ b.build_root.path.?, "busybox" }), .{}); defer src_dir.close(); var dst_dir = try std.fs.cwd().openDir(self.repo_path, .{}); defer dst_dir.close(); @@ -42,25 +42,27 @@ pub fn add( }); const prep = BusyboxPrepStep.create(b, repo); - - const exe = b.addExecutable("busybox", null); - exe.setTarget(target); - exe.setBuildMode(mode); + + const exe = b.addExecutable(.{ + .name = "busybox", + .target = target, + .optimize = mode, + }); //exe.install(); _ = b.addInstallArtifact(exe); exe.step.dependOn(&prep.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - const sources = [_][]const u8 { + const sources = [_][]const u8{ "editors/sed.c", }; for (sources) |src| { - files.append(b.pathJoin(&.{repo_path, src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c99", }); - exe.addIncludePath(b.pathJoin(&.{repo_path, "include"})); + exe.addIncludePath(b.pathJoin(&.{ repo_path, "include" })); exe.addIncludePath("inc/libc"); exe.addIncludePath("inc/posix"); diff --git a/gnumakebuild.zig b/gnumakebuild.zig index edcfba0..aa3d524 100644 --- a/gnumakebuild.zig +++ b/gnumakebuild.zig @@ -19,9 +19,8 @@ pub fn addGnuMake( config_step.* = std.build.Step.initNoOp(.custom, "configure GNU Make", b.allocator); // note: this MUST be the first dependency config_step.dependOn(&repo.step); - - const gen_config_h = b.addWriteFile( - b.pathJoin(&.{repo.path, "src", "config.h"}), + + const gen_config_h = b.addWriteFile(b.pathJoin(&.{ repo.path, "src", "config.h" }), \\/* Name of package */ \\#define PACKAGE "GNUMake" \\/* Define to the address where bug reports for this package should be sent. */ @@ -54,20 +53,22 @@ pub fn addGnuMake( \\ \\#define FILE_TIMESTAMP_HI_RES 0 \\/* not sure what this is, but default.c seems to need it */ - \\#define SCCS_GET "get" + \\#define SCCS_GET "get" \\ ); //\\#define __ptr_t char * //\\#define HAVE_GETOPT_H 1 //\\#define HAVE_ALLOCA 1 config_step.dependOn(&gen_config_h.step); -// gcc -DHAVE_CONFIG_H -Isrc -I./src -Ilib -I./lib -DLIBDIR=\"/usr/local/lib\" -DLOCALEDIR=\"/usr/local/share/locale\" -DMAKE_MAINTAINER_MODE -C -Wall -Wextra -Werror -Wwrite-strings -Wshadow -Wdeclaration-after-statement -Wbad-function-cast -Wformat-security -Wtype-limits -Wunused-but-set-parameter -Wlogical-op -Wpointer-arith -Wignored-qualifiers -Wformat-signedness -Wduplicated-cond -g -O2 -MT src/hash.o -MD -MP -MF $depbase.Tpo -c -o src/hash.o src/hash.c &&\ + // gcc -DHAVE_CONFIG_H -Isrc -I./src -Ilib -I./lib -DLIBDIR=\"/usr/local/lib\" -DLOCALEDIR=\"/usr/local/share/locale\" -DMAKE_MAINTAINER_MODE -C -Wall -Wextra -Werror -Wwrite-strings -Wshadow -Wdeclaration-after-statement -Wbad-function-cast -Wformat-security -Wtype-limits -Wunused-but-set-parameter -Wlogical-op -Wpointer-arith -Wignored-qualifiers -Wformat-signedness -Wduplicated-cond -g -O2 -MT src/hash.o -MD -MP -MF $depbase.Tpo -c -o src/hash.o src/hash.c &&\ + + // home/marler8997/zig/0.11.0-dev.12+ebf9ffd34/files/zig build-exe -cflags -std=c11 -- /home/marler8997/git/ziglibc/dep/make.git/src/ar.c /home/marler8997/git/ziglibc/dep/make.git/src/arscan.c /home/marler8997/git/ziglibc/dep/make.git/src/commands.c /home/marler8997/git/ziglibc/dep/make.git/src/default.c /home/marler8997/git/ziglibc/dep/make.git/src/dir.c /home/marler8997/git/ziglibc/dep/make.git/src/expand.c /home/marler8997/git/ziglibc/dep/make.git/src/file.c /home/marler8997/git/ziglibc/dep/make.git/src/function.c /home/marler8997/git/ziglibc/dep/make.git/src/getopt.c /home/marler8997/git/ziglibc/dep/make.git/src/getopt1.c /home/marler8997/git/ziglibc/dep/make.git/src/guile.c /home/marler8997/git/ziglibc/dep/make.git/src/hash.c /home/marler8997/git/ziglibc/dep/make.git/src/implicit.c /home/marler8997/git/ziglibc/dep/make.git/src/job.c /home/marler8997/git/ziglibc/dep/make.git/src/load.c /home/marler8997/git/ziglibc/dep/make.git/src/loadapi.c /home/marler8997/git/ziglibc/dep/make.git/src/main.c /home/marler8997/git/ziglibc/dep/make.git/src/misc.c /home/marler8997/git/ziglibc/dep/make.git/src/output.c /home/marler8997/git/ziglibc/dep/make.git/src/read.c /home/marler8997/git/ziglibc/dep/make.git/src/remake.c /home/marler8997/git/ziglibc/dep/make.git/src/rule.c /home/marler8997/git/ziglibc/dep/make.git/src/shuffle.c /home/marler8997/git/ziglibc/dep/make.git/src/signame.c /home/marler8997/git/ziglibc/dep/make.git/src/strcache.c /home/marler8997/git/ziglibc/dep/make.git/src/variable.c /home/marler8997/git/ziglibc/dep/make.git/src/version.c /home/marler8997/git/ziglibc/dep/make.git/src/vpath.c /home/marler8997/git/ziglibc/dep/make.git/src/posixos.c /home/marler8997/git/ziglibc/dep/make.git/src/remote-stub.c /home/marler8997/git/ziglibc/zig-cache/o/b2ab2b27dd98ed5352486d2081cf35bf/libc-only-std.a /home/marler8997/git/ziglibc/zig-cache/o/4d76e73699236d8f95a7f75ae51db269/libc-only-posix.a /home/marler8997/git/ziglibc/zig-cache/o/f647e7cbfedb41adc3d86981e126be58/libstart.a --verbose-cc --cache-dir /home/marler8997/git/ziglibc/zig-cache --global-cache-dir /home/marler8997/.cache/zig --name make -I /home/marler8997/git/ziglibc/inc/libc -I /home/marler8997/git/ziglibc/inc/posix -I /home/marler8997/git/ziglibc/inc/gnu --enable-cache -// home/marler8997/zig/0.11.0-dev.12+ebf9ffd34/files/zig build-exe -cflags -std=c11 -- /home/marler8997/git/ziglibc/dep/make.git/src/ar.c /home/marler8997/git/ziglibc/dep/make.git/src/arscan.c /home/marler8997/git/ziglibc/dep/make.git/src/commands.c /home/marler8997/git/ziglibc/dep/make.git/src/default.c /home/marler8997/git/ziglibc/dep/make.git/src/dir.c /home/marler8997/git/ziglibc/dep/make.git/src/expand.c /home/marler8997/git/ziglibc/dep/make.git/src/file.c /home/marler8997/git/ziglibc/dep/make.git/src/function.c /home/marler8997/git/ziglibc/dep/make.git/src/getopt.c /home/marler8997/git/ziglibc/dep/make.git/src/getopt1.c /home/marler8997/git/ziglibc/dep/make.git/src/guile.c /home/marler8997/git/ziglibc/dep/make.git/src/hash.c /home/marler8997/git/ziglibc/dep/make.git/src/implicit.c /home/marler8997/git/ziglibc/dep/make.git/src/job.c /home/marler8997/git/ziglibc/dep/make.git/src/load.c /home/marler8997/git/ziglibc/dep/make.git/src/loadapi.c /home/marler8997/git/ziglibc/dep/make.git/src/main.c /home/marler8997/git/ziglibc/dep/make.git/src/misc.c /home/marler8997/git/ziglibc/dep/make.git/src/output.c /home/marler8997/git/ziglibc/dep/make.git/src/read.c /home/marler8997/git/ziglibc/dep/make.git/src/remake.c /home/marler8997/git/ziglibc/dep/make.git/src/rule.c /home/marler8997/git/ziglibc/dep/make.git/src/shuffle.c /home/marler8997/git/ziglibc/dep/make.git/src/signame.c /home/marler8997/git/ziglibc/dep/make.git/src/strcache.c /home/marler8997/git/ziglibc/dep/make.git/src/variable.c /home/marler8997/git/ziglibc/dep/make.git/src/version.c /home/marler8997/git/ziglibc/dep/make.git/src/vpath.c /home/marler8997/git/ziglibc/dep/make.git/src/posixos.c /home/marler8997/git/ziglibc/dep/make.git/src/remote-stub.c /home/marler8997/git/ziglibc/zig-cache/o/b2ab2b27dd98ed5352486d2081cf35bf/libc-only-std.a /home/marler8997/git/ziglibc/zig-cache/o/4d76e73699236d8f95a7f75ae51db269/libc-only-posix.a /home/marler8997/git/ziglibc/zig-cache/o/f647e7cbfedb41adc3d86981e126be58/libstart.a --verbose-cc --cache-dir /home/marler8997/git/ziglibc/zig-cache --global-cache-dir /home/marler8997/.cache/zig --name make -I /home/marler8997/git/ziglibc/inc/libc -I /home/marler8997/git/ziglibc/inc/posix -I /home/marler8997/git/ziglibc/inc/gnu --enable-cache - - const exe = b.addExecutable("make", null); - exe.setTarget(target); - exe.setBuildMode(mode); + const exe = b.addExecutable(.{ + .name = "make", + .target = target, + .optimize = mode, + }); _ = b.addInstallArtifact(exe); //exe.install(); exe.step.dependOn(&repo.step); @@ -75,16 +76,25 @@ pub fn addGnuMake( const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); for (src_filenames) |src| { - files.append(b.pathJoin(&.{repo_path, "src", src})) catch unreachable; + files.append(b.pathJoin(&.{ repo_path, "src", src })) catch unreachable; } - exe.addIncludePath(b.pathJoin(&.{repo_path, "src"})); - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addIncludePath(b.pathJoin(&.{ repo_path, "src" })); + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c99", "-DHAVE_CONFIG_H", - "-Wall", "-Wextra", "-Werror", "-Wwrite-strings", "-Wshadow", "-Wdeclaration-after-statement", - "-Wbad-function-cast", "-Wformat-security", "-Wtype-limits", "-Wunused-but-set-parameter", - "-Wpointer-arith", "-Wignored-qualifiers", + "-Wall", + "-Wextra", + "-Werror", + "-Wwrite-strings", + "-Wshadow", + "-Wdeclaration-after-statement", + "-Wbad-function-cast", + "-Wformat-security", + "-Wtype-limits", + "-Wunused-but-set-parameter", + "-Wpointer-arith", + "-Wignored-qualifiers", // ignore unused parameter errors because the ATTRIBUTE define isn't working in makeint.h "-Wno-unused-parameter", "-Wno-dangling-else", @@ -110,7 +120,7 @@ pub fn addGnuMake( return exe; } -const src_filenames = &[_][]const u8 { +const src_filenames = &[_][]const u8{ "ar.c", "arscan.c", "commands.c", diff --git a/ncurses/build.zig b/ncurses/build.zig index 8f0075a..27fdc57 100644 --- a/ncurses/build.zig +++ b/ncurses/build.zig @@ -18,8 +18,8 @@ const NcursesPrepStep = struct { .step = std.build.Step.init(.custom, "ncurses prep", b.allocator, make), .builder = b, .repo_path = repo.path, - .defs_h_src = b.pathJoin(&.{repo.path, "include", "ncurses_defs"}), - .defs_h_dst = b.pathJoin(&.{repo.path, "include", "ncurses_def.h"}), + .defs_h_src = b.pathJoin(&.{ repo.path, "include", "ncurses_defs" }), + .defs_h_dst = b.pathJoin(&.{ repo.path, "include", "ncurses_def.h" }), //.curses_h = b.pathJoin(&.{repo.path, "include", "curses.h"}), }; result.*.step.dependOn(&repo.step); @@ -44,7 +44,7 @@ const NcursesPrepStep = struct { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); const content = std.fs.cwd().readFileAlloc(arena.allocator(), self.defs_h_src, std.math.maxInt(usize)) catch |err| { - std.log.err("failed to read file '{s}' to process ({s})", .{self.defs_h_src, @errorName(err)}); + std.log.err("failed to read file '{s}' to process ({s})", .{ self.defs_h_src, @errorName(err) }); std.os.exit(0xff); }; @@ -68,7 +68,7 @@ const NcursesPrepStep = struct { try writer.print("\n#ifndef {s}\n", .{name}); if (optional_value) |value| { const value_offset = @ptrToInt(value.ptr) - @ptrToInt(line.ptr); - try writer.print("#define {s} {s}\n", .{name, line[value_offset..]}); + try writer.print("#define {s} {s}\n", .{ name, line[value_offset..] }); } else { try writer.print("#define {s} 0\n", .{name}); } @@ -91,8 +91,8 @@ fn addProcessFile( }, ) void { const process_file = ProcessFileStep.create(b, .{ - .in_filename = b.pathJoin(&.{repo.path, in_sub_path}), - .out_filename = b.pathJoin(&.{repo.path, out_sub_path}), + .in_filename = b.pathJoin(&.{ repo.path, in_sub_path }), + .out_filename = b.pathJoin(&.{ repo.path, out_sub_path }), .subs = opt.subs, }); process_file.step.dependOn(&repo.step); @@ -114,42 +114,50 @@ pub fn add( const prep = NcursesPrepStep.create(b, repo); - const exe = b.addStaticLibrary("ncurses", null); - addProcessFile(b, repo, exe, - b.pathJoin(&.{"include", "ncurses_dll.h.in"}), - b.pathJoin(&.{"include", "ncurses_dll.h"}), + const exe = b.addStaticLibrary(.{ + .name = "ncurses", + .target = target, + .optimize = mode, + }); + addProcessFile( + b, + repo, + exe, + b.pathJoin(&.{ "include", "ncurses_dll.h.in" }), + b.pathJoin(&.{ "include", "ncurses_dll.h" }), .{}, ); - const defs_sub = ProcessFileStep.Sub { + const defs_sub = ProcessFileStep.Sub{ .current = "@DEFS@", .new = @embedFile("DEFS"), }; - addProcessFile(b, repo, exe, - b.pathJoin(&.{"include", "ncurses_cfg.hin"}), - b.pathJoin(&.{"include", "ncurses_cfg.h"}), - .{ .subs = &.{ defs_sub } }, + addProcessFile( + b, + repo, + exe, + b.pathJoin(&.{ "include", "ncurses_cfg.hin" }), + b.pathJoin(&.{ "include", "ncurses_cfg.h" }), + .{ .subs = &.{defs_sub} }, ); //addProcessFile(b, repo, exe, // b.pathJoin(&.{"include", "curses.h.in"}), // b.pathJoin(&.{"include", "curses.head"}), // .{ .subs = &.{ defs_sub } }, //); - exe.setTarget(target); - exe.setBuildMode(mode); //exe.install(); _ = b.addInstallArtifact(exe); exe.step.dependOn(&prep.step); const repo_path = repo.getPath(&exe.step); var files = std.ArrayList([]const u8).init(b.allocator); - for ([_][]const u8 { "lib_initscr.c" }) |src| { - files.append(b.pathJoin(&.{repo_path, "ncurses", "base", src})) catch unreachable; + for ([_][]const u8{"lib_initscr.c"}) |src| { + files.append(b.pathJoin(&.{ repo_path, "ncurses", "base", src })) catch unreachable; } - exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8 { + exe.addCSourceFiles(files.toOwnedSlice() catch unreachable, &[_][]const u8{ "-std=c99", }); - exe.addIncludePath(b.pathJoin(&.{repo_path, "include"})); - exe.addIncludePath(b.pathJoin(&.{repo_path, "ncurses"})); + exe.addIncludePath(b.pathJoin(&.{ repo_path, "include" })); + exe.addIncludePath(b.pathJoin(&.{ repo_path, "ncurses" })); exe.addIncludePath("inc/libc"); exe.addIncludePath("inc/posix"); diff --git a/ziglibcbuild.zig b/ziglibcbuild.zig index 04d863b..7d07443 100644 --- a/ziglibcbuild.zig +++ b/ziglibcbuild.zig @@ -20,11 +20,17 @@ pub const ZigLibcOptions = struct { start: Start, trace: bool, target: std.zig.CrossTarget, + optimize: std.builtin.Mode, }; /// Provides a _start symbol that will call C main -pub fn addZigStart(builder: *std.build.Builder) *std.build.LibExeObjStep { - const lib = builder.addStaticLibrary("start", "src" ++ std.fs.path.sep_str ++ "start.zig"); +pub fn addZigStart(builder: *std.Build.Builder, target: std.zig.CrossTarget, optimize: std.builtin.Mode) *std.build.LibExeObjStep { + const lib = builder.addStaticLibrary(.{ + .name = "start", + .root_source_file = .{ .path = "src" ++ std.fs.path.sep_str ++ "start.zig" }, + .target = target, + .optimize = optimize, + }); // TODO: not sure if this is reallly needed or not, but it shouldn't hurt // anything except performance to enable it lib.force_pic = true; @@ -35,34 +41,48 @@ pub fn addZigStart(builder: *std.build.Builder) *std.build.LibExeObjStep { // Caller will also need to add the include path to get the C headers pub fn addLibc(builder: *std.build.Builder, opt: ZigLibcOptions) *std.build.LibExeObjStep { const name = switch (opt.variant) { - .only_std => "c-only-std", + .only_std => if (opt.link == .static) "c-only-std-static" else "c-only-std", .only_posix => "c-only-posix", .only_linux => "c-only-linux", .only_gnu => "c-only-gnu", //.full => "c", .full => "cguana", // use cguana to avoid passing in '-lc' to zig which will - // cause it to add the system libc headers + // cause it to add the system libc headers }; const trace_options = builder.addOptions(); trace_options.addOption(bool, "enabled", opt.trace); const modules_options = builder.addOptions(); - modules_options.addOption(bool, "glibcstart", switch (opt.start) { .glibc => true, else => false }); + modules_options.addOption(bool, "glibcstart", switch (opt.start) { + .glibc => true, + else => false, + }); const index = "src" ++ std.fs.path.sep_str ++ "lib.zig"; const lib = switch (opt.link) { - .static => builder.addStaticLibrary(name, index), - .shared => builder.addSharedLibrary(name, index, switch (opt.variant) { - .full => .{ .versioned = .{ .major = 6, .minor = 0 } }, - else => .unversioned, + .static => builder.addStaticLibrary(.{ + .name = name, + .root_source_file = .{ .path = index }, + .target = opt.target, + .optimize = opt.optimize, + }), + .shared => builder.addSharedLibrary(.{ + .name = name, + .root_source_file = .{ .path = index }, + .target = opt.target, + .optimize = opt.optimize, + .version = switch (opt.variant) { + .full => .{ .major = 6, .minor = 0 }, + else => null, + }, }), }; - lib.setTarget(opt.target); + lib.installHeadersDirectory("inc/libc", "include"); // TODO: not sure if this is reallly needed or not, but it shouldn't hurt // anything except performance to enable it lib.force_pic = true; lib.addOptions("modules", modules_options); lib.addOptions("trace_options", trace_options); - const c_flags = [_][]const u8 { + const c_flags = [_][]const u8{ "-std=c11", }; const include_cstd = switch (opt.variant) {