Skip to content

Commit

Permalink
try manual musl gcc config on debian
Browse files Browse the repository at this point in the history
  • Loading branch information
vszakats committed Oct 11, 2023
1 parent aa3ca4a commit 17ca19e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
34 changes: 14 additions & 20 deletions _build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -677,15 +677,6 @@ build_single_target() {
if [ "${_CC}" = 'llvm' ]; then
ccver="$("clang${_CCSUFFIX}" -dumpversion)"
else
if [ "${_CRT}" = 'musl' ] && [ "${_HOST}" != 'mac' ] && [ "${_DISTRO}" != 'alpine' ]; then
# method 1
# FIXME: Downside: supports the prefix-less gcc only.
# Migrate to the manual method for better control over this.
# Only for CC, not for binutils
_CCPREFIX='musl-'
_CCSUFFIX=''
fi

ccver="$("${_CCPREFIX}gcc${_CCSUFFIX}" -dumpversion)"

if [ "${_CRT}" = 'ucrt' ]; then
Expand Down Expand Up @@ -833,11 +824,7 @@ build_single_target() {
fi

export _LD
if [ "${_CCPREFIX}" = 'musl-' ]; then # Do not apply the Debian 'musl-' prefix to binutils
_BINUTILS_PREFIX=''
else
_BINUTILS_PREFIX="${_CCPREFIX}"
fi
_BINUTILS_PREFIX="${_CCPREFIX}"
_BINUTILS_SUFFIX=''
if [ "${_TOOLCHAIN}" = 'llvm-apple' ]; then
_arch="${_machine}"
Expand Down Expand Up @@ -988,11 +975,7 @@ build_single_target() {
fi

_CMAKE_GLOBAL="${_CMAKE_GLOBAL} -DCMAKE_C_COMPILER=${_CCPREFIX}gcc${_CCSUFFIX}"
if [ "${_CCPREFIX}" != 'musl-' ]; then
_CMAKE_CXX_GLOBAL="${_CMAKE_CXX_GLOBAL} -DCMAKE_CXX_COMPILER=${_CCPREFIX}g++${_CCSUFFIX}"
else
_CMAKE_CXX_GLOBAL="${_CMAKE_CXX_GLOBAL} -DCMAKE_CXX_COMPILER=g++"
fi
_CMAKE_CXX_GLOBAL="${_CMAKE_CXX_GLOBAL} -DCMAKE_CXX_COMPILER=${_CCPREFIX}g++${_CCSUFFIX}"

_LD='ld'

Expand Down Expand Up @@ -1142,14 +1125,25 @@ build_single_target() {
fi
fi

if [ "${_CC}" = 'gcc' ] && [ "${_CRT}" = 'musl' ] && [ "${_DISTRO}" = 'debian' ]; then
clangrtlib="$("${_CCPREFIX}gcc${_CCSUFFIX}" -print-libgcc-file-name)" # /usr/lib/gcc/aarch64-linux-gnu/10/libgcc.a
clangrsdir="$(dirname "${clangrtlib}")" # /usr/lib/gcc/aarch64-linux-gnu/10
clangrtlib="$(basename "${clangrtlib}" | cut -c 4-)" # delete 'lib' prefix
clangrtlib="${clangrtlib%.*}" # gcc
libprefix="/usr/lib/${_machine}-linux-musl"
_CFLAGS_GLOBAL="${_CFLAGS_GLOBAL} -nostdinc -isystem ${clangrsdir}/include -isystem /usr/include/${_machine}-linux-musl"
_LDFLAGS_GLOBAL="${_LDFLAGS_GLOBAL} -nostdlib -nodefaultlibs -nostartfiles -L${libprefix} ${libprefix}/crt1.o ${libprefix}/crti.o -L${clangrsdir} ${libprefix}/crtn.o"
_LIBS_GLOBAL="${_LIBS_GLOBAL} -lc -l${clangrtlib}"
fi

if [ "${_CCRT}" = 'clang-rt' ]; then
if [ "${_TOOLCHAIN}" != 'llvm-apple' ]; then
if [ "${_CRT}" = 'musl' ] && [ "${_DISTRO}" = 'debian' ]; then
# This method should also work to replace the `_CCPREFIX='musl-'` solution we use with gcc.
clangrsdir="$("clang${_CCSUFFIX}" -print-resource-dir)" # /usr/lib/llvm-13/lib/clang/13.0.1
clangrtdir="$("clang${_CCSUFFIX}" -print-runtime-dir)" # /usr/lib/llvm-13/lib/clang/13.0.1/lib/linux
clangrtlib="$("clang${_CCSUFFIX}" -print-libgcc-file-name -rtlib=compiler-rt)" # /usr/lib/llvm-13/lib/clang/13.0.1/lib/linux/libclang_rt.builtins-aarch64.a
clangrtlib="$(basename "${clangrtlib}" | cut -c 4-)"
clangrtlib="$(basename "${clangrtlib}" | cut -c 4-)" # delete 'lib' prefix
clangrtlib="${clangrtlib%.*}" # clang_rt.builtins-aarch64
libprefix="/usr/lib/${_machine}-linux-musl"
_CFLAGS_GLOBAL="${_CFLAGS_GLOBAL} -nostdinc -isystem ${clangrsdir}/include -isystem /usr/include/${_machine}-linux-musl"
Expand Down
11 changes: 6 additions & 5 deletions _ci-linux-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ if [[ "${CW_CONFIG:-}" = *'win'* ]]; then
extra="${extra} nasm"
fi
elif [[ "${CW_CONFIG:-}" = *'linux'* ]]; then
[ -n "${CW_GCCSUFFIX:-}" ] || CW_GCCSUFFIX='-13'
extra="${extra} checksec"
if [[ "${CW_CONFIG:-}" = *'gcc'* ]]; then
extra="${extra} gcc${CW_GCCSUFFIX} g++${CW_GCCSUFFIX}"
export CW_CCSUFFIX="${CW_GCCSUFFIX}"
fi
if [[ "${CW_CONFIG:-}" = *'musl'* ]]; then
extra="${extra} musl musl-dev musl-tools"
[[ "${CW_CONFIG:-}" = *'gcc'* ]] && extra="${extra} g++"
extra="${extra} musl musl-dev"
# for openssl 'secure-memory' feature
if [ "$(uname -m)" = 'aarch64' ]; then
extra="${extra} linux-headers-arm64"
elif [ "$(uname -m)" = 'x86_64' ]; then
extra="${extra} linux-headers-amd64"
fi
else
[ -n "${CW_GCCSUFFIX:-}" ] || CW_GCCSUFFIX='-13'
if [[ "${CW_CONFIG:-}" = *'gcc'* ]]; then
extra="${extra} gcc${CW_GCCSUFFIX} g++${CW_GCCSUFFIX}"
export CW_CCSUFFIX="${CW_GCCSUFFIX}"
if [ "$(uname -m)" = 'aarch64' ]; then
extra="${extra} gcc${CW_GCCSUFFIX}-x86-64-linux-gnu g++${CW_GCCSUFFIX}-x86-64-linux-gnu"
else
Expand Down

0 comments on commit 17ca19e

Please sign in to comment.