| author | |
| committer | |
| log | c0b774fbc65e3e406a38d37b02fffda7c5d3df26 |
| tree | 42ddfb82ff654e5a59e47837172959ff651b89b7 |
| parent | d03fcc73fc7083558915f6c170432fce8fb84993 |
closes #35083 files changed, 35 insertions(+), 7 deletions(-)
BRANCH_TODO+1-2| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | * add CLI support for a way to pass extra flags to c source files | |
| 2 | * musl | |
| 3 | 1 | * support rpaths in ELF linker code |
| 2 | * musl | |
| 4 | 3 | * implement proper parsing of LLD stderr/stdout and exposing compile errors |
| 5 | 4 | * tests passing with -Dskip-non-native |
| 6 | 5 | * windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj] |
lib/std/build.zig+18-3| ... | ... | @@ -1947,6 +1947,7 @@ pub const LibExeObjStep = struct { |
| 1947 | 1947 | |
| 1948 | 1948 | if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder)); |
| 1949 | 1949 | |
| 1950 | var prev_has_extra_flags = false; | |
| 1950 | 1951 | for (self.link_objects.span()) |link_object| { |
| 1951 | 1952 | switch (link_object) { |
| 1952 | 1953 | .StaticPath => |static_path| { |
| ... | ... | @@ -1979,12 +1980,26 @@ pub const LibExeObjStep = struct { |
| 1979 | 1980 | try zig_args.append(name); |
| 1980 | 1981 | }, |
| 1981 | 1982 | .AssemblyFile => |asm_file| { |
| 1983 | if (prev_has_extra_flags) { | |
| 1984 | try zig_args.append("-extra-cflags"); | |
| 1985 | try zig_args.append("--"); | |
| 1986 | prev_has_extra_flags = false; | |
| 1987 | } | |
| 1982 | 1988 | try zig_args.append(asm_file.getPath(builder)); |
| 1983 | 1989 | }, |
| 1984 | 1990 | .CSourceFile => |c_source_file| { |
| 1985 | try zig_args.append("--c-source"); | |
| 1986 | for (c_source_file.args) |arg| { | |
| 1987 | try zig_args.append(arg); | |
| 1991 | if (c_source_file.args.len == 0) { | |
| 1992 | if (prev_has_extra_flags) { | |
| 1993 | try zig_args.append("-cflags"); | |
| 1994 | try zig_args.append("--"); | |
| 1995 | prev_has_extra_flags = false; | |
| 1996 | } | |
| 1997 | } else { | |
| 1998 | try zig_args.append("-cflags"); | |
| 1999 | for (c_source_file.args) |arg| { | |
| 2000 | try zig_args.append(arg); | |
| 2001 | } | |
| 2002 | try zig_args.append("--"); | |
| 1988 | 2003 | } |
| 1989 | 2004 | try zig_args.append(c_source_file.source.getPath(builder)); |
| 1990 | 2005 | }, |
src/main.zig+16-2| ... | ... | @@ -244,6 +244,7 @@ const usage_build_generic = |
| 244 | 244 | \\ -I[dir] Add directory to include search path |
| 245 | 245 | \\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted) |
| 246 | 246 | \\ --libc [file] Provide a file which specifies libc paths |
| 247 | \\ -cflags [flags] -- Set extra flags for the next positional C source files | |
| 247 | 248 | \\ |
| 248 | 249 | \\Link Options: |
| 249 | 250 | \\ -l[lib], --library [lib] Link against system library |
| ... | ... | @@ -376,6 +377,9 @@ pub fn buildOutputType( |
| 376 | 377 | var clang_argv = std.ArrayList([]const u8).init(gpa); |
| 377 | 378 | defer clang_argv.deinit(); |
| 378 | 379 | |
| 380 | var extra_cflags = std.ArrayList([]const u8).init(gpa); | |
| 381 | defer extra_cflags.deinit(); | |
| 382 | ||
| 379 | 383 | var lld_argv = std.ArrayList([]const u8).init(gpa); |
| 380 | 384 | defer lld_argv.deinit(); |
| 381 | 385 | |
| ... | ... | @@ -469,6 +473,14 @@ pub fn buildOutputType( |
| 469 | 473 | if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg}); |
| 470 | 474 | i += 1; |
| 471 | 475 | main_pkg_path = args[i]; |
| 476 | } else if (mem.eql(u8, arg, "-cflags")) { | |
| 477 | extra_cflags.shrinkRetainingCapacity(0); | |
| 478 | while (true) { | |
| 479 | i += 1; | |
| 480 | if (i + 1 >= args.len) fatal("expected -- after -cflags", .{}); | |
| 481 | if (mem.eql(u8, args[i], "--")) break; | |
| 482 | try extra_cflags.append(args[i]); | |
| 483 | } | |
| 472 | 484 | } else if (mem.eql(u8, arg, "--color")) { |
| 473 | 485 | if (i + 1 >= args.len) { |
| 474 | 486 | fatal("expected [auto|on|off] after --color", .{}); |
| ... | ... | @@ -713,8 +725,10 @@ pub fn buildOutputType( |
| 713 | 725 | try link_objects.append(arg); |
| 714 | 726 | }, |
| 715 | 727 | .assembly, .c, .cpp, .h, .ll, .bc => { |
| 716 | // TODO a way to pass extra flags on the CLI | |
| 717 | try c_source_files.append(.{ .src_path = arg }); | |
| 728 | try c_source_files.append(.{ | |
| 729 | .src_path = arg, | |
| 730 | .extra_flags = try arena.dupe([]const u8, extra_cflags.items), | |
| 731 | }); | |
| 718 | 732 | }, |
| 719 | 733 | .shared_library => { |
| 720 | 734 | fatal("linking against dynamic libraries not yet supported", .{}); |