Skip to content

Commit aa20537

Browse files
committed
fix(llvm): restore build
1 parent 89954bb commit aa20537

5 files changed

Lines changed: 80 additions & 33 deletions

File tree

packages/llvm/cmake/Distribution-stage2.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
2020
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
2121
set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
2222

23-
# NOTE - the coresponding CMAKE_EXE_LINKER_FLAGS is set in `llvm.tg.ts`.
23+
# Set linker flags for executables and shared libraries.
24+
# The dynamic linker and RPATH are configured via cmake variables below.
2425
set(CMAKE_SHARED_LINKER_FLAGS "-unwindlib=libunwind" CACHE STRING "")
2526

2627
# Set up LLVM configuration.
@@ -30,7 +31,16 @@ set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
3031
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
3132
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
3233
set(CMAKE_INSTALL_LIBDIR lib CACHE STRING "")
33-
set(CMAKE_SKIP_INSTALL_RPATH ON CACHE BOOL "")
34+
35+
# Configure RPATH for installed binaries. Use $ORIGIN for relocatable binaries.
36+
# TANGRAM_HOST_TRIPLE is passed from tangram.ts to set the host-specific library path.
37+
set(CMAKE_SKIP_INSTALL_RPATH OFF CACHE BOOL "")
38+
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
39+
if(TANGRAM_HOST_TRIPLE)
40+
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib;$ORIGIN/../lib/${TANGRAM_HOST_TRIPLE}" CACHE STRING "")
41+
else()
42+
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib" CACHE STRING "")
43+
endif()
3444

3545
# Define toolchain components.
3646
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")

packages/llvm/tangram.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const toolchain = async (arg?: LLVMArg) => {
5252
sdk,
5353
source: source_,
5454
} = arg ?? {};
55-
const host = host_ ?? std.triple.host();
55+
const host = std.sdk.canonicalTriple(host_ ?? std.triple.host());
5656
const build = build_ ?? host;
5757

