Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve toolchain integration #492

Merged
merged 50 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bd98bca
Distro: code for determining the Linux distro
ehaas Jul 12, 2023
72a860f
build.zig: Add default linker option
ehaas Jul 12, 2023
cc105cc
Toolchain: code for finding/using other parts of the build toolchain
ehaas Jul 12, 2023
75bd4a1
Toolchain: Add an option for passing --build-id to linker
ehaas Jul 12, 2023
6d67f84
Driver: store raw target triple
ehaas Jul 12, 2023
4af282e
Toolchain: search program paths for programs
ehaas Jul 12, 2023
3ff47ca
Toolchain: use a FixedBufferAllocator for path testing
ehaas Jul 12, 2023
9ee156e
Toolchain: skip too-long search paths instead of erroring
ehaas Jul 12, 2023
f9b8e7d
Toolchain: improve doc comment for searchPaths
ehaas Jul 12, 2023
10aa61e
Driver: make default sysroot an aro build setting
ehaas Jul 12, 2023
1adc734
Toolchain: Add sysroot support for path searching
ehaas Jul 12, 2023
dadcce0
Toolchain: add some doc comments
ehaas Jul 12, 2023
36f9385
Toolchain: panic if we try to link when we shouldn't
ehaas Jul 12, 2023
38d7fc1
Toolchain: use target-specific default linker
ehaas Jul 12, 2023
a63c731
Build: put system defaults into their own set of options
ehaas Jul 12, 2023
9da2446
linux toolchain: make tc arg const
ehaas Jul 12, 2023
f3490c8
Toolchain: put paths into the toolchain arena
ehaas Jul 12, 2023
d35d669
Toolchain: implement searching PATH for executables
ehaas Jul 13, 2023
984ee24
Toolchain: add -L arguments for linker
ehaas Jul 13, 2023
d45425d
util: use platform-specific code for canExecute
ehaas Jul 14, 2023
f6f3ff1
GCCVersion: Add ability to parse GCC versions
ehaas Jul 14, 2023
07b9b31
Toolchain: Add GCC detector to find GCC installs
ehaas Jul 17, 2023
afeebd3
Driver: move driver files into their own directory
ehaas Jul 18, 2023
bd31e75
Toolchain: add filesystem abstraction to ease testing
ehaas Jul 18, 2023
33e53eb
Toolchain: add crt begin/end files
ehaas Jul 21, 2023
fddb561
Toolchain: add unwind lib args
ehaas Jul 27, 2023
f02ecb7
Toolchain: use tc for self arg for consistency
ehaas Jul 28, 2023
760d679
Toolchain: Add a doc comment for buildLinkerArgs
ehaas Jul 28, 2023
2ea408c
target: implement get64BitArchVariant
ehaas Jul 28, 2023
05ec9bf
Driver: dump linker args with quoted+escaped arguments
ehaas Jul 29, 2023
eab7ab5
Driver: only perform toolchain discovery if linking
ehaas Jul 29, 2023
d6e7ca5
Toolchain: cleanup BoundedArray usage
ehaas Aug 13, 2023
bd14d94
Multilib: return an error instead of panicking if too many multilibs …
ehaas Aug 13, 2023
fcb3140
GCCDetector: Fill out remaining collectLibDirsAndTriples prongs
ehaas Aug 14, 2023
a464cdc
GCCDetector: make use of biarch_variant_target
ehaas Aug 14, 2023
8e609a6
Toolchain: Add more multiarch triples
ehaas Aug 17, 2023
8f3d337
Toolchain: get PATH env var from compilation instead of getenv
ehaas Aug 17, 2023
feb3b4b
Filesystem: make PATH separator configurable
ehaas Aug 17, 2023
865a145
Linux toolchain: Add basic test for linker args
ehaas Aug 17, 2023
0ddafc4
Toolchain: use Filesystem for Distro and GCC detection
ehaas Aug 17, 2023
6fac5b5
GCCDetector: join lib_suffix correctly
ehaas Aug 18, 2023
4d124b3
Driver: move self-exe determination to main
ehaas Aug 18, 2023
39de175
Toolchain: reset allocator properly in path search
ehaas Aug 18, 2023
0c34e51
Driver: remove unnecessary driver_test.zig
ehaas Aug 25, 2023
6b072e3
Driver: reorganize namespace so Driver.zig is at the top level
ehaas Aug 25, 2023
72fd17d
target: use Zig arch name for spu_2 since LLVM does not support it
ehaas Aug 25, 2023
01328f2
target: adjust toLLVMTriple to it doesn't return an error union
ehaas Aug 25, 2023
dfb5f0d
GCCDetector: skip directory entries that cause errors
ehaas Aug 25, 2023
d13b5e6
main: return u8 instead of an error union from main
ehaas Aug 25, 2023
ff76738
Multilib: make MultilibArray its own type
ehaas Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ 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 "";
const gcc_install_prefix = b.option([]const u8, "gcc-install-prefix", "Directory where gcc is installed.") orelse "";
const default_rtlib = b.option([]const u8, "default-rtlib", "Default compiler runtime library if --rtlib is not specified") orelse "";
const default_unwindlib = b.option([]const u8, "default-unwindlib", "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty to match runtime library.)") orelse
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 All @@ -65,6 +75,18 @@ pub fn build(b: *Build) !void {
});
const exe_options = b.addOptions();
exe.addOptions("build_options", exe_options);

