Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow external zig in CMake #17159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ register_command(
ARTIFACTS
${BUN_ZIG_OUTPUT}
TARGETS
clone-zig
${BUN_ZIG_TARGETS}
SOURCES
${BUN_ZIG_SOURCES}
${BUN_ZIG_GENERATED_SOURCES}
Expand Down
64 changes: 40 additions & 24 deletions cmake/tools/SetupZig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,50 @@ optionx(ZIG_GLOBAL_CACHE_DIR FILEPATH "The path to the global zig cache director
setenv(ZIG_LOCAL_CACHE_DIR ${ZIG_LOCAL_CACHE_DIR})
setenv(ZIG_GLOBAL_CACHE_DIR ${ZIG_GLOBAL_CACHE_DIR})

setx(ZIG_PATH ${VENDOR_PATH}/zig)
if(ZIG_PATH AND NOT ZIG_EXECUTABLE)
if(WIN32)
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig.exe)
else()
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig)
endif()
elseif(NOT ZIG_EXECUTABLE)
setx(ZIG_PATH ${VENDOR_PATH}/zig)

if(WIN32)
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig.exe)
else()
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig)
if(WIN32)
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig.exe)
else()
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig)
endif()

set(BUN_ZIG_TARGETS clone-zig)
register_command(
TARGET
clone-zig
COMMENT
"Downloading zig"
COMMAND
${CMAKE_COMMAND}
-DZIG_PATH=${ZIG_PATH}
-DZIG_VERSION=${ZIG_VERSION}
-DZIG_COMMIT=${ZIG_COMMIT}
-DENABLE_ASAN=${ENABLE_ASAN}
-P ${CWD}/cmake/scripts/DownloadZig.cmake
SOURCES
${CWD}/cmake/scripts/DownloadZig.cmake
OUTPUTS
${ZIG_EXECUTABLE}
)
endif()

if(NOT ZIG_LIB_DIR)
execute_process(COMMAND "${ZIG_EXECUTABLE}" env
OUTPUT_VARIABLE ZIG_ENV)

string(JSON ZIG_LIB_DIR GET "${ZIG_ENV}" "lib_dir")
endif()

set(CMAKE_ZIG_FLAGS
--cache-dir ${ZIG_LOCAL_CACHE_DIR}
--global-cache-dir ${ZIG_GLOBAL_CACHE_DIR}
--zig-lib-dir ${ZIG_PATH}/lib
)

register_command(
TARGET
clone-zig
COMMENT
"Downloading zig"
COMMAND
${CMAKE_COMMAND}
-DZIG_PATH=${ZIG_PATH}
-DZIG_VERSION=${ZIG_VERSION}
-DZIG_COMMIT=${ZIG_COMMIT}
-DENABLE_ASAN=${ENABLE_ASAN}
-P ${CWD}/cmake/scripts/DownloadZig.cmake
SOURCES
${CWD}/cmake/scripts/DownloadZig.cmake
OUTPUTS
${ZIG_EXECUTABLE}
--zig-lib-dir ${ZIG_LIB_DIR}
)