Skip to content

Commit

Permalink
wrappers: Use config files for setting defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
mstorsjo committed Sep 14, 2024
1 parent e0af4d1 commit 39d6c9b
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 30 deletions.
4 changes: 4 additions & 0 deletions install-wrappers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ fi

mkdir -p "$PREFIX/bin"
cp wrappers/*-wrapper.sh "$PREFIX/bin"
cp wrappers/musl-common.cfg "$PREFIX/bin"
for arch in $ARCHS; do
cp wrappers/$arch*.cfg $PREFIX/bin
done
if [ -n "$HOST" ] && [ -n "$EXEEXT" ]; then
# TODO: If building natively on msys, pick up the default HOST value from there.
WRAPPER_FLAGS="$WRAPPER_FLAGS -DDEFAULT_TARGET=\"$HOST\""
Expand Down
2 changes: 2 additions & 0 deletions wrappers/aarch64-unknown-linux-musl.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-target aarch64-linux-musl
@musl-common.cfg
2 changes: 2 additions & 0 deletions wrappers/arm-unknown-linux-musleabihf.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-target armv7-linux-musleabihf
@musl-common.cfg
2 changes: 2 additions & 0 deletions wrappers/armv7-unknown-linux-musleabihf.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-target armv7-linux-musleabihf
@musl-common.cfg
20 changes: 1 addition & 19 deletions wrappers/clang-target-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ int _tmain(int argc, TCHAR* argv[]) {
split_argv(argv[0], &dir, NULL, &target, &exe);
if (!target)
target = _T(DEFAULT_TARGET);
TCHAR *arch = _tcsdup(target);
TCHAR *dash = _tcschr(arch, '-');
TCHAR *target_without_arch = NULL;
if (dash) {
*dash = '\0';
target_without_arch = dash + 1;
}

TCHAR *basedir = _tcsdup(dir);
size_t basedirlen = _tcslen(basedir);
Expand All @@ -48,12 +41,6 @@ int _tmain(int argc, TCHAR* argv[]) {
TCHAR *sep = _tcsrchrs(basedir, '/', '\\');
if (sep)
*(sep + 1) = '\0';
TCHAR *sysroot = concat(basedir, _T("generic-linux-musl"));
if (!_tcscmp(arch, _T("arm"))) {
arch = _T("armv7");
if (target_without_arch)
target = concat(_T("armv7-"), target_without_arch);
}

// Check if trying to compile Ada; if we try to do this, invoking clang
// would end up invoking <triplet>-gcc with the same arguments, which ends
Expand All @@ -65,7 +52,7 @@ int _tmain(int argc, TCHAR* argv[]) {
}
}

int max_arg = argc + 18;
int max_arg = argc + 17;
const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv));
int arg = 0;
if (getenv("CCACHE"))
Expand All @@ -83,11 +70,6 @@ int _tmain(int argc, TCHAR* argv[]) {

exec_argv[arg++] = _T("-target");
exec_argv[arg++] = target;
exec_argv[arg++] = concat(_T("--sysroot="), sysroot);
exec_argv[arg++] = _T("-rtlib=compiler-rt");
exec_argv[arg++] = _T("-unwindlib=libunwind");
exec_argv[arg++] = _T("-stdlib=libc++");
exec_argv[arg++] = _T("-fuse-ld=lld");
exec_argv[arg++] = _T("--end-no-unused-arguments");

for (int i = 1; i < argc; i++)
Expand Down
11 changes: 0 additions & 11 deletions wrappers/clang-target-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ DEFAULT_TARGET=x86_64-linux-musl
if [ "$TARGET" = "$BASENAME" ]; then
TARGET=$DEFAULT_TARGET
fi
ARCH="${TARGET%%-*}"
SYSROOT="$(dirname "$DIR")/generic-linux-musl"
if [ "$ARCH" = "arm" ]; then
# Convert arm-linux-musleabihf into armv7-linux-musleabihf
ARCH=armv7
TARGET=$ARCH-${TARGET#*-}
fi

# Check if trying to compile Ada; if we try to do this, invoking clang
# would end up invoking <triplet>-gcc with the same arguments, which ends
Expand Down Expand Up @@ -74,11 +68,6 @@ c11)
esac

FLAGS="$FLAGS -target $TARGET"
FLAGS="$FLAGS --sysroot=$SYSROOT"
FLAGS="$FLAGS -rtlib=compiler-rt"
FLAGS="$FLAGS -unwindlib=libunwind"
FLAGS="$FLAGS -stdlib=libc++"
FLAGS="$FLAGS -fuse-ld=lld"
FLAGS="$FLAGS --end-no-unused-arguments"

$CCACHE "$CLANG" $FLAGS "$@" $LINKER_FLAGS
2 changes: 2 additions & 0 deletions wrappers/i386-unknown-linux-musl.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-target i386-linux-musl
@musl-common.cfg
5 changes: 5 additions & 0 deletions wrappers/musl-common.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--sysroot=<CFGDIR>/../generic-linux-musl
-rtlib=compiler-rt
-unwindlib=libunwind
-stdlib=libc++
-fuse-ld=lld
2 changes: 2 additions & 0 deletions wrappers/powerpc64le-unknown-linux-musl.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-target powerpc64le-linux-musl
@musl-common.cfg
2 changes: 2 additions & 0 deletions wrappers/riscv64-unknown-linux-musl.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-target riscv64-linux-musl
@musl-common.cfg
2 changes: 2 additions & 0 deletions wrappers/x86_64-unknown-linux-musl.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-target x86_64-linux-musl
@musl-common.cfg

0 comments on commit 39d6c9b

Please sign in to comment.