authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-06 13:07:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-06 13:07:19-04:00
log96ed5446659549cd21574dcd4996797a99aae39d
tree8fec3c489bc74e86e56f0a48382a08596e6427e5
parenta0b73c9f02b3bb9e550d0283053cc9fc6c1dade6
signaturelock-open Commit is signed but in an unrecognized format.

build.zig supports specifying config.h location explicitly

also it does not try to run llvm-config executable when -Dlib-files-only This fixes cross-compiling using the bootstrap repository.

2 files changed, 25 insertions(+), 11 deletions(-)

CMakeLists.txt+3-1
......@@ -303,9 +303,10 @@ set(LIBC_FILES_DEST "${ZIG_LIB_DIR}/libc")
303303set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")
304304set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")
305305set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
306set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h")
306307configure_file (
307308 "${CMAKE_SOURCE_DIR}/src/config.h.in"
308 "${CMAKE_BINARY_DIR}/config.h"
309 "${ZIG_CONFIG_H_OUT}"
309310)
310311
311312include_directories(
......@@ -485,6 +486,7 @@ set(ZIG_INSTALL_ARGS "build"
485486 --override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
486487 "-Dlib-files-only"
487488 --prefix "${CMAKE_INSTALL_PREFIX}"
489 "-Dconfig_h=${ZIG_CONFIG_H_OUT}"
488490 install
489491)
490492
build.zig+22-10
......@@ -34,8 +34,14 @@ pub fn build(b: *Builder) !void {
3434
3535 const test_step = b.step("test", "Run all the tests");
3636
37 var ctx = try findAndParseConfigH(b);
38 ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);
37 const config_h_text = if (b.option(
38 []const u8,
39 "config_h",
40 "Path to the generated config.h",
41 )) |config_h_path|
42 try std.fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes)
43 else
44 try findAndReadConfigH(b);
3945
4046 var test_stage2 = b.addTest("src-self-hosted/test.zig");
4147 test_stage2.setBuildMode(builtin.Mode.Debug);
......@@ -46,9 +52,6 @@ pub fn build(b: *Builder) !void {
4652 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
4753 exe.setBuildMode(mode);
4854
49 try configureStage2(b, test_stage2, ctx);
50 try configureStage2(b, exe, ctx);
51
5255 const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false;
5356 const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
5457 const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;
......@@ -62,6 +65,12 @@ pub fn build(b: *Builder) !void {
6265
6366 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
6467 if (!only_install_lib_files and !skip_self_hosted) {
68 var ctx = parseConfigH(config_h_text);
69 ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);
70
71 try configureStage2(b, test_stage2, ctx);
72 try configureStage2(b, exe, ctx);
73
6574 b.default_step.dependOn(&exe.step);
6675 exe.install();
6776 }
......@@ -343,14 +352,15 @@ const Context = struct {
343352 llvm: LibraryDep,
344353};
345354
346fn findAndParseConfigH(b: *Builder) !Context {
355const max_config_h_bytes = 1 * 1024 * 1024;
356
357fn findAndReadConfigH(b: *Builder) ![]const u8 {
347358 var check_dir = fs.path.dirname(b.zig_exe).?;
348 const config_h_text = while (true) {
359 while (true) {
349360 var dir = try fs.cwd().openDir(check_dir, .{});
350361 defer dir.close();
351362
352 const max_bytes = 1 * 1024 * 1024;
353 const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_bytes) catch |err| switch (err) {
363 const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
354364 error.FileNotFound => {
355365 const new_check_dir = fs.path.dirname(check_dir);
356366 if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
......@@ -363,9 +373,11 @@ fn findAndParseConfigH(b: *Builder) !Context {
363373 },
364374 else => |e| return e,
365375 };
366 break config_h_text;
376 return config_h_text;
367377 } else unreachable; // TODO should not need `else unreachable`.
378}
368379
380fn parseConfigH(config_h_text: []const u8) Context {
369381 var ctx: Context = .{
370382 .cmake_binary_dir = undefined,
371383 .cxx_compiler = undefined,