const system_defaults = b.addOptions();
exe.addOptions("system_defaults", system_defaults);

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);
system_defaults.addOption([]const u8, "unwindlib", default_unwindlib);

exe_options.addOption(bool, "enable_tracy", tracy != null);
exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
Expand Down Expand Up @@ -101,6 +123,7 @@ pub fn build(b: *Build) !void {

var unit_tests = b.addTest(.{ .root_source_file = .{ .path = "src/main.zig" } });
unit_tests.addModule("zig", zig_module);
unit_tests.addOptions("system_defaults", system_defaults);
const run_test = b.addRunArtifact(unit_tests);
tests_step.dependOn(&run_test.step);

Expand All @@ -111,6 +134,7 @@ pub fn build(b: *Build) !void {
integration_tests.addModule("aro", aro_module);
const test_runner_options = b.addOptions();
integration_tests.addOptions("build_options", test_runner_options);
integration_tests.addOptions("system_defaults", system_defaults);
test_runner_options.addOption(bool, "test_all_allocation_failures", test_all_allocation_failures);

const integration_test_runner = b.addRunArtifact(integration_tests);
Expand Down
7 changes: 5 additions & 2 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub const Environment = struct {
/// TODO: not implemented yet
tmpdir: ?[]const u8 = null,

/// PATH environment variable used to search for programs
path: ?[]const u8 = null,

/// Directories to try when searching for subprograms.
/// TODO: not implemented yet
compiler_path: ?[]const u8 = null,
Expand Down Expand Up @@ -901,9 +904,9 @@ pub fn getCharSignedness(comp: *const Compilation) std.builtin.Signedness {
return comp.langopts.char_signedness_override orelse comp.target.charSignedness();
}

pub fn defineSystemIncludes(comp: *Compilation) !void {
pub fn defineSystemIncludes(comp: *Compilation, aro_dir: []const u8) !void {
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var search_path: []const u8 = std.fs.selfExePath(&buf) catch return error.SelfExeNotFound;
var search_path = aro_dir;
while (std.fs.path.dirname(search_path)) |dirname| : (search_path = dirname) {
var base_dir = std.fs.cwd().openDir(dirname, .{}) catch continue;
defer base_dir.close();
Expand Down
25 changes: 25 additions & 0 deletions src/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub const Options = packed struct {
@"gnu-auto-type": Kind = .default,
@"gnu-union-cast": Kind = .default,
@"pointer-sign": Kind = .default,
@"fuse-ld-path": Kind = .default,
};

const messages = struct {
Expand Down Expand Up @@ -2351,6 +2352,30 @@ const messages = struct {
const msg = "environment variable SOURCE_DATE_EPOCH must expand to a non-negative integer less than or equal to 253402300799";
const kind = .@"error";
};
pub const fuse_ld_path = struct {
const msg = "'-fuse-ld=' taking a path is deprecated; use '--ld-path=' instead";
const kind = .off;
const opt = "fuse-ld-path";
};
pub const invalid_rtlib = struct {
const msg = "invalid runtime library name '{s}'";
const kind = .@"error";
const extra = .str;
};
pub const unsupported_rtlib_gcc = struct {
const msg = "unsupported runtime library 'libgcc' for platform '{s}'";
const kind = .@"error";
const extra = .str;
};
pub const invalid_unwindlib = struct {
const msg = "invalid unwind library name '{s}'";
const kind = .@"error";
const extra = .str;
};
pub const incompatible_unwindlib = struct {
const msg = "--rtlib=libgcc requires --unwindlib=libgcc";
const kind = .@"error";
};
};

list: std.ArrayListUnmanaged(Message) = .{},
Expand Down
Loading