From 8cdea1013951264b36e670ab4b7fefb2f7c64dea Mon Sep 17 00:00:00 2001 From: Ben Lovy Date: Fri, 3 Jan 2025 14:31:06 -0500 Subject: [PATCH] cmake changes --- ...00-linker-proxy-passthrough-conftest.patch | 16 ++++++ packages/cmake/tangram.ts | 49 ++++++++++++++----- 2 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 packages/cmake/patches/0000-linker-proxy-passthrough-conftest.patch diff --git a/packages/cmake/patches/0000-linker-proxy-passthrough-conftest.patch b/packages/cmake/patches/0000-linker-proxy-passthrough-conftest.patch new file mode 100644 index 00000000..59d09a92 --- /dev/null +++ b/packages/cmake/patches/0000-linker-proxy-passthrough-conftest.patch @@ -0,0 +1,16 @@ +diff --git a/Modules/TestBigEndian.cmake b/Modules/TestBigEndian.cmake +index 03c8588f..6f8f7213 100644 +--- a/Modules/TestBigEndian.cmake ++++ b/Modules/TestBigEndian.cmake +@@ -85,9 +85,11 @@ macro(__TEST_BIG_ENDIAN_LEGACY_IMPL VARIABLE) + file(READ "${CMAKE_ROOT}/Modules/TestEndianess.c.in" TEST_ENDIANESS_FILE_CONTENT) + string(CONFIGURE "${TEST_ENDIANESS_FILE_CONTENT}" TEST_ENDIANESS_FILE_CONTENT @ONLY) + ++ set(ENV{TANGRAM_LINKER_PASSTHROUGH} "TRUE") + try_compile(HAVE_${VARIABLE} + SOURCE_FROM_VAR "${_test_file}" TEST_ENDIANESS_FILE_CONTENT + COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" ) ++ unset(ENV{TANGRAM_LINKER_PASSTHROUGH}) + + if(HAVE_${VARIABLE}) + diff --git a/packages/cmake/tangram.ts b/packages/cmake/tangram.ts index 6ca9c5c2..fb914f12 100644 --- a/packages/cmake/tangram.ts +++ b/packages/cmake/tangram.ts @@ -4,10 +4,13 @@ import * as libpsl from "libpsl" with { path: "../libpsl" }; import * as make from "gnumake" with { path: "../gnumake" }; import * as ncurses from "ncurses" with { path: "../ncurses" }; import * as pkgConf from "pkgconf" with { path: "../pkgconf" }; +import * as pkgConfig from "pkg-config" with { path: "../pkgconf" }; import * as openssl from "openssl" with { path: "../openssl" }; import * as zlib from "zlib" with { path: "../zlib" }; import * as zstd from "zstd" with { path: "../zstd" }; +import patches from "./patches" with { type: "directory" }; + import * as ninja from "./ninja.tg.ts"; export * as ninja from "./ninja.tg.ts"; @@ -26,14 +29,16 @@ export const source = tg.target(() => { const owner = "Kitware"; const repo = "CMake"; const tag = `v${version}`; - return std.download.fromGithub({ - checksum, - owner, - repo, - source: "release", - tag, - version, - }); + return std.download + .fromGithub({ + checksum, + owner, + repo, + source: "release", + tag, + version, + }) + .then((source) => std.patch(source, patches)); }); export type Arg = { @@ -44,7 +49,6 @@ export type Arg = { libpsl?: libpsl.Arg; ncurses?: ncurses.Arg; openssl?: openssl.Arg; - pkgconf?: pkgConf.Arg; zlib?: zlib.Arg; zstd?: zstd.Arg; }; @@ -63,7 +67,6 @@ export const cmake = tg.target(async (...args: std.Args) => { libpsl: libpslArg = {}, ncurses: ncursesArg = {}, openssl: opensslArg = {}, - pkgconf: pkgconfArg = {}, zlib: zlibArg = {}, zstd: zstdArg = {}, } = {}, @@ -73,6 +76,7 @@ export const cmake = tg.target(async (...args: std.Args) => { source: source_, } = await std.args.apply(...args); const sourceDir = source_ ?? source(); + const os = std.triple.os(host); const curlRoot = curl.default_({ build, env: env_, host, sdk }, curlArg); const ncursesRoot = ncurses.default_( @@ -95,12 +99,30 @@ export const cmake = tg.target(async (...args: std.Args) => { args: [ "--parallel=$(nproc)", "--system-curl", + "--", + // "-DCMAKE_VERBOSE_MAKEFILE=ON", + // "-DFindZLIB_DEBUG=ON" + // tg`-DZLIB_ROOT=${zlibRoot}` + // "--debug-find", + // "--debug-output", + // "--trace-expand", + `-DCMAKE_LIBRARY_PATH="$(echo $LIBRARY_PATH | tr ':' ';')"`, + `-DCMAKE_INCLUDE_PATH="$(echo $CPATH | tr ':' ';')"`, + `-DCMAKE_VERBOSE_MAKEFILE=ON`, ], }; + const phases = { configure }; + + let pkgConfigRoot; + if (os === "linux") { + pkgConfigRoot = pkgConfig.default_({ build, host: build }); + } else { + pkgConfigRoot = pkgConf.default_({ build, host: build }); + } const deps = [ curlRoot, - pkgConf.default_({ build, host: build }, pkgconfArg), + pkgConfigRoot, ncursesRoot, libpslRoot, opensslRoot, @@ -108,7 +130,7 @@ export const cmake = tg.target(async (...args: std.Args) => { zstdRoot, ]; const env = [...deps, env_]; - if (std.triple.os(host) === "darwin") { + if (os === "darwin") { // On macOS, the bootstrap script wants to test for `ext/stdio_filebuf.h`, which is not part of the macOS toolchain. // Using the `gcc` and `g++` named symlinks to the AppleClang compiler instead of `clang`/`clang++` prevents this. env.push({ @@ -120,7 +142,8 @@ export const cmake = tg.target(async (...args: std.Args) => { const result = std.autotools.build({ ...(await std.triple.rotate({ build, host })), env: std.env.arg(...env), - phases: { configure }, + phases, + setRuntimeLibraryPath: os === "linux", sdk, source: sourceDir, });