| author | |
| committer | |
| log | b72f858194a3f6391de06d83ffa49596cfce21a4 |
| tree | 98952511a648bf22edddb12e6fe358e99ba606d3 |
| parent | b5ac079f88e9098ea9c95356518820a5c3fb42a8 |
| parent | b9f4ac86efc8bd1e53c75d204aa6f08c2df58be3 |
| signature |
cmake: support `make` and `make install`3 files changed, 86 insertions(+), 27 deletions(-)
CMakeLists.txt+29-12| ... | ... | @@ -45,7 +45,6 @@ message("Configuring zig version ${ZIG_VERSION}") |
| 45 | 45 | |
| 46 | 46 | set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)") |
| 47 | 47 | set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries") |
| 48 | set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix") | |
| 49 | 48 | set(ZIG_ENABLE_MEM_PROFILE off CACHE BOOL "Activate memory usage instrumentation") |
| 50 | 49 | |
| 51 | 50 | if(ZIG_STATIC) |
| ... | ... | @@ -608,19 +607,26 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") |
| 608 | 607 | else() |
| 609 | 608 | set(LIBUSERLAND_RELEASE_MODE "true") |
| 610 | 609 | endif() |
| 611 | if(ZIG_SKIP_INSTALL_LIB_FILES) | |
| 612 | set(ZIG_BUILD_INSTALL_STEP "") | |
| 613 | else() | |
| 614 | set(ZIG_BUILD_INSTALL_STEP "install") | |
| 610 | ||
| 611 | set(BUILD_LIBUSERLAND_ARGS "build" | |
| 612 | --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" | |
| 613 | "-Doutput-dir=${CMAKE_BINARY_DIR}" | |
| 614 | "-Drelease=${LIBUSERLAND_RELEASE_MODE}" | |
| 615 | "-Dlib-files-only" | |
| 616 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 617 | libuserland | |
| 618 | ) | |
| 619 | ||
| 620 | # When using Visual Studio build system generator we default to libuserland install. | |
| 621 | if(MSVC) | |
| 622 | set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix") | |
| 623 | if(NOT ZIG_SKIP_INSTALL_LIB_FILES) | |
| 624 | set(BUILD_LIBUSERLAND_ARGS ${BUILD_LIBUSERLAND_ARGS} install) | |
| 625 | endif() | |
| 615 | 626 | endif() |
| 627 | ||
| 616 | 628 | add_custom_target(zig_build_libuserland ALL |
| 617 | COMMAND zig0 build | |
| 618 | --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" | |
| 619 | libuserland ${ZIG_BUILD_INSTALL_STEP} | |
| 620 | "-Doutput-dir=${CMAKE_BINARY_DIR}" | |
| 621 | "-Drelease=${LIBUSERLAND_RELEASE_MODE}" | |
| 622 | "-Dlib-files-only" | |
| 623 | --prefix "${CMAKE_INSTALL_PREFIX}" | |
| 629 | COMMAND zig0 ${BUILD_LIBUSERLAND_ARGS} | |
| 624 | 630 | DEPENDS zig0 |
| 625 | 631 | BYPRODUCTS "${LIBUSERLAND}" |
| 626 | 632 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| ... | ... | @@ -638,4 +644,15 @@ elseif(MINGW) |
| 638 | 644 | target_link_libraries(zig ntdll) |
| 639 | 645 | endif() |
| 640 | 646 | add_dependencies(zig zig_build_libuserland) |
| 647 | ||
| 641 | 648 | install(TARGETS zig DESTINATION bin) |
| 649 | ||
| 650 | # CODE has no effect with Visual Studio build system generator. | |
| 651 | if(NOT MSVC) | |
| 652 | get_target_property(zig0_BINARY_DIR zig0 BINARY_DIR) | |
| 653 | install(CODE "set(zig0_EXE \"${zig0_BINARY_DIR}/zig0\")") | |
| 654 | install(CODE "set(INSTALL_LIBUSERLAND_ARGS \"${BUILD_LIBUSERLAND_ARGS}\" install)") | |
| 655 | install(CODE "set(BUILD_LIBUSERLAND_ARGS \"${BUILD_LIBUSERLAND_ARGS}\")") | |
| 656 | install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")") | |
| 657 | install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake) | |
| 658 | endif() |
CONTRIBUTING.md+20-15| ... | ... | @@ -51,23 +51,28 @@ knowledge of Zig internals.** |
| 51 | 51 | |
| 52 | 52 | ### Editing Source Code |
| 53 | 53 | |
| 54 | First, build the Stage 1 compiler as described in [the Building section](#building). | |
| 55 | ||
| 56 | One modification you may want to make is adding `-DZIG_SKIP_INSTALL_LIB_FILES=ON` | |
| 57 | to the cmake line. If you use the build directory as a working directory to run | |
| 58 | tests with, zig will find the lib files in the source directory, and they will not | |
| 59 | be "installed" every time you run `make`. This will allow you to make modifications | |
| 60 | directly to the standard library, for example, and have them effective immediately. | |
| 61 | Note that if you already ran `make` or `make install` with the default cmake | |
| 62 | settings, there will already be a `lib/` directory in your build directory. When | |
| 63 | executed from the build directory, zig will find this instead of the source lib/ | |
| 64 | directory. Remove the unwanted directory so that the desired one can be found. | |
| 54 | First, build the Stage 1 compiler as described in [Building from Source](README.md#Building-from-Source). | |
| 55 | ||
| 56 | Zig locates lib files relative to executable path by searching up the | |
| 57 | filesystem tree for a sub-path of `lib/zig/std/std.zig` or `lib/std/std.zig`. | |
| 58 | Typically the former is an install and the latter a git working tree which | |
| 59 | contains the build directory. | |
| 60 | ||
| 61 | During development it is not necessary to perform installs when modifying | |
| 62 | stage1 or userland sources and in fact it is faster and simpler to run, | |
| 63 | test and debug from a git working tree. | |
| 64 | ||
| 65 | - `make` is typically sufficient to build zig during development iterations. | |
| 66 | - `make install` performs a build __and__ install. | |
| 67 | - `msbuild -p:Configuration=Release INSTALL.vcxproj` on Windows performs a | |
| 68 | build and install. To avoid install, pass cmake option `-DZIG_SKIP_INSTALL_LIB_FILES=ON`. | |
| 65 | 69 | |
| 66 | 70 | To test changes, do the following from the build directory: |
| 67 | 71 | |
| 68 | 1. Run `make install` (on POSIX) or | |
| 72 | 1. Run `make` (on POSIX) or | |
| 69 | 73 | `msbuild -p:Configuration=Release INSTALL.vcxproj` (on Windows). |
| 70 | 2. `bin/zig build test` (on POSIX) or `bin\zig.exe build test` (on Windows). | |
| 74 | 2. `$BUILD_DIR/zig build test` (on POSIX) or | |
| 75 | `$BUILD_DIR/Release\zig.exe build test` (on Windows). | |
| 71 | 76 | |
| 72 | 77 | That runs the whole test suite, which does a lot of extra testing that you |
| 73 | 78 | likely won't always need, and can take upwards of 1 hour. This is what the |
| ... | ... | @@ -85,8 +90,8 @@ Another example is choosing a different set of things to test. For example, |
| 85 | 90 | not the other ones. Combining this suggestion with the previous one, you could |
| 86 | 91 | do this: |
| 87 | 92 | |
| 88 | `bin/zig build test-std -Dskip-release` (on POSIX) or | |
| 89 | `bin\zig.exe build test-std -Dskip-release` (on Windows). | |
| 93 | `$BUILD_DIR/bin/zig build test-std -Dskip-release` (on POSIX) or | |
| 94 | `$BUILD_DIR/Release\zig.exe build test-std -Dskip-release` (on Windows). | |
| 90 | 95 | |
| 91 | 96 | This will run only the standard library tests, in debug mode only, for all |
| 92 | 97 | targets (it will cross-compile the tests for non-native targets but not run |
cmake/install.cmake created+37| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | message("-- Installing: ${CMAKE_INSTALL_PREFIX}/lib") | |
| 2 | ||
| 3 | if(NOT EXISTS ${zig0_EXE}) | |
| 4 | message("::") | |
| 5 | message(":: ERROR: Executable not found") | |
| 6 | message(":: (execute_process)") | |
| 7 | message("::") | |
| 8 | message(":: executable: ${zig0_EXE}") | |
| 9 | message("::") | |
| 10 | message(FATAL_ERROR) | |
| 11 | endif() | |
| 12 | ||
| 13 | execute_process(COMMAND ${zig0_EXE} ${INSTALL_LIBUSERLAND_ARGS} | |
| 14 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| 15 | RESULT_VARIABLE _result | |
| 16 | ) | |
| 17 | if(_result) | |
| 18 | message("::") | |
| 19 | message(":: ERROR: ${_result}") | |
| 20 | message(":: (execute_process)") | |
| 21 | ||
| 22 | string(REPLACE ";" " " s_INSTALL_LIBUSERLAND_ARGS "${INSTALL_LIBUSERLAND_ARGS}") | |
| 23 | message("::") | |
| 24 | message(":: argv: ${zig0_EXE} ${s_INSTALL_LIBUSERLAND_ARGS} install") | |
| 25 | ||
| 26 | set(_args ${zig0_EXE} ${INSTALL_LIBUSERLAND_ARGS}) | |
| 27 | list(LENGTH _args _len) | |
| 28 | math(EXPR _len "${_len} - 1") | |
| 29 | message("::") | |
| 30 | foreach(_i RANGE 0 ${_len}) | |
| 31 | list(GET _args ${_i} _arg) | |
| 32 | message(":: argv[${_i}]: ${_arg}") | |
| 33 | endforeach() | |
| 34 | ||
| 35 | message("::") | |
| 36 | message(FATAL_ERROR) | |
| 37 | endif() |