So, this went rather smooth. just had to copy over stuff from wasm.
The patch builds the compiler-rt libraries for windows. in short,
there will be 2 new files in libclang-rt-18-dev:
/usr/lib/llvm-18/lib/clang/18/lib/windows/libclang_rt.builtins-i386.a
/usr/lib/llvm-18/lib/clang/18/lib/windows/libclang_rt.builtins-x86_64.a
The result is that, aslong as mingw-w64-x86-64-dev is installed, this will work:
clang -rtlib=compiler-rt -target x86_64-w64-mingw test.cpp
Notably, I hard-coded those archs, windows support would make sense
for aarch64 and armv7 aswell.
I am unsure how the policy is, when to build which target
architecture, clang/llvm wont care.
maybe place all windows builtins into an libclang-rt-18-dev-w64
package for all architectures?
regards, Norbert
Am Di., 30. Apr. 2024 um 22:14 Uhr schrieb Norbert Lange :
>
> Am So., 28. Apr. 2024 um 18:17 Uhr schrieb Sylvestre Ledru
> :
> >
> > Hello
> >
> >
> > Le 16/09/2023 à 00:29, Norbert Lange a écrit :
> > > Package: libclang-rt-16-dev
> > > Version: 1:16.0.6-3
> > > Severity: wishlist
> > > X-Debbugs-Cc: nolang...@gmail.com
> > >
> > > Adding the compiler-rt library for windows / mingw-64 would allow ease
> > > building
> > > mingw-64 tools,
> > > the builtins seem to be pretty universal for any windows target.
> > >
> > > There is a project providing a full mingw toolchain for reference:
> > > https://github.com/mstorsjo/llvm-mingw
> > >
> > > I am able to create the builtins just with the mingw-w64-common package
> > > and
> > > debians llvm/clang like this:
> >
> > Sorry but I am not a windows user (or interested by this space), could
> > you please provide a MR to implement this?
>
> I am not windows user (or interested by this space) but I am forced to build
> for it and I prefer still staying away from that OS as much as possible.
>
> The package is a a bit of a monster though, both in complexity as well
> as build-time.
> Any tips for hacking around?
>
> Ill try to look at 'build-wasm/compiler-rt-%'.
>
> I am meant to use STAGE2 binaries? Are those the final ones?
>
> Given that clang is a native crosscompiler, I guess it makes sense providing
> the mingw builtins as "all" package like libclang-rt-18-dev-wasm32?
>
> Ill see if I find time for that next week.
>
> Regards, Norbert
diff -burN debian.orig/control debian/control
--- debian.orig/control 2024-04-04 07:52:43.0 +0200
+++ debian/control 2024-06-17 14:40:56.331727789 +0200
@@ -29,6 +29,7 @@
llvm-spirv-18 [amd64 arm64 armhf i386 ppc64 ppc64el riscv64 s390x] | hello [amd64 arm64 armhf i386 ppc64 ppc64el riscv64 s390x] ,
spirv-tools [linux-any] | hello [linux-any],
wasi-libc | hello,
+mingw-w64-common [amd64 arm64 armhf i386],
libcurl4-openssl-dev | libcurl-dev ,
libgrpc++-dev [amd64 arm64 armel armhf mips64el mipsel ppc64 ppc64el powerpc riscv64 s390x] ,
protobuf-compiler-grpc [amd64 arm64 armel armhf mips64el mipsel ppc64 ppc64el powerpc riscv64 s390x] ,
diff -burN debian.orig/rules debian/rules
--- debian.orig/rules 2024-05-19 09:27:15.0 +0200
+++ debian/rules 2024-06-17 14:45:48.531063108 +0200
@@ -938,6 +938,38 @@
STAGE_2_WASM_CFLAGS := $(filter-out -march=% -mfpu=% -fcf-protection% -mbranch-protection%, $(STAGE_2_CFLAGS))
STAGE_2_WASM_CXXFLAGS := $(filter-out -march=% -mfpu=% -fcf-protection% -mbranch-protection%, $(STAGE_2_CXXFLAGS))
+build-mingw/compiler-rt-%: cpu = $(@:build-mingw/compiler-rt-%=%)
+build-mingw/compiler-rt-%:
+ @echo "Building compiler-rt for $(cpu)-w64-windows-gnu"
+ @echo "Using cmake: $(CMAKE_BIN)"
+ mkdir -p "$@"
+ $(CMAKE_BIN) -B "$@" -S compiler-rt/lib/builtins/ \
+ -G Ninja \
+ $(SCCACHE_CMAKE) \
+ -DCMAKE_SYSTEM_NAME=Windows \
+ -DCMAKE_SYSROOT=/usr/share/mingw-w64 \
+ -DCMAKE_C_COMPILER_TARGET=$(cpu)-w64-windows-gnu \
+ -DCMAKE_CXX_COMPILER_TARGET=$(cpu)-w64-windows-gnu \
+ -DCMAKE_ASM_COMPILER_TARGET=$(cpu)-w64-windows-gnu \
+ -DCMAKE_C_COMPILER=$(STAGE_2_BIN_DIR)/clang \
+ -DCMAKE_CXX_COMPILER=$(STAGE_2_BIN_DIR)/clang++ \
+ -DCMAKE_C_FLAGS="$(opt_flags)" \
+ -DCMAKE_CXX_FLAGS="$(opt_flags)" \
+ -DCMAKE_SHARED_LINKER_FLAGS="$(STAGE_2_LDFLAGS) -L$(STAGE_2_LIB_DIR)" \
+ -DCMAKE_MODULE_LINKER_FLAGS="$(STAGE_2_LDFLAGS) -L$(STAGE_2_LIB_DIR)" \
+ -DCMAKE_EXE_LINKER_FLAGS="$(STAGE_2_LDFLAGS) -L$(STAGE_2_LIB_DIR)" \
+ -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm-$(LLVM_VERSION)/lib/clang/$(LLVM_VERSION) \
+ -DCMAKE_INSTALL_DATADIR=lib \
+ -DCMAKE_INSTALL_INCLUDEDIR=include \
+ -DLLVM_CMAKE_DIR=$(STAGE_2_BIN_DIR)/../ \
+ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
+ -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON \
+ -DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
+ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
+ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
+ -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
+ ninja -C "$@" -j $(NJOBS) $(VERBOSE)
+
build-wasm/compiler-rt-%: cpu = $(@:build-wasm/compiler-rt-%=%)
build-wasm/compiler-rt-%:
@echo "Building compiler-rt for $(cpu)"
@@ -1062,6 +1094,13 @@