Skip to content

Conversation

@Ryaningli
Copy link

Problem

When using RUSTFLAGS="-C target-feature=+crt-static" for static linking on non-Windows platforms (Linux/macOS), the build fails with linker errors. The current build.rs only handles static linking configuration for MSVC compiler but completely ignores GCC/Clang compilers.

Solution

Extend static linking support to GCC/Clang compilers by:

  • Detecting crt-static feature for all compiler types
  • Setting SPM_ENABLE_SHARED=OFF and SPM_BUILD_SHARED_LIBS=OFF for GCC/Clang when static linking is requested
  • This prevents CMake from building shared libraries when Rust expects static linking

Changes

Modified sentencepiece-sys/build.rs to:

  • Extract crt-static detection into a reusable variable
  • Add GCC/Clang static linking configuration mirroring the existing MSVC logic
  • Maintain backward compatibility with existing behavior

Testing

Verified that static linking now works correctly on Linux platforms with RUSTFLAGS="-C target-feature=+crt-static".

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.

1 participant