| author | |
| committer | |
| log | b844605c524b9d7fe7327d7b95463ce70ed6fbf4 |
| tree | dadc4abe23ea12c4d82fcc6de51bf1b93b70bd4a |
| parent | 41d3b9a3edacc7e0e903fffc5c912f7e69f30c3a |
closes #355684 files changed, 18 insertions(+), 14 deletions(-)
lib/compiler/Maker/Step/TranslateC.zig+2-3| ... | ... | @@ -59,9 +59,8 @@ pub fn make( |
| 59 | 59 | for (0..conf_tc.include_dirs.len) |i| |
| 60 | 60 | try Step.Compile.appendIncludeDirFlags(arena, conf_tc.include_dirs.get(conf.extra, i), &argv, step_index, maker); |
| 61 | 61 | |
| 62 | for (conf_tc.c_macros.slice) |c_macro| { | |
| 63 | (try argv.addManyAsArray(arena, 2)).* = .{ "-D", c_macro.slice(conf) }; | |
| 64 | } | |
| 62 | try argv.ensureUnusedCapacity(arena, conf_tc.cc_argv.slice.len); | |
| 63 | for (conf_tc.cc_argv.slice) |arg| argv.appendAssumeCapacity(arg.slice(conf)); | |
| 65 | 64 | |
| 66 | 65 | var prev_search_strategy: std.Build.Module.SystemLib.SearchStrategy = .paths_first; |
| 67 | 66 | var prev_preferred_link_mode: std.builtin.LinkMode = .dynamic; |
lib/std/Build/Configuration.zig+2-2| ... | ... | @@ -1402,14 +1402,14 @@ pub const Step = extern struct { |
| 1402 | 1402 | output_file: GeneratedFileIndex, |
| 1403 | 1403 | include_dirs: Storage.UnionList(.flags, .include_dirs, Module.IncludeDir), |
| 1404 | 1404 | system_libs: Storage.FlagLengthPrefixedList(.flags, .system_libs, SystemLib.Index), |
| 1405 | c_macros: Storage.FlagLengthPrefixedList(.flags, .c_macros, String), | |
| 1405 | cc_argv: Storage.FlagLengthPrefixedList(.flags, .cc_argv, String), | |
| 1406 | 1406 | target: ResolvedTarget.OptionalIndex, |
| 1407 | 1407 | |
| 1408 | 1408 | pub const Flags = packed struct(u32) { |
| 1409 | 1409 | tag: Tag = .translate_c, |
| 1410 | 1410 | include_dirs: bool, |
| 1411 | 1411 | system_libs: bool, |
| 1412 | c_macros: bool, | |
| 1412 | cc_argv: bool, | |
| 1413 | 1413 | link_libc: bool, |
| 1414 | 1414 | optimize: Module.Optimize, |
| 1415 | 1415 | _: u20 = 0, |
lib/std/Build/Serialize.zig+2-2| ... | ... | @@ -357,7 +357,7 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi |
| 357 | 357 | .flags = .{ |
| 358 | 358 | .include_dirs = tc.include_dirs.items.len != 0, |
| 359 | 359 | .system_libs = system_libs.len != 0, |
| 360 | .c_macros = tc.c_macros.items.len != 0, | |
| 360 | .cc_argv = tc.cc_argv.items.len != 0, | |
| 361 | 361 | .link_libc = tc.link_libc, |
| 362 | 362 | .optimize = .init(tc.optimize), |
| 363 | 363 | }, |
| ... | ... | @@ -365,7 +365,7 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi |
| 365 | 365 | .output_file = tc.output_file, |
| 366 | 366 | .include_dirs = .init(try s.initIncludeDirList(tc.include_dirs.items)), |
| 367 | 367 | .system_libs = .{ .slice = system_libs }, |
| 368 | .c_macros = .{ .slice = tc.c_macros.items }, | |
| 368 | .cc_argv = .{ .slice = tc.cc_argv.items }, | |
| 369 | 369 | .target = try addOptionalResolvedTarget(wc, tc.target), |
| 370 | 370 | }); |
| 371 | 371 | }, |
lib/std/Build/Step/TranslateC.zig+12-7| ... | ... | @@ -11,7 +11,7 @@ step: Step, |
| 11 | 11 | source: std.Build.LazyPath, |
| 12 | 12 | include_dirs: std.ArrayList(std.Build.Module.IncludeDir) = .empty, |
| 13 | 13 | system_libs: std.ArrayList(std.Build.Module.SystemLib) = .empty, |
| 14 | c_macros: std.ArrayList(Configuration.String) = .empty, | |
| 14 | cc_argv: std.ArrayList(Configuration.String) = .empty, | |
| 15 | 15 | target: std.Build.ResolvedTarget, |
| 16 | 16 | optimize: std.builtin.Optimize, |
| 17 | 17 | output_file: Configuration.GeneratedFileIndex, |
| ... | ... | @@ -156,19 +156,24 @@ pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const |
| 156 | 156 | pub fn defineCMacro(translate_c: *TranslateC, name: []const u8, value: ?[]const u8) void { |
| 157 | 157 | const graph = translate_c.step.owner.graph; |
| 158 | 158 | const arena = graph.arena; |
| 159 | const wc = &graph.wip_configuration; | |
| 160 | const macro = arena.print("{s}={s}", .{ name, value orelse "1" }) catch @panic("OOM"); | |
| 161 | const macro_string = wc.addString(macro) catch @panic("OOM"); | |
| 162 | translate_c.c_macros.append(arena, macro_string) catch @panic("OOM"); | |
| 159 | return addCFlags(translate_c, &.{ | |
| 160 | "-D", | |
| 161 | arena.print("{s}={s}", .{ name, value orelse "1" }) catch @panic("OOM"), | |
| 162 | }); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /// name_and_value looks like [name]=[value]. |
| 166 | 166 | pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void { |
| 167 | return addCFlags(translate_c, &.{ "-D", name_and_value }); | |
| 168 | } | |
| 169 | ||
| 170 | /// Append arbitrary C compiler CLI arguments to the translation unit. | |
| 171 | pub fn addCFlags(translate_c: *TranslateC, args: []const []const u8) void { | |
| 167 | 172 | const graph = translate_c.step.owner.graph; |
| 168 | 173 | const arena = graph.arena; |
| 169 | 174 | const wc = &graph.wip_configuration; |
| 170 | const macro_string = wc.addString(name_and_value) catch @panic("OOM"); | |
| 171 | translate_c.c_macros.append(arena, macro_string) catch @panic("OOM"); | |
| 175 | translate_c.cc_argv.ensureUnusedCapacity(arena, args.len) catch @panic("OOM"); | |
| 176 | for (args) |arg| translate_c.cc_argv.appendAssumeCapacity(wc.addString(arg) catch @panic("OOM")); | |
| 172 | 177 | } |
| 173 | 178 | |
| 174 | 179 | pub fn linkSystemLibrary( |