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")...@@ -303,9 +303,10 @@ set(LIBC_FILES_DEST "${ZIG_LIB_DIR}/libc")
303set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")303set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")
304set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")304set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")
305set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")305set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
306set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h")
306configure_file (307configure_file (
307 "${CMAKE_SOURCE_DIR}/src/config.h.in"308 "${CMAKE_SOURCE_DIR}/src/config.h.in"
308 "${CMAKE_BINARY_DIR}/config.h"309 "${ZIG_CONFIG_H_OUT}"
309)310)
310311
311include_directories(312include_directories(
...@@ -485,6 +486,7 @@ set(ZIG_INSTALL_ARGS "build"...@@ -485,6 +486,7 @@ set(ZIG_INSTALL_ARGS "build"
485 --override-lib-dir "${CMAKE_SOURCE_DIR}/lib"486 --override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
486 "-Dlib-files-only"487 "-Dlib-files-only"
487 --prefix "${CMAKE_INSTALL_PREFIX}"488 --prefix "${CMAKE_INSTALL_PREFIX}"
489 "-Dconfig_h=${ZIG_CONFIG_H_OUT}"
488 install490 install
489)491)
490492
build.zig+22-10
...@@ -34,8 +34,14 @@ pub fn build(b: *Builder) !void {...@@ -34,8 +34,14 @@ pub fn build(b: *Builder) !void {
3434
35 const test_step = b.step("test", "Run all the tests");35 const test_step = b.step("test", "Run all the tests");
3636
37 var ctx = try findAndParseConfigH(b);37 const config_h_text = if (b.option(
38 ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);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
40 var test_stage2 = b.addTest("src-self-hosted/test.zig");46 var test_stage2 = b.addTest("src-self-hosted/test.zig");
41 test_stage2.setBuildMode(builtin.Mode.Debug);47 test_stage2.setBuildMode(builtin.Mode.Debug);
...@@ -46,9 +52,6 @@ pub fn build(b: *Builder) !void {...@@ -46,9 +52,6 @@ pub fn build(b: *Builder) !void {
46 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");52 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
47 exe.setBuildMode(mode);53 exe.setBuildMode(mode);
4854
49 try configureStage2(b, test_stage2, ctx);
50 try configureStage2(b, exe, ctx);
51
52 const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false;55 const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false;
53 const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;56 const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
54 const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;57 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 {...@@ -62,6 +65,12 @@ pub fn build(b: *Builder) !void {
6265
63 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;66 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
64 if (!only_install_lib_files and !skip_self_hosted) {67 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
65 b.default_step.dependOn(&exe.step);74 b.default_step.dependOn(&exe.step);
66 exe.install();75 exe.install();
67 }76 }
...@@ -343,14 +352,15 @@ const Context = struct {...@@ -343,14 +352,15 @@ const Context = struct {
343 llvm: LibraryDep,352 llvm: LibraryDep,
344};353};
345354
346fn findAndParseConfigH(b: *Builder) !Context {355const max_config_h_bytes = 1 * 1024 * 1024;
356
357fn findAndReadConfigH(b: *Builder) ![]const u8 {
347 var check_dir = fs.path.dirname(b.zig_exe).?;358 var check_dir = fs.path.dirname(b.zig_exe).?;
348 const config_h_text = while (true) {359 while (true) {
349 var dir = try fs.cwd().openDir(check_dir, .{});360 var dir = try fs.cwd().openDir(check_dir, .{});
350 defer dir.close();361 defer dir.close();
351362
352 const max_bytes = 1 * 1024 * 1024;363 const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
353 const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_bytes) catch |err| switch (err) {
354 error.FileNotFound => {364 error.FileNotFound => {
355 const new_check_dir = fs.path.dirname(check_dir);365 const new_check_dir = fs.path.dirname(check_dir);
356 if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {366 if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
...@@ -363,9 +373,11 @@ fn findAndParseConfigH(b: *Builder) !Context {...@@ -363,9 +373,11 @@ fn findAndParseConfigH(b: *Builder) !Context {
363 },373 },
364 else => |e| return e,374 else => |e| return e,
365 };375 };
366 break config_h_text;376 return config_h_text;
367 } else unreachable; // TODO should not need `else unreachable`.377 } else unreachable; // TODO should not need `else unreachable`.
378}
368379
380fn parseConfigH(config_h_text: []const u8) Context {
369 var ctx: Context = .{381 var ctx: Context = .{
370 .cmake_binary_dir = undefined,382 .cmake_binary_dir = undefined,
371 .cxx_compiler = undefined,383 .cxx_compiler = undefined,