diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-09-23 09:56:30 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-09-23 09:56:30 -0700 |
| commit | d03fcc73fc7083558915f6c170432fce8fb84993 (patch) | |
| tree | 106c14aad3ac777dd9e41426cf8606ddaa747ff8 /src | |
| parent | 15b2bae517c54db22604eb303645d2f0023768e0 (diff) | |
| download | zig-d03fcc73fc7083558915f6c170432fce8fb84993.tar.gz zig-d03fcc73fc7083558915f6c170432fce8fb84993.zip | |
stage2: implement --main-pkg-path
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 6 | ||||
| -rw-r--r-- | src/main.zig | 22 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index be26a400c2..656baa898b 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2248,10 +2248,12 @@ fn updateStage1Module(comp: *Compilation) !void { comp.stage1_cache_hash = &ch; + const main_pkg_path = mod.root_pkg.root_src_directory.path orelse ""; + const stage1_module = stage1.create( @enumToInt(comp.bin_file.options.optimize_mode), - undefined, - 0, // TODO --main-pkg-path + main_pkg_path.ptr, + main_pkg_path.len, main_zig_file.ptr, main_zig_file.len, zig_lib_dir.ptr, diff --git a/src/main.zig b/src/main.zig index 87ddbed343..1873656e77 100644 --- a/src/main.zig +++ b/src/main.zig @@ -217,6 +217,7 @@ const usage_build_generic = \\ ReleaseSmall Optimize for small binary, safety off \\ --pkg-begin [name] [path] Make pkg available to import and push current pkg \\ --pkg-end Pop current pkg + \\ --main-pkg-path Set the directory of the root package \\ -fPIC Force-enable Position Independent Code \\ -fno-PIC Force-disable Position Independent Code \\ -fstack-check Enable stack probing in unsafe builds @@ -234,8 +235,8 @@ const usage_build_generic = \\ c Compile to C source code \\ wasm WebAssembly \\ pe Portable Executable (Windows) - \\ coff (planned) Common Object File Format (Windows) - \\ macho (planned) macOS relocatables + \\ coff Common Object File Format (Windows) + \\ macho macOS relocatables \\ hex (planned) Intel IHEX \\ raw (planned) Dump machine code directly \\ -dirafter [dir] Add directory to AFTER include search path @@ -367,6 +368,7 @@ pub fn buildOutputType( var override_local_cache_dir: ?[]const u8 = null; var override_global_cache_dir: ?[]const u8 = null; var override_lib_dir: ?[]const u8 = null; + var main_pkg_path: ?[]const u8 = null; var system_libs = std.ArrayList([]const u8).init(gpa); defer system_libs.deinit(); @@ -463,6 +465,10 @@ pub fn buildOutputType( } else if (mem.eql(u8, arg, "--pkg-end")) { cur_pkg = cur_pkg.parent orelse fatal("encountered --pkg-end with no matching --pkg-begin", .{}); + } else if (mem.eql(u8, arg, "--main-pkg-path")) { + if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg}); + i += 1; + main_pkg_path = args[i]; } else if (mem.eql(u8, arg, "--color")) { if (i + 1 >= args.len) { fatal("expected [auto|on|off] after --color", .{}); @@ -1248,8 +1254,18 @@ pub fn buildOutputType( .yes => |p| p, }; + var cleanup_root_dir: ?fs.Dir = null; + defer if (cleanup_root_dir) |*dir| dir.close(); + const root_pkg: ?*Package = if (root_src_file) |src_path| blk: { - root_pkg_memory.root_src_directory = .{ .path = null, .handle = fs.cwd() }; + root_pkg_memory.root_src_directory = m: { + if (main_pkg_path) |p| { + const dir = try fs.cwd().openDir(p, .{}); + cleanup_root_dir = dir; + break :m .{ .path = p, .handle = dir }; + } + break :m .{ .path = null, .handle = fs.cwd() }; + }; root_pkg_memory.root_src_path = src_path; break :blk &root_pkg_memory; } else null; |
