Skip to content

musl: support build-llvm-musl#1718

Merged
kito-cheng merged 1 commit intoriscv-collab:masterfrom
zqb-all:musl-llvm
Mar 27, 2026
Merged

musl: support build-llvm-musl#1718
kito-cheng merged 1 commit intoriscv-collab:masterfrom
zqb-all:musl-llvm

Conversation

@zqb-all
Copy link
Copy Markdown
Contributor

@zqb-all zqb-all commented May 16, 2025

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.

@zqb-all zqb-all marked this pull request as ready for review March 26, 2026 15:54
@kito-cheng kito-cheng requested a review from Copilot March 26, 2026 16:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-musl and a musl top-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_SETUP macro.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Makefile.in Outdated
Comment on lines +1242 to +1243
cp $(notdir $@)/lib/riscv$(XLEN)-unknown-linux-musl/libc++* $(SYSROOT)/lib
cp $(notdir $@)/lib/riscv$(XLEN)-unknown-linux-musl/libunwind* $(SYSROOT)/lib
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
ln -s -f $(INSTALL_DIR)/lib/gcc $(SYSROOT)/lib/gcc
ln -s -f ../../lib/gcc $(SYSROOT)/lib/gcc

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Collaborator

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@kito-cheng kito-cheng merged commit c7b3494 into riscv-collab:master Mar 27, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants