Skip to content

Commit

Permalink
wrappers: Use clang config files for defaults
Browse files Browse the repository at this point in the history
This makes these defaults more easy to get picked up in various
use cases, when not directly executing a compiler.
  • Loading branch information
mstorsjo committed Nov 6, 2024
1 parent 0ebb52a commit e2e9216
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ARG CFGUARD_ARGS=--enable-cfguard

# Build everything that uses the llvm monorepo. We need to build the mingw runtime before the compiler-rt/libunwind/libcxxabi/libcxx runtimes.
COPY build-llvm.sh build-lldb-mi.sh strip-llvm.sh install-wrappers.sh build-mingw-w64.sh build-mingw-w64-tools.sh build-compiler-rt.sh build-libcxx.sh build-mingw-w64-libraries.sh build-openmp.sh ./
COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/
COPY wrappers/*.sh wrappers/*.c wrappers/*.h wrappers/*.cfg ./wrappers/
RUN ./build-llvm.sh $TOOLCHAIN_PREFIX && \
./build-lldb-mi.sh $TOOLCHAIN_PREFIX && \
./strip-llvm.sh $TOOLCHAIN_PREFIX && \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ARG TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64"
COPY build-mingw-w64.sh build-mingw-w64-tools.sh ./
RUN ./build-mingw-w64-tools.sh $CROSS_TOOLCHAIN_PREFIX --skip-include-triplet-prefix --host=$HOST

COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/
COPY wrappers/*.sh wrappers/*.c wrappers/*.h wrappers/*.cfg ./wrappers/
COPY install-wrappers.sh .
RUN ./install-wrappers.sh $CROSS_TOOLCHAIN_PREFIX --host=$HOST

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ RUN ./strip-llvm.sh $TOOLCHAIN_PREFIX
ARG TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64"

# Install the usual $TUPLE-clang binaries
COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/
COPY wrappers/*.sh wrappers/*.c wrappers/*.h wrappers/*.cfg ./wrappers/
COPY install-wrappers.sh ./
RUN ./install-wrappers.sh $TOOLCHAIN_PREFIX

Expand Down
3 changes: 3 additions & 0 deletions install-wrappers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ fi

mkdir -p "$PREFIX/bin"
cp wrappers/*-wrapper.sh "$PREFIX/bin"
for arch in $ARCHS; do
cp wrappers/$arch-w64-mingw32.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
6 changes: 6 additions & 0 deletions wrappers/aarch64-w64-mingw32.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-target aarch64-w64-mingw32
-rtlib=compiler-rt
-unwindlib=libunwind
-stdlib=libc++
-fuse-ld=lld
# SEH is the default for aarch64.
6 changes: 6 additions & 0 deletions wrappers/armv7-w64-mingw32.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-target armv7-w64-mingw32
-rtlib=compiler-rt
-unwindlib=libunwind
-stdlib=libc++
-fuse-ld=lld
# SEH is the default for armv7.
20 changes: 3 additions & 17 deletions wrappers/clang-target-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int _tmain(int argc, TCHAR* argv[]) {
}
}

int max_arg = argc + 22;
int max_arg = argc + 18;
const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv));
int arg = 0;
if (getenv("CCACHE"))
Expand All @@ -66,16 +66,6 @@ int _tmain(int argc, TCHAR* argv[]) {
else if (!_tcscmp(exe, _T("c11")))
exec_argv[arg++] = _T("-std=c11");

if (!_tcscmp(arch, _T("i686"))) {
// Dwarf is the default for i686.
} else if (!_tcscmp(arch, _T("x86_64"))) {
// SEH is the default for x86_64.
} else if (!_tcscmp(arch, _T("armv7"))) {
// SEH is the default for armv7.
} else if (!_tcscmp(arch, _T("aarch64"))) {
// SEH is the default for aarch64.
}

if (target_os && !_tcscmp(target_os, _T("mingw32uwp"))) {
// the UWP target is for Windows 10
exec_argv[arg++] = _T("-D_WIN32_WINNT=0x0A00");
Expand All @@ -88,12 +78,8 @@ int _tmain(int argc, TCHAR* argv[]) {
exec_argv[arg++] = _T("-D_UCRT");
}

exec_argv[arg++] = _T("-target");
exec_argv[arg++] = target;
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("--config");
exec_argv[arg++] = concat(arch, _T("-w64-mingw32.cfg"));
exec_argv[arg++] = _T("--end-no-unused-arguments");

for (int i = 1; i < argc; i++)
Expand Down
20 changes: 1 addition & 19 deletions wrappers/clang-target-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,6 @@ c11)
FLAGS="$FLAGS -std=c11"
;;
esac
case $ARCH in
i686)
# Dwarf is the default for i686.
;;
x86_64)
# SEH is the default for x86_64.
;;
armv7)
# SEH is the default for armv7.
;;
aarch64)
# SEH is the default for aarch64.
;;
esac
LINKER_FLAGS=""
case $TARGET_OS in
mingw32uwp)
Expand All @@ -106,11 +92,7 @@ mingw32uwp)
;;
esac

FLAGS="$FLAGS -target $TARGET"
FLAGS="$FLAGS -rtlib=compiler-rt"
FLAGS="$FLAGS -unwindlib=libunwind"
FLAGS="$FLAGS -stdlib=libc++"
FLAGS="$FLAGS -fuse-ld=lld"
FLAGS="$FLAGS --config $ARCH-w64-mingw32.cfg"
FLAGS="$FLAGS --end-no-unused-arguments"

$CCACHE "$CLANG" $FLAGS "$@" $LINKER_FLAGS
6 changes: 6 additions & 0 deletions wrappers/i686-w64-mingw32.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-target i686-w64-mingw32
-rtlib=compiler-rt
-unwindlib=libunwind
-stdlib=libc++
-fuse-ld=lld
# Dwarf is the default for i686.
6 changes: 6 additions & 0 deletions wrappers/x86_64-w64-mingw32.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-target x86_64-w64-mingw32
-rtlib=compiler-rt
-unwindlib=libunwind
-stdlib=libc++
-fuse-ld=lld
# SEH is the default for x86_64.

0 comments on commit e2e9216

Please sign in to comment.