Skip to content

Commit

Permalink
Filesystem: make PATH separator configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Aug 17, 2023
1 parent bd38dc4 commit 7fa8788
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub fn build(b: *Build) !void {
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardOptimizeOption(.{});

const default_path_sep: u8 = if (target.isWindows()) ';' else ':';

const enable_linker_build_id = b.option(bool, "enable-linker-build-id", "pass --build-id to linker") orelse false;
const default_linker = b.option([]const u8, "default-linker", "Default linker aro will use if none is supplied via -fuse-ld") orelse "ld";
const default_sysroot = b.option([]const u8, "default-sysroot", "Default <path> to all compiler invocations for --sysroot=<path>.") orelse "";
Expand All @@ -49,6 +51,7 @@ pub fn build(b: *Build) !void {
if (std.mem.eql(u8, default_rtlib, "libgcc")) "libgcc" else "";
const test_all_allocation_failures = b.option(bool, "test-all-allocation-failures", "Test all allocation failures") orelse false;
const link_libc = b.option(bool, "link-libc", "Force self-hosted compiler to link libc") orelse (mode != .Debug);
const path_sep = b.option(u8, "path-sep", "Path separator in PATH environment variable") orelse default_path_sep;
const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
Expand Down Expand Up @@ -78,6 +81,7 @@ pub fn build(b: *Build) !void {

system_defaults.addOption(bool, "enable_linker_build_id", enable_linker_build_id);
system_defaults.addOption([]const u8, "linker", default_linker);
system_defaults.addOption(u8, "path_sep", path_sep);
system_defaults.addOption([]const u8, "sysroot", default_sysroot);
system_defaults.addOption([]const u8, "gcc_install_prefix", gcc_install_prefix);
system_defaults.addOption([]const u8, "rtlib", default_rtlib);
Expand Down
3 changes: 2 additions & 1 deletion src/driver/Filesystem.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const std = @import("std");
const mem = std.mem;
const builtin = @import("builtin");
const system_defaults = @import("system_defaults");
const is_windows = builtin.os.tag == .windows;

fn findProgramByNameFake(allocator: std.mem.Allocator, name: []const u8, path: ?[]const u8, buf: []u8) ?[]const u8 {
Expand Down Expand Up @@ -58,7 +59,7 @@ fn findProgramByNamePosix(name: []const u8, path: ?[]const u8, buf: []u8) ?[]con
const path_env = path orelse return null;
var fib = std.heap.FixedBufferAllocator.init(buf);

var it = mem.tokenizeScalar(u8, path_env, ':');
var it = mem.tokenizeScalar(u8, path_env, system_defaults.path_sep);
while (it.next()) |path_dir| {
defer fib.reset();
const full_path = std.fs.path.join(fib.allocator(), &.{ path_dir, name }) catch continue;
Expand Down

0 comments on commit 7fa8788

Please sign in to comment.