5858
const sourceDir = source_ ?? source();
@@ -69,13 +69,7 @@ export const toolchain = async (arg?: LLVMArg) => {
6969
.then((d) => d.get(host))
7070
.then(tg.Directory.expect);
7171

72-
const env = await std.env.arg(
73-
...deps,
74-
{
75-
CFLAGS: tg.Mutation.suffix("-Wno-unused-command-line-argument", " "),
76-
},
77-
env_,
78-
);
72+
const env = await std.env.arg(...deps, env_, { utils: false });
7973

8074
const ldsoName = glibc.interpreterName(host);
8175
// Ensure that stage2 unproxied binaries are runnable during the build, before we have a chance to wrap them post-install.
@@ -84,19 +78,18 @@ export const toolchain = async (arg?: LLVMArg) => {
8478
const stage2ExeLinkerFlags = tg`-Wl,-dynamic-linker=${sysroot}/lib/${ldsoName} -unwindlib=libunwind`;
8579

8680
// Ensure that stage2 unproxied binaries are able to locate libraries during the build, without hardcoding rpaths. We'll wrap them afterwards.
87-
const prepare = tg`set -x && export HOME=$PWD && export LD_LIBRARY_PATH="${sysroot}/lib:${zlibNgArtifact}/lib:${ncursesArtifact}/lib:$HOME/build/lib:$HOME/build/lib/${host}"`;
81+
const prepare = tg`set -x && export HOME=$PWD && export LD_LIBRARY_PATH="${sysroot}/lib:${zlibNgArtifact}/lib:$HOME/build/lib:$HOME/build/lib/${host}"`;
8882

8983
// Define default flags.
9084
const configure = {
9185
args: [
9286
tg`-DBOOTSTRAP_CMAKE_EXE_LINKER_FLAGS='${stage2ExeLinkerFlags}'`,
9387
tg`-DDEFAULT_SYSROOT=${sysroot}`,
9488
`-DLLVM_HOST_TRIPLE=${host}`,
89+
`-DTANGRAM_HOST_TRIPLE=${host}`,
9590
"-DLLVM_PARALLEL_LINK_JOBS=1",
96-
tg`-DTerminfo_ROOT=${ncursesArtifact}`,
97-
tg`-DBOOTSTRAP_Terminfo_ROOT=${ncursesArtifact}`,
9891
tg`-DZLIB_ROOT=${zlibNgArtifact}`,
99-
`-DCLANG_BOOTSTRAP_PASSTHROUGH="DEFAULT_SYSROOT;LLVM_PARALLEL_LINK_JOBS;ZLIB_ROOT"`,
92+
`-DCLANG_BOOTSTRAP_PASSTHROUGH="DEFAULT_SYSROOT;LLVM_PARALLEL_LINK_JOBS;ZLIB_ROOT;TANGRAM_HOST_TRIPLE"`,
10093
],
10194
};
10295

@@ -120,15 +113,22 @@ export const toolchain = async (arg?: LLVMArg) => {
120113
const phases = { prepare, configure, build: buildPhase, install };
121114

122115
let llvmArtifact = await cmake.build({
123-
...(await std.triple.rotate({ build, host })),
116+
host: build,
117+
target: host,
124118
env,
125119
phases,
126120
sdk,
127121
source: tg`${sourceDir}/llvm`,
128122
});
129123

130-
// Add sysroot and symlinks.
124+
// Merge zlib-ng libraries into the artifact so $ORIGIN-based RPATH can find them.
125+
const zlibLibDir = await tg.Directory.expect(zlibNgArtifact)
126+
.get("lib")
127+
.then(tg.Directory.expect);
128+
129+
// Add sysroot, zlib libs, and symlinks.
131130
llvmArtifact = await tg.directory(llvmArtifact, sysroot, {
131+
lib: zlibLibDir,
132132
"bin/ar": tg.symlink("llvm-ar"),
133133
"bin/cc": tg.symlink("clang"),
134134
"bin/c++": tg.symlink("clang++"),
@@ -142,15 +142,13 @@ export const toolchain = async (arg?: LLVMArg) => {
142142
});
143143

144144
// The bootstrap compiler was not proxied. Manually wrap the output binaries.
145-
// With the sysroot embedded, binaries can find libraries relative to their location.
146-
// We still wrap to ensure the interpreter is correct.
145+
// With $ORIGIN-based RPATH embedded during build, binaries can find libraries
146+
// relative to their location. We still wrap to ensure the interpreter is correct.
147147

148-
// Collect all required library paths.
148+
// Collect library paths for non-clang binaries that may not have RPATH set.
149149
const libDir = llvmArtifact.get("lib").then(tg.Directory.expect);
150150
const hostLibDir = libDir.then((d) => d.get(host)).then(tg.Directory.expect);
151-
const ncursesLibDir = ncursesArtifact.get("lib").then(tg.Directory.expect);
152-
const zlibLibDir = zlibNgArtifact.get("lib").then(tg.Directory.expect);
153-
const libraryPaths = [libDir, hostLibDir, ncursesLibDir, zlibLibDir];
151+
const libraryPaths = [libDir, hostLibDir];
154152

155153
// Wrap all ELF binaries in the bin directory, except clang-XX which must not be
156154
// wrapped to preserve /proc/self/exe for the -cc1 driver.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Fix const-correctness in strchr casts for glibc >= 2.43.
2+
3+
glibc 2.43 introduced ISO C23 const-preserving _Generic macros for strchr
4+
and similar functions. When the input is const char *, strchr now returns
5+
const char * instead of char *, causing a -Werror=discarded-qualifiers
6+
failure. Remove the unnecessary const casts.
7+
8+
Upstream fix: https://github.com/besser82/libxcrypt/commit/174c24d6e87aeae631bc0a7bb1ba983cf8def4de
9+
10+
diff --git a/lib/crypt-gost-yescrypt.c b/lib/crypt-gost-yescrypt.c
11+
--- a/lib/crypt-gost-yescrypt.c
12+
+++ b/lib/crypt-gost-yescrypt.c
13+
@@ -131,7 +131,7 @@
14+
intbuf->outbuf[1] = 'g';
15+
16+
/* extract yescrypt output from "$y$param$salt$output" */
17+
- char *hptr = strchr ((const char *) intbuf->retval + 3, '$');
18+
+ char *hptr = strchr ((char *) intbuf->retval + 3, '$');
19+
if (!hptr)
20+
{
21+
errno = EINVAL;
22+
diff --git a/lib/crypt-sm3-yescrypt.c b/lib/crypt-sm3-yescrypt.c
23+
--- a/lib/crypt-sm3-yescrypt.c
24+
+++ b/lib/crypt-sm3-yescrypt.c
25+
@@ -136,7 +136,7 @@
26+
intbuf->outbuf[3] = '3';
27+
28+
/* extract yescrypt output from "$y$param$salt$output" */
29+
- char *hptr = strchr ((const char *) intbuf->retval + 3, '$');
30+
+ char *hptr = strchr ((char *) intbuf->retval + 3, '$');
31+
if (!hptr)
32+
{
33+
errno = EINVAL;

packages/std/sdk/dependencies/libxcrypt.tg.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as std from "../../tangram.ts";
2+
import * as bootstrap from "../../bootstrap.tg.ts";
3+
import strchrConstFix from "./libxcrypt-strchr-const-fix.patch" with { type: "file" };
24

35
export const metadata = {
46
homepage: "https://github.com/besser82/libxcrypt",
@@ -16,15 +18,17 @@ export const source = () => {
1618
const tag = `v${version}`;
1719
const checksum =
1820
"sha256:71513a31c01a428bccd5367a32fd95f115d6dac50fb5b60c779d5c7942aec071";
19-
return std.download.fromGithub({
20-
checksum,
21-
compression: "xz",
22-
owner,
23-
source: "release",
24-
repo,
25-
tag,
26-
version,
27-
});
21+
return std.download
22+
.fromGithub({
23+
checksum,
24+
compression: "xz",
25+
owner,
26+
source: "release",
27+
repo,
28+
tag,
29+
version,
30+
})
31+
.then((dir) => bootstrap.patch(dir, strchrConstFix));
2832
};
2933

3034
export type Arg = std.autotools.Arg;
@@ -45,8 +49,6 @@ export const build = async (...args: std.Args<Arg>) => {
4549

4650
export default build;
4751

48-
import * as bootstrap from "../../bootstrap.tg.ts";
49-
5052
export const test = async () => {
5153
const host = bootstrap.toolchainTriple(std.triple.host());
5254
const sdkArg = await bootstrap.sdk.arg(host);

scripts/package_automation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ const PACKAGE_EXPORT_MATRICES: Record<string, ExportMatrix> = {
533533
{ ref: "default", tagPath: "default" },
534534
{ ref: "self", tagPath: "self" },
535535
],
536+
llvm: [
537+
{ ref: "default", tagPath: "default" },
538+
{ ref: "libclang", tagPath: "libclang" },
539+
],
536540
poetry: [
537541
{ ref: "default", tagPath: "default" },
538542
{ ref: "self", tagPath: "self" },

0 commit comments

Comments
 (0)