mirror of
https://github.com/ziglang/zig.git
synced 2025-12-12 17:23:09 +00:00
cmake: support make and make install
(2nd attempt to get this right)
This commit is contained in:
parent
b5ac079f88
commit
b9f4ac86ef
@ -45,7 +45,6 @@ message("Configuring zig version ${ZIG_VERSION}")
|
|||||||
|
|
||||||
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
|
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
|
||||||
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
|
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
|
||||||
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix")
|
|
||||||
set(ZIG_ENABLE_MEM_PROFILE off CACHE BOOL "Activate memory usage instrumentation")
|
set(ZIG_ENABLE_MEM_PROFILE off CACHE BOOL "Activate memory usage instrumentation")
|
||||||
|
|
||||||
if(ZIG_STATIC)
|
if(ZIG_STATIC)
|
||||||
@ -608,19 +607,26 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
|||||||
else()
|
else()
|
||||||
set(LIBUSERLAND_RELEASE_MODE "true")
|
set(LIBUSERLAND_RELEASE_MODE "true")
|
||||||
endif()
|
endif()
|
||||||
if(ZIG_SKIP_INSTALL_LIB_FILES)
|
|
||||||
set(ZIG_BUILD_INSTALL_STEP "")
|
set(BUILD_LIBUSERLAND_ARGS "build"
|
||||||
else()
|
|
||||||
set(ZIG_BUILD_INSTALL_STEP "install")
|
|
||||||
endif()
|
|
||||||
add_custom_target(zig_build_libuserland ALL
|
|
||||||
COMMAND zig0 build
|
|
||||||
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
|
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
|
||||||
libuserland ${ZIG_BUILD_INSTALL_STEP}
|
|
||||||
"-Doutput-dir=${CMAKE_BINARY_DIR}"
|
"-Doutput-dir=${CMAKE_BINARY_DIR}"
|
||||||
"-Drelease=${LIBUSERLAND_RELEASE_MODE}"
|
"-Drelease=${LIBUSERLAND_RELEASE_MODE}"
|
||||||
"-Dlib-files-only"
|
"-Dlib-files-only"
|
||||||
--prefix "${CMAKE_INSTALL_PREFIX}"
|
--prefix "${CMAKE_INSTALL_PREFIX}"
|
||||||
|
libuserland
|
||||||
|
)
|
||||||
|
|
||||||
|
# When using Visual Studio build system generator we default to libuserland install.
|
||||||
|
if(MSVC)
|
||||||
|
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Disable copying lib/ files to install prefix")
|
||||||
|
if(NOT ZIG_SKIP_INSTALL_LIB_FILES)
|
||||||
|
set(BUILD_LIBUSERLAND_ARGS ${BUILD_LIBUSERLAND_ARGS} install)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_custom_target(zig_build_libuserland ALL
|
||||||
|
COMMAND zig0 ${BUILD_LIBUSERLAND_ARGS}
|
||||||
DEPENDS zig0
|
DEPENDS zig0
|
||||||
BYPRODUCTS "${LIBUSERLAND}"
|
BYPRODUCTS "${LIBUSERLAND}"
|
||||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||||
@ -638,4 +644,15 @@ elseif(MINGW)
|
|||||||
target_link_libraries(zig ntdll)
|
target_link_libraries(zig ntdll)
|
||||||
endif()
|
endif()
|
||||||
add_dependencies(zig zig_build_libuserland)
|
add_dependencies(zig zig_build_libuserland)
|
||||||
|
|
||||||
install(TARGETS zig DESTINATION bin)
|
install(TARGETS zig DESTINATION bin)
|
||||||
|
|
||||||
|
# CODE has no effect with Visual Studio build system generator.
|
||||||
|
if(NOT MSVC)
|
||||||
|
get_target_property(zig0_BINARY_DIR zig0 BINARY_DIR)
|
||||||
|
install(CODE "set(zig0_EXE \"${zig0_BINARY_DIR}/zig0\")")
|
||||||
|
install(CODE "set(INSTALL_LIBUSERLAND_ARGS \"${BUILD_LIBUSERLAND_ARGS}\" install)")
|
||||||
|
install(CODE "set(BUILD_LIBUSERLAND_ARGS \"${BUILD_LIBUSERLAND_ARGS}\")")
|
||||||
|
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
|
||||||
|
install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake)
|
||||||
|
endif()
|
||||||
|
|||||||
@ -51,23 +51,28 @@ knowledge of Zig internals.**
|
|||||||
|
|
||||||
### Editing Source Code
|
### Editing Source Code
|
||||||
|
|
||||||
First, build the Stage 1 compiler as described in [the Building section](#building).
|
First, build the Stage 1 compiler as described in [Building from Source](README.md#Building-from-Source).
|
||||||
|
|
||||||
One modification you may want to make is adding `-DZIG_SKIP_INSTALL_LIB_FILES=ON`
|
Zig locates lib files relative to executable path by searching up the
|
||||||
to the cmake line. If you use the build directory as a working directory to run
|
filesystem tree for a sub-path of `lib/zig/std/std.zig` or `lib/std/std.zig`.
|
||||||
tests with, zig will find the lib files in the source directory, and they will not
|
Typically the former is an install and the latter a git working tree which
|
||||||
be "installed" every time you run `make`. This will allow you to make modifications
|
contains the build directory.
|
||||||
directly to the standard library, for example, and have them effective immediately.
|
|
||||||
Note that if you already ran `make` or `make install` with the default cmake
|
During development it is not necessary to perform installs when modifying
|
||||||
settings, there will already be a `lib/` directory in your build directory. When
|
stage1 or userland sources and in fact it is faster and simpler to run,
|
||||||
executed from the build directory, zig will find this instead of the source lib/
|
test and debug from a git working tree.
|
||||||
directory. Remove the unwanted directory so that the desired one can be found.
|
|
||||||
|
- `make` is typically sufficient to build zig during development iterations.
|
||||||
|
- `make install` performs a build __and__ install.
|
||||||
|
- `msbuild -p:Configuration=Release INSTALL.vcxproj` on Windows performs a
|
||||||
|
build and install. To avoid install, pass cmake option `-DZIG_SKIP_INSTALL_LIB_FILES=ON`.
|
||||||
|
|
||||||
To test changes, do the following from the build directory:
|
To test changes, do the following from the build directory:
|
||||||
|
|
||||||
1. Run `make install` (on POSIX) or
|
1. Run `make` (on POSIX) or
|
||||||
`msbuild -p:Configuration=Release INSTALL.vcxproj` (on Windows).
|
`msbuild -p:Configuration=Release INSTALL.vcxproj` (on Windows).
|
||||||
2. `bin/zig build test` (on POSIX) or `bin\zig.exe build test` (on Windows).
|
2. `$BUILD_DIR/zig build test` (on POSIX) or
|
||||||
|
`$BUILD_DIR/Release\zig.exe build test` (on Windows).
|
||||||
|
|
||||||
That runs the whole test suite, which does a lot of extra testing that you
|
That runs the whole test suite, which does a lot of extra testing that you
|
||||||
likely won't always need, and can take upwards of 1 hour. This is what the
|
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,
|
|||||||
not the other ones. Combining this suggestion with the previous one, you could
|
not the other ones. Combining this suggestion with the previous one, you could
|
||||||
do this:
|
do this:
|
||||||
|
|
||||||
`bin/zig build test-std -Dskip-release` (on POSIX) or
|
`$BUILD_DIR/bin/zig build test-std -Dskip-release` (on POSIX) or
|
||||||
`bin\zig.exe build test-std -Dskip-release` (on Windows).
|
`$BUILD_DIR/Release\zig.exe build test-std -Dskip-release` (on Windows).
|
||||||
|
|
||||||
This will run only the standard library tests, in debug mode only, for all
|
This will run only the standard library tests, in debug mode only, for all
|
||||||
targets (it will cross-compile the tests for non-native targets but not run
|
targets (it will cross-compile the tests for non-native targets but not run
|
||||||
|
|||||||
37
cmake/install.cmake
Normal file
37
cmake/install.cmake
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
message("-- Installing: ${CMAKE_INSTALL_PREFIX}/lib")
|
||||||
|
|
||||||
|
if(NOT EXISTS ${zig0_EXE})
|
||||||
|
message("::")
|
||||||
|
message(":: ERROR: Executable not found")
|
||||||
|
message(":: (execute_process)")
|
||||||
|
message("::")
|
||||||
|
message(":: executable: ${zig0_EXE}")
|
||||||
|
message("::")
|
||||||
|
message(FATAL_ERROR)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
execute_process(COMMAND ${zig0_EXE} ${INSTALL_LIBUSERLAND_ARGS}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
RESULT_VARIABLE _result
|
||||||
|
)
|
||||||
|
if(_result)
|
||||||
|
message("::")
|
||||||
|
message(":: ERROR: ${_result}")
|
||||||
|
message(":: (execute_process)")
|
||||||
|
|
||||||
|
string(REPLACE ";" " " s_INSTALL_LIBUSERLAND_ARGS "${INSTALL_LIBUSERLAND_ARGS}")
|
||||||
|
message("::")
|
||||||
|
message(":: argv: ${zig0_EXE} ${s_INSTALL_LIBUSERLAND_ARGS} install")
|
||||||
|
|
||||||
|
set(_args ${zig0_EXE} ${INSTALL_LIBUSERLAND_ARGS})
|
||||||
|
list(LENGTH _args _len)
|
||||||
|
math(EXPR _len "${_len} - 1")
|
||||||
|
message("::")
|
||||||
|
foreach(_i RANGE 0 ${_len})
|
||||||
|
list(GET _args ${_i} _arg)
|
||||||
|
message(":: argv[${_i}]: ${_arg}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
message("::")
|
||||||
|
message(FATAL_ERROR)
|
||||||
|
endif()
|
||||||
Loading…
x
Reference in New Issue
Block a user