| ... | @@ -217,6 +217,7 @@ const usage_build_generic = | ... | @@ -217,6 +217,7 @@ const usage_build_generic = |
| 217 | \\ ReleaseSmall Optimize for small binary, safety off | 217 | \\ ReleaseSmall Optimize for small binary, safety off |
| 218 | \\ --pkg-begin [name] [path] Make pkg available to import and push current pkg | 218 | \\ --pkg-begin [name] [path] Make pkg available to import and push current pkg |
| 219 | \\ --pkg-end Pop current pkg | 219 | \\ --pkg-end Pop current pkg |
| | 220 | \\ --main-pkg-path Set the directory of the root package |
| 220 | \\ -fPIC Force-enable Position Independent Code | 221 | \\ -fPIC Force-enable Position Independent Code |
| 221 | \\ -fno-PIC Force-disable Position Independent Code | 222 | \\ -fno-PIC Force-disable Position Independent Code |
| 222 | \\ -fstack-check Enable stack probing in unsafe builds | 223 | \\ -fstack-check Enable stack probing in unsafe builds |
| ... | @@ -234,8 +235,8 @@ const usage_build_generic = | ... | @@ -234,8 +235,8 @@ const usage_build_generic = |
| 234 | \\ c Compile to C source code | 235 | \\ c Compile to C source code |
| 235 | \\ wasm WebAssembly | 236 | \\ wasm WebAssembly |
| 236 | \\ pe Portable Executable (Windows) | 237 | \\ pe Portable Executable (Windows) |
| 237 | \\ coff (planned) Common Object File Format (Windows) | 238 | \\ coff Common Object File Format (Windows) |
| 238 | \\ macho (planned) macOS relocatables | 239 | \\ macho macOS relocatables |
| 239 | \\ hex (planned) Intel IHEX | 240 | \\ hex (planned) Intel IHEX |
| 240 | \\ raw (planned) Dump machine code directly | 241 | \\ raw (planned) Dump machine code directly |
| 241 | \\ -dirafter [dir] Add directory to AFTER include search path | 242 | \\ -dirafter [dir] Add directory to AFTER include search path |
| ... | @@ -367,6 +368,7 @@ pub fn buildOutputType( | ... | @@ -367,6 +368,7 @@ pub fn buildOutputType( |
| 367 | var override_local_cache_dir: ?[]const u8 = null; | 368 | var override_local_cache_dir: ?[]const u8 = null; |
| 368 | var override_global_cache_dir: ?[]const u8 = null; | 369 | var override_global_cache_dir: ?[]const u8 = null; |
| 369 | var override_lib_dir: ?[]const u8 = null; | 370 | var override_lib_dir: ?[]const u8 = null; |
| | 371 | var main_pkg_path: ?[]const u8 = null; |
| 370 | | 372 | |
| 371 | var system_libs = std.ArrayList([]const u8).init(gpa); | 373 | var system_libs = std.ArrayList([]const u8).init(gpa); |
| 372 | defer system_libs.deinit(); | 374 | defer system_libs.deinit(); |
| ... | @@ -463,6 +465,10 @@ pub fn buildOutputType( | ... | @@ -463,6 +465,10 @@ pub fn buildOutputType( |
| 463 | } else if (mem.eql(u8, arg, "--pkg-end")) { | 465 | } else if (mem.eql(u8, arg, "--pkg-end")) { |
| 464 | cur_pkg = cur_pkg.parent orelse | 466 | cur_pkg = cur_pkg.parent orelse |
| 465 | fatal("encountered --pkg-end with no matching --pkg-begin", .{}); | 467 | fatal("encountered --pkg-end with no matching --pkg-begin", .{}); |
| | 468 | } else if (mem.eql(u8, arg, "--main-pkg-path")) { |
| | 469 | if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg}); |
| | 470 | i += 1; |
| | 471 | main_pkg_path = args[i]; |
| 466 | } else if (mem.eql(u8, arg, "--color")) { | 472 | } else if (mem.eql(u8, arg, "--color")) { |
| 467 | if (i + 1 >= args.len) { | 473 | if (i + 1 >= args.len) { |
| 468 | fatal("expected [auto|on|off] after --color", .{}); | 474 | fatal("expected [auto|on|off] after --color", .{}); |
| ... | @@ -1248,8 +1254,18 @@ pub fn buildOutputType( | ... | @@ -1248,8 +1254,18 @@ pub fn buildOutputType( |
| 1248 | .yes => |p| p, | 1254 | .yes => |p| p, |
| 1249 | }; | 1255 | }; |
| 1250 | | 1256 | |
| | 1257 | var cleanup_root_dir: ?fs.Dir = null; |
| | 1258 | defer if (cleanup_root_dir) |*dir| dir.close(); |
| | 1259 | |
| 1251 | const root_pkg: ?*Package = if (root_src_file) |src_path| blk: { | 1260 | const root_pkg: ?*Package = if (root_src_file) |src_path| blk: { |
| 1252 | root_pkg_memory.root_src_directory = .{ .path = null, .handle = fs.cwd() }; | 1261 | root_pkg_memory.root_src_directory = m: { |
| | 1262 | if (main_pkg_path) |p| { |
| | 1263 | const dir = try fs.cwd().openDir(p, .{}); |
| | 1264 | cleanup_root_dir = dir; |
| | 1265 | break :m .{ .path = p, .handle = dir }; |
| | 1266 | } |
| | 1267 | break :m .{ .path = null, .handle = fs.cwd() }; |
| | 1268 | }; |
| 1253 | root_pkg_memory.root_src_path = src_path; | 1269 | root_pkg_memory.root_src_path = src_path; |
| 1254 | break :blk &root_pkg_memory; | 1270 | break :blk &root_pkg_memory; |
| 1255 | } else null; | 1271 | } else null; |