Skip to content

Commit 308b0d4

Browse files
committed
Cirrus: add targets for creating FreeBSD/powerpc64* bootstraps
Since Cirrus offers only FreeBSD/amd64 VMs, crosscompilation is necessary.
1 parent 9c3a028 commit 308b0d4

1 file changed

Lines changed: 193 additions & 0 deletions

File tree

.cirrus.yml

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,196 @@ task:
270270
bin/ldc2 -version
271271
<< : *COMMON_STEPS_TEMPLATE
272272
<< : *PACKAGING_STEPS_TEMPLATE
273+
274+
# ============================================================================
275+
# Addition to .cirrus.yml: cross-build FreeBSD/powerpc64 and powerpc64le
276+
# prebuilt bootstrap packages on the x86_64 FreeBSD runner.
277+
#
278+
# Rationale: Cirrus only offers x86_64 FreeBSD VMs, and there are no native
279+
# ppc64 FreeBSD CI runners. A single LDC can cross-emit any target via
280+
# -mtriple, so we build the runtime + compiler objects for the target on the
281+
# x64 host and do the final link against a target sysroot. The result is a
282+
# relocatable ldc2-<id>-freebsd-{ppc64,ppc64le}.tar.xz, produced exactly like
283+
# the x86_64 package and uploaded to the same GitHub release.
284+
#
285+
# Requires the ELFv2-on-FreeBSD/powerpc64 fix (see companion patch) to be in
286+
# the tree, otherwise the cross-built ppc64 (big-endian) compiler is miscompiled.
287+
# ============================================================================
288+
289+
# Cross-builds the target runtime + compiler objects on the x64 host, links
290+
# against a target sysroot, and packs a portable artifact.
291+
# Requires env: CI_ARCH (ppc64|ppc64le), TARGET_TRIPLE, PKG_ABI, BASE_ARCH_PATH.
292+
freebsd_cross_bootstrap_template: &FREEBSD_CROSS_BOOTSTRAP_TEMPLATE
293+
# Build a target sysroot: FreeBSD base + the llvm19/libconfig build deps.
294+
build_sysroot_script: |
295+
cd $CIRRUS_WORKING_DIR/..
296+
SYSROOT=$PWD/sysroot-$CI_ARCH
297+
REL=14.3-RELEASE
298+
mkdir -p $SYSROOT
299+
fetch -o base.txz \
300+
https://download.freebsd.org/releases/${BASE_ARCH_PATH}/${REL}/base.txz
301+
tar -xf base.txz -C $SYSROOT
302+
# Install the target build-deps (llvm19, libconfig) into the sysroot.
303+
mkdir -p $SYSROOT/usr/local/etc/pkg/repos
304+
ABI=$PKG_ABI IGNORE_OSVERSION=yes \
305+
pkg -r $SYSROOT -o ASSUME_ALWAYS_YES=yes -o ABI=$PKG_ABI \
306+
install -y llvm19 libconfig zstd
307+
echo "SYSROOT=$SYSROOT" >> $CIRRUS_ENV
308+
# Cross-build druntime + phobos for the target.
309+
build_runtime_script: |
310+
cd $CIRRUS_WORKING_DIR/..
311+
cat > tc-$CI_ARCH.cmake <<EOF
312+
set(CMAKE_SYSTEM_NAME FreeBSD)
313+
set(CMAKE_SYSTEM_PROCESSOR ${CI_ARCH})
314+
set(CMAKE_SYSROOT $SYSROOT)
315+
set(CMAKE_C_COMPILER cc)
316+
set(CMAKE_C_COMPILER_TARGET $TARGET_TRIPLE)
317+
set(CMAKE_CXX_COMPILER c++)
318+
set(CMAKE_CXX_COMPILER_TARGET $TARGET_TRIPLE)
319+
set(CMAKE_ASM_COMPILER cc)
320+
set(CMAKE_ASM_COMPILER_TARGET $TARGET_TRIPLE)
321+
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld")
322+
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld")
323+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
324+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
325+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
326+
EOF
327+
./host-ldc/bin/ldc-build-runtime --ninja \
328+
--ldc=$PWD/host-ldc/bin/ldc2 \
329+
--ldcSrcDir=$CIRRUS_WORKING_DIR \
330+
--buildDir=$PWD/rt-$CI_ARCH \
331+
--dFlags="-mtriple=$TARGET_TRIPLE" \
332+
CMAKE_TOOLCHAIN_FILE=$PWD/tc-$CI_ARCH.cmake \
333+
BUILD_SHARED_LIBS=BOTH BUILD_LTO_LIBS=ON
334+
# Cross-build the compiler objects (host LLVM headers are arch-independent;
335+
# only the final link needs the target's LLVM/LLD libs).
336+
build_compiler_objects_script: |
337+
cd $CIRRUS_WORKING_DIR/..
338+
RT=$PWD/rt-$CI_ARCH/lib
339+
mkdir build-$CI_ARCH && cd build-$CI_ARCH
340+
# Bypass the configure-time D-linker probe (it cannot link a target exe on
341+
# the host); the final exe link is done manually below.
342+
LA="$RT/ldc_rt.dso.o;-L$RT;-target;$TARGET_TRIPLE;--sysroot=$SYSROOT;-fuse-ld=lld;-lphobos2-ldc-shared;-ldruntime-ldc-shared;-Wl,--gc-sections;-lexecinfo;-lpthread;-lm"
343+
DFLAGS="-mtriple=$TARGET_TRIPLE" cmake -G Ninja $CIRRUS_WORKING_DIR \
344+
-DCMAKE_BUILD_TYPE=Release \
345+
-DCMAKE_TOOLCHAIN_FILE=$PWD/../tc-$CI_ARCH.cmake \
346+
-DD_COMPILER=$PWD/../host-ldc/bin/ldmd2 \
347+
-DLLVM_CONFIG=/usr/local/bin/llvm-config \
348+
-DBUILD_SHARED_LIBS=BOTH -DBUILD_LTO_LIBS=ON \
349+
-DLDC_LINK_MANUALLY=ON -DD_LINKER_COMMAND=/usr/bin/cc "-DD_LINKER_ARGS=$LA"
350+
# Compile all objects + archive libldc.a/libldmd.a (the exe link fails on
351+
# the host for lack of target LLVM libs; that is expected).
352+
DFLAGS="-mtriple=$TARGET_TRIPLE" ninja lib/libldc.a lib/libldmd.a obj/ldc2.o obj/ldmd2.o
353+
# Final link of ldc2/ldmd2 against the target sysroot's LLVM/LLD, with a
354+
# relocatable $ORIGIN runpath so the package works after extraction.
355+
link_compiler_script: |
356+
cd $CIRRUS_WORKING_DIR/../build-$CI_ARCH
357+
L19=$SYSROOT/usr/local/llvm19/lib
358+
RT=$PWD/../rt-$CI_ARCH/lib
359+
for t in ldc2 ldmd2; do
360+
lib=libldc.a; [ $t = ldmd2 ] && lib=libldmd.a
361+
c++ --target=$TARGET_TRIPLE --sysroot=$SYSROOT -O3 -DNDEBUG -fuse-ld=lld \
362+
obj/$t.o $RT/ldc_rt.dso.o -o bin/$t lib/$lib \
363+
-llldMinGW -llldCOFF -llldELF -llldMachO -llldWasm -llldCommon \
364+
-lLLVMSymbolize -lLLVM-19 -L$L19 -lzstd -Wl,--export-dynamic \
365+
-L$RT -lphobos2-ldc-shared -ldruntime-ldc-shared \
366+
-Wl,-rpath,'$ORIGIN/../lib' -Wl,--gc-sections -lexecinfo -lpthread -lm
367+
done
368+
# Assemble the portable package (same layout as the x86_64 artifact).
369+
pack_artifact_script: |
370+
cd $CIRRUS_WORKING_DIR/..
371+
if [[ "${CIRRUS_TAG:-}" == v* ]]; then artifactID=${CIRRUS_TAG:1}; else artifactID=${CIRRUS_CHANGE_IN_REPO:0:8}; fi
372+
name=ldc2-$artifactID-freebsd-$CI_ARCH
373+
mkdir -p $name/bin $name/lib $name/import $name/etc/ldc2.conf
374+
cp build-$CI_ARCH/bin/ldc2 build-$CI_ARCH/bin/ldmd2 $name/bin/
375+
cp -a rt-$CI_ARCH/lib/. $name/lib/
376+
# Assemble the import tree (arch-independent D sources), same layout as
377+
# the official packages: druntime's modules + phobos's std and etc.
378+
D=$CIRRUS_WORKING_DIR/runtime/druntime/src
379+
cp -a $D/object.d $D/core $D/ldc $D/etc $D/importc.h $D/__importc_builtins.di $name/import/
380+
cp -a $CIRRUS_WORKING_DIR/runtime/phobos/std $name/import/
381+
cp -a $CIRRUS_WORKING_DIR/runtime/phobos/etc/. $name/import/etc/
382+
cat > $name/etc/ldc2.conf/50-target-default.conf <<EOF
383+
"default":
384+
{
385+
switches = [ "-defaultlib=phobos2-ldc,druntime-ldc" ];
386+
post-switches = [ "-I%%ldcbinarypath%%/../import" ];
387+
lib-dirs = [ "%%ldcbinarypath%%/../lib" ];
388+
rpath = "%%ldcbinarypath%%/../lib";
389+
};
390+
EOF
391+
cp $CIRRUS_WORKING_DIR/{LICENSE,packaging/README} $name/
392+
mkdir -p artifacts
393+
chmod -R go=rX $name
394+
gtar -cf - --owner=0 --group=0 $name | 7z a artifacts/$name.tar.xz -si -txz -mx9 -mmt$PARALLELISM
395+
ls -lh artifacts/ldc2-*.tar.xz
396+
upload_to_github_script: |
397+
cd $CIRRUS_WORKING_DIR
398+
if [[ "${CIRRUS_TAG:-}" == v* ]]; then
399+
tools/upload-to-github.sh $CIRRUS_TAG ../artifacts/ldc2-*.tar.xz
400+
elif [[ "${CIRRUS_TAG:-}" = "" && "$CIRRUS_PR" = "" && "$CIRRUS_BRANCH" = "master" ]]; then
401+
tools/upload-to-github.sh CI ../artifacts/ldc2-*.tar.xz
402+
fi
403+
404+
task:
405+
name: FreeBSD powerpc64le cross-bootstrap
406+
freebsd_instance:
407+
image_family: freebsd-13-5
408+
cpu: 4
409+
memory: 8G
410+
timeout_in: 60m
411+
environment:
412+
CI_ARCH: ppc64le
413+
TARGET_TRIPLE: powerpc64le-portbld-freebsd14.3
414+
PKG_ABI: "FreeBSD:14:powerpc64le"
415+
BASE_ARCH_PATH: powerpc/powerpc64le
416+
PARALLELISM: 4
417+
CC: clang19
418+
CXX: clang++19
419+
install_prerequisites_script: |
420+
pkg install -y git cmake ninja gmake llvm19 bash gtar 7-zip ldc
421+
ln -sf llvm-config19 /usr/local/bin/llvm-config
422+
<< : *CLONE_STEPS_TEMPLATE
423+
clone_submodules_early_script: |
424+
cd $CIRRUS_WORKING_DIR
425+
git submodule update --init --depth $CIRRUS_CLONE_DEPTH
426+
# Reuse the same host-LDC build used by the native FreeBSD task.
427+
build_bootstrap_ldc_script: |
428+
cd $CIRRUS_WORKING_DIR/..
429+
mkdir host-ldc && cd host-ldc
430+
cmake -G Ninja $CIRRUS_WORKING_DIR -DCMAKE_BUILD_TYPE=Release \
431+
-DD_COMPILER=ldmd2 -DBUILD_SHARED_LIBS=OFF -DLDC_DYNAMIC_COMPILE=OFF -DBUILD_LTO_LIBS=ON
432+
ninja -j$PARALLELISM
433+
bin/ldc2 -version
434+
<< : *FREEBSD_CROSS_BOOTSTRAP_TEMPLATE
435+
436+
task:
437+
name: FreeBSD powerpc64 cross-bootstrap
438+
freebsd_instance:
439+
image_family: freebsd-13-5
440+
cpu: 4
441+
memory: 8G
442+
timeout_in: 60m
443+
environment:
444+
CI_ARCH: ppc64
445+
TARGET_TRIPLE: powerpc64-portbld-freebsd14.3
446+
PKG_ABI: "FreeBSD:14:powerpc64"
447+
BASE_ARCH_PATH: powerpc/powerpc64
448+
PARALLELISM: 4
449+
CC: clang19
450+
CXX: clang++19
451+
install_prerequisites_script: |
452+
pkg install -y git cmake ninja gmake llvm19 bash gtar 7-zip ldc
453+
ln -sf llvm-config19 /usr/local/bin/llvm-config
454+
<< : *CLONE_STEPS_TEMPLATE
455+
clone_submodules_early_script: |
456+
cd $CIRRUS_WORKING_DIR
457+
git submodule update --init --depth $CIRRUS_CLONE_DEPTH
458+
build_bootstrap_ldc_script: |
459+
cd $CIRRUS_WORKING_DIR/..
460+
mkdir host-ldc && cd host-ldc
461+
cmake -G Ninja $CIRRUS_WORKING_DIR -DCMAKE_BUILD_TYPE=Release \
462+
-DD_COMPILER=ldmd2 -DBUILD_SHARED_LIBS=OFF -DLDC_DYNAMIC_COMPILE=OFF -DBUILD_LTO_LIBS=ON
463+
ninja -j$PARALLELISM
464+
bin/ldc2 -version
465+
<< : *FREEBSD_CROSS_BOOTSTRAP_TEMPLATE

0 commit comments

Comments
 (0)