From 291a50aff50840385a17a7c5ffa029c070251817 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Wed, 25 Sep 2024 12:42:47 -0700 Subject: [PATCH] Fix zig build (#14163) --- cmake/Globals.cmake | 8 +++++++- cmake/scripts/DownloadUrl.cmake | 4 +--- cmake/scripts/DownloadZig.cmake | 16 ++++++++-------- scripts/build.mjs | 24 ++---------------------- 4 files changed, 18 insertions(+), 34 deletions(-) diff --git a/cmake/Globals.cmake b/cmake/Globals.cmake index 54cc5cba6e..3b9714548b 100644 --- a/cmake/Globals.cmake +++ b/cmake/Globals.cmake @@ -129,7 +129,13 @@ else() set(WARNING WARNING) endif() -optionx(VENDOR_PATH FILEPATH "The path to the vendor directory" DEFAULT ${CWD}/vendor) +if(CI) + set(DEFAULT_VENDOR_PATH ${CACHE_PATH}/vendor) +else() + set(DEFAULT_VENDOR_PATH ${CWD}/vendor) +endif() + +optionx(VENDOR_PATH FILEPATH "The path to the vendor directory" DEFAULT ${DEFAULT_VENDOR_PATH}) optionx(TMP_PATH FILEPATH "The path to the temporary directory" DEFAULT ${BUILD_PATH}/tmp) optionx(FRESH BOOL "Set when --fresh is used" DEFAULT OFF) diff --git a/cmake/scripts/DownloadUrl.cmake b/cmake/scripts/DownloadUrl.cmake index b9a6929bf2..c8801de005 100644 --- a/cmake/scripts/DownloadUrl.cmake +++ b/cmake/scripts/DownloadUrl.cmake @@ -125,7 +125,5 @@ else() file(RENAME ${DOWNLOAD_TMP_FILE} ${DOWNLOAD_PATH}) endif() -get_filename_component(DOWNLOAD_FILENAME ${DOWNLOAD_PATH} NAME) -message(STATUS "Saved ${DOWNLOAD_FILENAME}") - file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH}) +message(STATUS "Saved ${DOWNLOAD_PATH}") diff --git a/cmake/scripts/DownloadZig.cmake b/cmake/scripts/DownloadZig.cmake index d1c97dfc74..f7f9d8789e 100644 --- a/cmake/scripts/DownloadZig.cmake +++ b/cmake/scripts/DownloadZig.cmake @@ -38,7 +38,6 @@ else() set(ZIG_FILENAME ${ZIG_NAME}.tar.xz) endif() -message(STATUS "Downloading ${ZIG_EXE} ${ZIG_VERSION} on ${ZIG_OS} ${ZIG_ARCH}...") set(ZIG_DOWNLOAD_URL https://ziglang.org/download/${ZIG_VERSION}/${ZIG_FILENAME}) execute_process( @@ -59,7 +58,7 @@ if(NOT ZIG_DOWNLOAD_RESULT EQUAL 0) endif() if(NOT EXISTS ${ZIG_PATH}/${ZIG_EXE}) - message(FATAL_ERROR "Download failed: executable not found: \"${ZIG_PATH}/${ZIG_EXE}\"") + message(FATAL_ERROR "Executable not found: \"${ZIG_PATH}/${ZIG_EXE}\"") endif() # Tools like VSCode need a stable path to the zig executable, on both Unix and Windows @@ -68,12 +67,12 @@ if(NOT WIN32) file(CREATE_LINK ${ZIG_PATH}/${ZIG_EXE} ${ZIG_PATH}/zig.exe SYMBOLIC) endif() -message(STATUS "Downloading zig library at ${ZIG_COMMIT}...") +set(ZIG_REPOSITORY_PATH ${ZIG_PATH}/repository) execute_process( COMMAND ${CMAKE_COMMAND} - -DGIT_PATH=${ZIG_PATH}/tmp + -DGIT_PATH=${ZIG_REPOSITORY_PATH} -DGIT_REPOSITORY=oven-sh/zig -DGIT_COMMIT=${ZIG_COMMIT} -P ${CMAKE_CURRENT_LIST_DIR}/GitClone.cmake @@ -89,8 +88,9 @@ if(NOT ZIG_REPOSITORY_RESULT EQUAL 0) endif() file(REMOVE_RECURSE ${ZIG_PATH}/lib) -file(RENAME ${ZIG_PATH}/tmp/lib ${ZIG_PATH}/lib) -file(REMOVE_RECURSE ${ZIG_PATH}/tmp) -message(STATUS "Saved ${ZIG_PATH}/lib") -message(STATUS "Saved ${ZIG_EXE}") +# Use copy_directory instead of file(RENAME) because there were +# race conditions in CI where some files were not copied. +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${ZIG_REPOSITORY_PATH}/lib ${ZIG_PATH}/lib) + +file(REMOVE_RECURSE ${ZIG_REPOSITORY_PATH}) diff --git a/scripts/build.mjs b/scripts/build.mjs index 82f3bc7b4e..b620d7964f 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -1,8 +1,8 @@ #!/usr/bin/env node import { spawn as nodeSpawn } from "node:child_process"; -import { existsSync, readFileSync, readdirSync, mkdirSync, cpSync, chmodSync } from "node:fs"; -import { basename, join, relative, resolve } from "node:path"; +import { existsSync, readFileSync, mkdirSync, cpSync, chmodSync } from "node:fs"; +import { basename, join, resolve } from "node:path"; // https://cmake.org/cmake/help/latest/manual/cmake.1.html#generate-a-project-buildsystem const generateFlags = [ @@ -118,26 +118,6 @@ async function build(args) { .flatMap(([flag, value]) => [flag, value]); await spawn("cmake", buildArgs, { env }, "compilation"); - const buildFiles = ["ccache.log", "compile_commands.json"]; - const buildPaths = [buildPath, ...readdirSync(buildPath).map(path => join(buildPath, path))]; - const buildArtifacts = []; - for (const buildPath of buildPaths) { - for (const buildFile of buildFiles) { - const path = join(buildPath, buildFile); - if (existsSync(path)) { - buildArtifacts.push(path); - } - } - } - - if (isBuildkite()) { - await Promise.all( - buildArtifacts.map(path => - spawn("buildkite-agent", ["artifact", "upload", relative(buildPath, path)], { cwd: buildPath, env }), - ), - ); - } - printDuration("total", Date.now() - startTime); }