Skip to content

Commit

Permalink
build: make flags build opt a list and rename it to copt
Browse files Browse the repository at this point in the history
  • Loading branch information
ripperi committed Nov 8, 2024
1 parent 4621182 commit 5efbc14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
7 changes: 4 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ Supported values:
- soon
- edge

#### `-Dflags=[string]`
Provide additional compiler flags. These propagate to all build artifacts and
dependencies.
#### `-Dcopt=[list]`
Provide additional compiler flags. These propagate to all build artifacts.

Example: `zig build -Dcopt="-g" -Dcopt="-fno-sanitize=all"`

<!-- ## LSP Integration -->

Expand Down
18 changes: 5 additions & 13 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,11 @@ pub fn build(b: *std.Build) !void {
"Release train (Default: once)",
) orelse if (release) Pace.live else Pace.once);

const flags_opt = b.option(
[]const u8,
"flags",
const copts: []const []const u8 = b.option(
[]const []const u8,
"copt",
"Provide additional compiler flags",
);
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
var iter_flags = std.mem.splitSequence(u8, flags_opt orelse "", " ");
while (iter_flags.next()) |flag| {
if (flag.len != 0) {
try flags.appendSlice(&.{flag});
}
}
) orelse &.{};

const cpu_dbg = b.option(
bool,
Expand Down Expand Up @@ -111,7 +103,7 @@ pub fn build(b: *std.Build) !void {
const build_cfg: BuildCfg = .{
.version = version,
.pace = pace,
.flags = flags.items,
.flags = copts,
.binary_name = binary_name,
.cpu_dbg = cpu_dbg,
.mem_dbg = mem_dbg,
Expand Down

0 comments on commit 5efbc14

Please sign in to comment.