musl: support build-llvm-musl#1718
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new build-llvm-musl stamp target to build an LLVM/Clang toolchain targeting musl libc, while factoring out shared Linux LLVM CMake flags and sysroot setup logic to reduce duplication.
Changes:
- Introduce
stamps/build-llvm-musland amusltop-level target for LLVM toolchain builds targeting musl. - Extract common LLVM Linux CMake flags into
LLVM_LINUX_COMMON_CMAKE_FLAGS. - Extract sysroot/GCC-path workaround into the reusable
LLVM_LINUX_SYSROOT_SETUPmacro.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Makefile.in
Outdated
| cp $(notdir $@)/lib/riscv$(XLEN)-unknown-linux-musl/libc++* $(SYSROOT)/lib | ||
| cp $(notdir $@)/lib/riscv$(XLEN)-unknown-linux-musl/libunwind* $(SYSROOT)/lib |
There was a problem hiding this comment.
These cp paths hard-code the runtime output triple (riscv$(XLEN)-unknown-linux-musl) instead of using $(MUSL_TUPLE). This is brittle if MUSL_TUPLE differs from that pattern (or if LLVM’s runtime output directory naming changes). Prefer constructing the source path from $(MUSL_TUPLE) (or, better, rely on the install step/CMake install destinations rather than copying from the build tree) so the rule stays consistent with the configured target triple.
| cp $(notdir $@)/lib/riscv$(XLEN)-unknown-linux-musl/libc++* $(SYSROOT)/lib | |
| cp $(notdir $@)/lib/riscv$(XLEN)-unknown-linux-musl/libunwind* $(SYSROOT)/lib | |
| cp $(notdir $@)/lib/$(MUSL_TUPLE)/libc++* $(SYSROOT)/lib | |
| cp $(notdir $@)/lib/$(MUSL_TUPLE)/libunwind* $(SYSROOT)/lib |
There was a problem hiding this comment.
Addressed, similar cp command in build-llvm-linux has also been updated accordingly
Makefile.in
Outdated
| # Without a proper GCC install directory libgcc won't be found. | ||
| # As a workaround we have to merge both paths: | ||
| mkdir -p $(SYSROOT)/lib/ | ||
| ln -s -f $(INSTALL_DIR)/lib/gcc $(SYSROOT)/lib/gcc |
There was a problem hiding this comment.
This creates an absolute symlink into $(INSTALL_DIR), which can break relocatability of the resulting toolchain/sysroot if $(INSTALL_DIR) is moved after installation. If relocatable installs are a goal (suggested by the use of a relative DEFAULT_SYSROOT), consider making this symlink relative (from $(SYSROOT)/lib to $(INSTALL_DIR)/lib/gcc) or copying the needed GCC pieces into the sysroot instead.
| ln -s -f $(INSTALL_DIR)/lib/gcc $(SYSROOT)/lib/gcc | |
| ln -s -f ../../lib/gcc $(SYSROOT)/lib/gcc |
There was a problem hiding this comment.
Addressed, though I'm still uncertain about the actual impact once this soft link becomes invalid. It seems that we have been using absolute paths for a long time. When the packaged toolchain is extracted to a different environment, the paths are unlikely to match—meaning that many users are effectively working with a broken soft link.
Add stamps/build-llvm-musl target for LLVM toolchain builds targeting musl libc. Extract LLVM_LINUX_COMMON_CMAKE_FLAGS and LLVM_LINUX_SYSROOT_SETUP to reduce duplication with build-llvm-linux.
Add stamps/build-llvm-musl target for LLVM toolchain builds targeting musl libc. Extract LLVM_LINUX_COMMON_CMAKE_FLAGS and LLVM_LINUX_SYSROOT_SETUP to reduce duplication with build-llvm-linux.