diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-04 21:33:29 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-07 17:27:09 -0700 |
| commit | 5a65caa2a3686e12e4dfcfd599ed02f8a09c6017 (patch) | |
| tree | 7c5a644b61bdecdb1704e77724fbff74043ae4fe /lib | |
| parent | 5f7b97e84c7e2bc7682510e97996ad30147026d0 (diff) | |
| download | zig-5a65caa2a3686e12e4dfcfd599ed02f8a09c6017.tar.gz zig-5a65caa2a3686e12e4dfcfd599ed02f8a09c6017.zip | |
ability to build stage1 using only a zig tarball
The main idea here is that there are now 2 ways to get a stage1 zig
binary:
* The cmake path. Requirements: cmake, system C++ compiler, system
LLVM, LLD, Clang libraries, compiled by the system C++ compiler.
* The zig path. Requirements: a zig installation, system LLVM, LLD,
Clang libraries, compiled by the zig installation.
Note that the former can be used to now take the latter path.
Removed config.h.in and config.zig.in. The build.zig script no longer is
coupled to the cmake script.
cmake no longer tries to determine the zig version. A build with cmake
will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to
get reverted.
`zig build` now accepts `-Dstage1` which will build the stage1 compiler,
and put the stage2 backend behind a feature flag.
build.zig is simplified to only support the use case of enabling LLVM
support when the LLVM, LLD, and Clang libraries were built by zig. This
part is probably sadly going to have to get reverted to make package
maintainers happy.
Zig build system addBuildOption supports a couple new types.
The biggest reason to make this change is that the zig path is an
attractive option for doing compiler development work on Windows. It
allows people to work on the compiler without having MSVC installed,
using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/build.zig | 80 |
1 files changed, 76 insertions, 4 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig index d820ec639b..329c719573 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1150,6 +1150,11 @@ const CSourceFile = struct { args: []const []const u8, }; +const CSourceFiles = struct { + files: []const []const u8, + flags: []const []const u8, +}; + fn isLibCLibrary(name: []const u8) bool { const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" }; for (libc_libraries) |libc_lib_name| { @@ -1297,6 +1302,7 @@ pub const LibExeObjStep = struct { SystemLib: []const u8, AssemblyFile: FileSource, CSourceFile: *CSourceFile, + CSourceFiles: *CSourceFiles, }; const IncludeDir = union(enum) { @@ -1670,9 +1676,25 @@ pub const LibExeObjStep = struct { self.filter = text; } - pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, args: []const []const u8) void { + /// Handy when you have many C/C++ source files and want them all to have the same flags. + pub fn addCSourceFiles(self: *LibExeObjStep, files: []const []const u8, flags: []const []const u8) void { + const c_source_files = self.builder.allocator.create(CSourceFiles) catch unreachable; + + const flags_copy = self.builder.allocator.alloc([]u8, flags.len) catch unreachable; + for (flags) |flag, i| { + flags_copy[i] = self.builder.dupe(flag); + } + + c_source_files.* = .{ + .files = files, + .flags = flags_copy, + }; + self.link_objects.append(LinkObject{ .CSourceFiles = c_source_files }) catch unreachable; + } + + pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void { self.addCSourceFileSource(.{ - .args = args, + .args = flags, .source = .{ .path = file }, }); } @@ -1795,6 +1817,10 @@ pub const LibExeObjStep = struct { out.writeAll("};\n") catch unreachable; return; }, + [:0]const u8 => { + out.print("pub const {z}: [:0]const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable; + return; + }, []const u8 => { out.print("pub const {z}: []const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable; return; @@ -1808,6 +1834,22 @@ pub const LibExeObjStep = struct { } return; }, + std.builtin.Version => { + out.print( + \\pub const {z}: @import("builtin").Version = .{{ + \\ .major = {d}, + \\ .minor = {d}, + \\ .patch = {d}, + \\}}; + \\ + , .{ + name, + + value.major, + value.minor, + value.patch, + }) catch unreachable; + }, std.SemanticVersion => { out.print( \\pub const {z}: @import("std").SemanticVersion = .{{ @@ -2015,8 +2057,7 @@ pub const LibExeObjStep = struct { }, }, .SystemLib => |name| { - try zig_args.append("--library"); - try zig_args.append(name); + try zig_args.append(builder.fmt("-l{s}", .{name})); }, .AssemblyFile => |asm_file| { if (prev_has_extra_flags) { @@ -2026,6 +2067,7 @@ pub const LibExeObjStep = struct { } try zig_args.append(asm_file.getPath(builder)); }, + .CSourceFile => |c_source_file| { if (c_source_file.args.len == 0) { if (prev_has_extra_flags) { @@ -2042,6 +2084,25 @@ pub const LibExeObjStep = struct { } try zig_args.append(c_source_file.source.getPath(builder)); }, + + .CSourceFiles => |c_source_files| { + if (c_source_files.flags.len == 0) { + if (prev_has_extra_flags) { + try zig_args.append("-cflags"); + try zig_args.append("--"); + prev_has_extra_flags = false; + } + } else { + try zig_args.append("-cflags"); + for (c_source_files.flags) |flag| { + try zig_args.append(flag); + } + try zig_args.append("--"); + } + for (c_source_files.files) |file| { + try zig_args.append(builder.pathFromRoot(file)); + } + }, } } @@ -2304,6 +2365,17 @@ pub const LibExeObjStep = struct { } } + for (builder.search_prefixes.items) |search_prefix| { + try zig_args.append("-L"); + try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{ + search_prefix, "lib", + })); + try zig_args.append("-isystem"); + try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{ + search_prefix, "include", + })); + } + if (self.valgrind_support) |valgrind_support| { if (valgrind_support) { try zig_args.append("-fvalgrind"); |
