| author | |
| committer | |
| log | 7eb0a3edcef2ab752ff1e45e6f1316b633b29606 |
| tree | 152cce9cc48d92b8a8b319fb71c0aa83e44e8eec |
| parent | 39ee46a6c1b5a56129950953d304a1169b7ffa67 |
| signature |
Rather than `zig0 build ...` the build now does
`zig0 build-lib ...`, avoiding the requirement of linking the build
script, and thus avoiding the requirement of finding native libc,
for systems where libc is the system ABI.6 files changed, 90 insertions(+), 80 deletions(-)
CMakeLists.txt+41-22| ... | ... | @@ -604,28 +604,29 @@ else() |
| 604 | 604 | set(LIBUSERLAND "${CMAKE_BINARY_DIR}/libuserland.a") |
| 605 | 605 | endif() |
| 606 | 606 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") |
| 607 | set(LIBUSERLAND_RELEASE_MODE "false") | |
| 607 | set(LIBUSERLAND_RELEASE_ARG "") | |
| 608 | 608 | else() |
| 609 | set(LIBUSERLAND_RELEASE_MODE "true") | |
| 609 | set(LIBUSERLAND_RELEASE_ARG "--release-fast --strip") | |
| 610 | endif() | |
| 611 | if(WIN32) | |
| 612 | set(LIBUSERLAND_WINDOWS_ARGS "-lntdll") | |
| 613 | else() | |
| 614 | set(LIBUSERLAND_WINDOWS_ARGS "") | |
| 610 | 615 | endif() |
| 611 | 616 | |
| 612 | set(BUILD_LIBUSERLAND_ARGS "build" | |
| 617 | set(BUILD_LIBUSERLAND_ARGS "build-lib" | |
| 613 | 618 | --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" |
| 614 | "-Doutput-dir=${CMAKE_BINARY_DIR}" | |
| 615 | "-Drelease=${LIBUSERLAND_RELEASE_MODE}" | |
| 616 | "-Dlib-files-only" | |
| 617 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 618 | libuserland | |
| 619 | --cache on | |
| 620 | --output-dir "${CMAKE_BINARY_DIR}" | |
| 621 | ${LIBUSERLAND_RELEASE_ARG} | |
| 622 | "src-self-hosted/stage1.zig" | |
| 623 | --disable-gen-h | |
| 624 | --bundle-compiler-rt | |
| 625 | -fPIC | |
| 626 | -lc | |
| 627 | ${LIBUSERLAND_WINDOWS_ARGS} | |
| 619 | 628 | ) |
| 620 | 629 | |
| 621 | # When using Visual Studio build system generator we default to libuserland install. | |
| 622 | if(MSVC) | |
| 623 | set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix") | |
| 624 | if(NOT ZIG_SKIP_INSTALL_LIB_FILES) | |
| 625 | set(BUILD_LIBUSERLAND_ARGS ${BUILD_LIBUSERLAND_ARGS} install) | |
| 626 | endif() | |
| 627 | endif() | |
| 628 | ||
| 629 | 630 | add_custom_target(zig_build_libuserland ALL |
| 630 | 631 | COMMAND zig0 ${BUILD_LIBUSERLAND_ARGS} |
| 631 | 632 | DEPENDS zig0 |
| ... | ... | @@ -648,12 +649,30 @@ add_dependencies(zig zig_build_libuserland) |
| 648 | 649 | |
| 649 | 650 | install(TARGETS zig DESTINATION bin) |
| 650 | 651 | |
| 651 | # CODE has no effect with Visual Studio build system generator. | |
| 652 | if(NOT MSVC) | |
| 653 | get_target_property(zig0_BINARY_DIR zig0 BINARY_DIR) | |
| 654 | install(CODE "set(zig0_EXE \"${zig0_BINARY_DIR}/zig0\")") | |
| 655 | install(CODE "set(INSTALL_LIBUSERLAND_ARGS \"${BUILD_LIBUSERLAND_ARGS}\" install)") | |
| 656 | install(CODE "set(BUILD_LIBUSERLAND_ARGS \"${BUILD_LIBUSERLAND_ARGS}\")") | |
| 652 | set(ZIG_INSTALL_ARGS "build" | |
| 653 | --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" | |
| 654 | "-Dlib-files-only" | |
| 655 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 656 | install | |
| 657 | ) | |
| 658 | ||
| 659 | # CODE has no effect with Visual Studio build system generator, therefore | |
| 660 | # when using Visual Studio build system generator we resort to running | |
| 661 | # `zig build install` during the build phase. | |
| 662 | if(MSVC) | |
| 663 | set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL | |
| 664 | "Windows-only: Disable copying lib/ files to install prefix during the build phase") | |
| 665 | if(NOT ZIG_SKIP_INSTALL_LIB_FILES) | |
| 666 | add_custom_target(zig_install_lib_files ALL | |
| 667 | COMMAND zig ${ZIG_INSTALL_ARGS} | |
| 668 | DEPENDS zig | |
| 669 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" | |
| 670 | ) | |
| 671 | endif() | |
| 672 | else() | |
| 673 | get_target_property(zig_BINARY_DIR zig BINARY_DIR) | |
| 674 | install(CODE "set(zig_EXE \"${zig_BINARY_DIR}/zig\")") | |
| 675 | install(CODE "set(ZIG_INSTALL_ARGS \"${ZIG_INSTALL_ARGS}\")") | |
| 657 | 676 | install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")") |
| 658 | 677 | install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake) |
| 659 | 678 | endif() |
build.zig-27| ... | ... | @@ -64,8 +64,6 @@ pub fn build(b: *Builder) !void { |
| 64 | 64 | try configureStage2(b, test_stage2, ctx); |
| 65 | 65 | try configureStage2(b, exe, ctx); |
| 66 | 66 | |
| 67 | addLibUserlandStep(b, mode); | |
| 68 | ||
| 69 | 67 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; |
| 70 | 68 | const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; |
| 71 | 69 | const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release; |
| ... | ... | @@ -366,28 +364,3 @@ const Context = struct { |
| 366 | 364 | dia_guids_lib: []const u8, |
| 367 | 365 | llvm: LibraryDep, |
| 368 | 366 | }; |
| 369 | ||
| 370 | fn addLibUserlandStep(b: *Builder, mode: builtin.Mode) void { | |
| 371 | const artifact = b.addStaticLibrary("userland", "src-self-hosted/stage1.zig"); | |
| 372 | artifact.disable_gen_h = true; | |
| 373 | artifact.bundle_compiler_rt = true; | |
| 374 | artifact.setTarget(builtin.arch, builtin.os, builtin.abi); | |
| 375 | artifact.setBuildMode(mode); | |
| 376 | artifact.force_pic = true; | |
| 377 | if (mode != .Debug) { | |
| 378 | artifact.strip = true; | |
| 379 | } | |
| 380 | artifact.linkSystemLibrary("c"); | |
| 381 | if (builtin.os == .windows) { | |
| 382 | artifact.linkSystemLibrary("ntdll"); | |
| 383 | } | |
| 384 | const libuserland_step = b.step("libuserland", "Build the userland compiler library for use in stage1"); | |
| 385 | libuserland_step.dependOn(&artifact.step); | |
| 386 | ||
| 387 | const output_dir = b.option( | |
| 388 | []const u8, | |
| 389 | "output-dir", | |
| 390 | "For libuserland step, where to put the output", | |
| 391 | ) orelse return; | |
| 392 | artifact.setOutputDir(output_dir); | |
| 393 | } |
cmake/install.cmake+6-6| ... | ... | @@ -1,16 +1,16 @@ |
| 1 | 1 | message("-- Installing: ${CMAKE_INSTALL_PREFIX}/lib") |
| 2 | 2 | |
| 3 | if(NOT EXISTS ${zig0_EXE}) | |
| 3 | if(NOT EXISTS ${zig_EXE}) | |
| 4 | 4 | message("::") |
| 5 | 5 | message(":: ERROR: Executable not found") |
| 6 | 6 | message(":: (execute_process)") |
| 7 | 7 | message("::") |
| 8 | message(":: executable: ${zig0_EXE}") | |
| 8 | message(":: executable: ${zig_EXE}") | |
| 9 | 9 | message("::") |
| 10 | 10 | message(FATAL_ERROR) |
| 11 | 11 | endif() |
| 12 | 12 | |
| 13 | execute_process(COMMAND ${zig0_EXE} ${INSTALL_LIBUSERLAND_ARGS} | |
| 13 | execute_process(COMMAND ${zig_EXE} ${ZIG_INSTALL_ARGS} | |
| 14 | 14 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 15 | 15 | RESULT_VARIABLE _result |
| 16 | 16 | ) |
| ... | ... | @@ -19,11 +19,11 @@ if(_result) |
| 19 | 19 | message(":: ERROR: ${_result}") |
| 20 | 20 | message(":: (execute_process)") |
| 21 | 21 | |
| 22 | string(REPLACE ";" " " s_INSTALL_LIBUSERLAND_ARGS "${INSTALL_LIBUSERLAND_ARGS}") | |
| 22 | string(REPLACE ";" " " s_INSTALL_LIBUSERLAND_ARGS "${ZIG_INSTALL_ARGS}") | |
| 23 | 23 | message("::") |
| 24 | message(":: argv: ${zig0_EXE} ${s_INSTALL_LIBUSERLAND_ARGS} install") | |
| 24 | message(":: argv: ${zig_EXE} ${s_INSTALL_LIBUSERLAND_ARGS}") | |
| 25 | 25 | |
| 26 | set(_args ${zig0_EXE} ${INSTALL_LIBUSERLAND_ARGS}) | |
| 26 | set(_args ${zig_EXE} ${ZIG_INSTALL_ARGS}) | |
| 27 | 27 | list(LENGTH _args _len) |
| 28 | 28 | math(EXPR _len "${_len} - 1") |
| 29 | 29 | message("::") |
src-self-hosted/libc_installation.zig+11-8| ... | ... | @@ -204,14 +204,17 @@ pub const LibCInstallation = struct { |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | } else { |
| 207 | var batch = Batch(FindError!void, 2, .auto_async).init(); | |
| 208 | batch.add(&async self.findNativeIncludeDirPosix(allocator)); | |
| 209 | if (is_freebsd or is_netbsd) { | |
| 210 | self.crt_dir = try std.mem.dupeZ(allocator, u8, "/usr/lib"); | |
| 211 | } else if (is_linux or is_dragonfly) { | |
| 212 | batch.add(&async self.findNativeCrtDirPosix(allocator)); | |
| 213 | } | |
| 214 | try batch.wait(); | |
| 207 | try blk: { | |
| 208 | var batch = Batch(FindError!void, 2, .auto_async).init(); | |
| 209 | errdefer batch.wait() catch {}; | |
| 210 | batch.add(&async self.findNativeIncludeDirPosix(allocator)); | |
| 211 | if (is_freebsd or is_netbsd) { | |
| 212 | self.crt_dir = try std.mem.dupeZ(allocator, u8, "/usr/lib"); | |
| 213 | } else if (is_linux or is_dragonfly) { | |
| 214 | batch.add(&async self.findNativeCrtDirPosix(allocator)); | |
| 215 | } | |
| 216 | break :blk batch.wait(); | |
| 217 | }; | |
| 215 | 218 | } |
| 216 | 219 | return self; |
| 217 | 220 | } |
src/main.cpp+30-4| ... | ... | @@ -1003,9 +1003,22 @@ static int main0(int argc, char **argv) { |
| 1003 | 1003 | return main_exit(root_progress_node, EXIT_FAILURE); |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | // If both output_dir and enable_cache are provided, and doing build-lib, we | |
| 1007 | // will just do a file copy at the end. This helps when bootstrapping zig from zig0 | |
| 1008 | // because we want to pass something like this: | |
| 1009 | // zig0 build-lib --cache on --output-dir ${CMAKE_BINARY_DIR} | |
| 1010 | // And we don't have access to `zig0 build` because that would require detecting native libc | |
| 1011 | // on systems where we are not able to build a libc from source for them. | |
| 1012 | // But that's the only reason this works, so otherwise we give an error here. | |
| 1013 | Buf *final_output_dir_step = nullptr; | |
| 1006 | 1014 | if (output_dir != nullptr && enable_cache == CacheOptOn) { |
| 1007 | fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n"); | |
| 1008 | return print_error_usage(arg0); | |
| 1015 | if (cmd == CmdBuild && out_type == OutTypeLib) { | |
| 1016 | final_output_dir_step = output_dir; | |
| 1017 | output_dir = nullptr; | |
| 1018 | } else { | |
| 1019 | fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n"); | |
| 1020 | return print_error_usage(arg0); | |
| 1021 | } | |
| 1009 | 1022 | } |
| 1010 | 1023 | |
| 1011 | 1024 | if (target_requires_pic(&target, have_libc) && want_pic == WantPICDisabled) { |
| ... | ... | @@ -1290,8 +1303,21 @@ static int main0(int argc, char **argv) { |
| 1290 | 1303 | #if defined(ZIG_OS_WINDOWS) |
| 1291 | 1304 | buf_replace(&g->output_file_path, '/', '\\'); |
| 1292 | 1305 | #endif |
| 1293 | if (printf("%s\n", buf_ptr(&g->output_file_path)) < 0) | |
| 1294 | return main_exit(root_progress_node, EXIT_FAILURE); | |
| 1306 | if (final_output_dir_step != nullptr) { | |
| 1307 | Buf *dest_basename = buf_alloc(); | |
| 1308 | os_path_split(&g->output_file_path, nullptr, dest_basename); | |
| 1309 | Buf *dest_path = buf_alloc(); | |
| 1310 | os_path_join(final_output_dir_step, dest_basename, dest_path); | |
| 1311 | ||
| 1312 | if ((err = os_copy_file(&g->output_file_path, dest_path))) { | |
| 1313 | fprintf(stderr, "unable to copy %s to %s: %s\n", buf_ptr(&g->output_file_path), | |
| 1314 | buf_ptr(dest_path), err_str(err)); | |
| 1315 | return main_exit(root_progress_node, EXIT_FAILURE); | |
| 1316 | } | |
| 1317 | } else { | |
| 1318 | if (printf("%s\n", buf_ptr(&g->output_file_path)) < 0) | |
| 1319 | return main_exit(root_progress_node, EXIT_FAILURE); | |
| 1320 | } | |
| 1295 | 1321 | } |
| 1296 | 1322 | return main_exit(root_progress_node, EXIT_SUCCESS); |
| 1297 | 1323 | } else { |
src/userland.cpp+2-13| ... | ... | @@ -146,19 +146,8 @@ int stage2_cmd_targets(const char *zig_triple) { |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | enum Error stage2_libc_parse(struct Stage2LibCInstallation *libc, const char *libc_file) { |
| 149 | libc->include_dir = "/dummy/include"; | |
| 150 | libc->include_dir_len = strlen(libc->include_dir); | |
| 151 | libc->sys_include_dir = "/dummy/sys/include"; | |
| 152 | libc->sys_include_dir_len = strlen(libc->sys_include_dir); | |
| 153 | libc->crt_dir = ""; | |
| 154 | libc->crt_dir_len = strlen(libc->crt_dir); | |
| 155 | libc->static_crt_dir = ""; | |
| 156 | libc->static_crt_dir_len = strlen(libc->static_crt_dir); | |
| 157 | libc->msvc_lib_dir = ""; | |
| 158 | libc->msvc_lib_dir_len = strlen(libc->msvc_lib_dir); | |
| 159 | libc->kernel32_lib_dir = ""; | |
| 160 | libc->kernel32_lib_dir_len = strlen(libc->kernel32_lib_dir); | |
| 161 | return ErrorNone; | |
| 149 | const char *msg = "stage0 called stage2_libc_parse"; | |
| 150 | stage2_panic(msg, strlen(msg)); | |
| 162 | 151 | } |
| 163 | 152 | |
| 164 | 153 | enum Error stage2_libc_render(struct Stage2LibCInstallation *self, FILE *file) { |