aboutsummaryrefslogtreecommitdiffstats
path: root/community/ldc/APKBUILD
blob: 3b65f91d3f27b107a08acb3bcd3e9180f1782ceb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Contributor: Mathias LANG <pro.mathias.lang@gmail.com>
# Maintainer: Mathias LANG <pro.mathias.lang@gmail.com>
pkgname=ldc
pkgver=1.26.0
pkgrel=0
pkgdesc="The LLVM-based D Compiler"
url="https://github.com/ldc-developers/ldc"
# LDC does not support host compiling on most of the architecture Alpine supports
arch="x86_64 aarch64"
license="BSD-3-Clause AND BSL-1.0 AND ( Artistic-1.0 OR GPL-2.0-or-later ) AND NCSA AND MIT"
depends="llvm-libunwind-dev tzdata $pkgname-static=$pkgver-r$pkgrel"
makedepends="chrpath cmake curl-dev diffutils gdmd llvm11-dev llvm11-static
	libedit-dev zlib-dev"
checkdepends="bash gdb grep llvm11-test-utils"
# A user might want to install the '-runtime' subpackage when they have
# a dynamically-linked D program.
subpackages="
	$pkgname-runtime
	$pkgname-static
	$pkgname-dbg
	$pkgname-bash-completion:bashcomp:noarch"
source="https://github.com/ldc-developers/ldc/releases/download/v$pkgver/ldc-$pkgver-src.tar.gz"
builddir="$srcdir/ldc-$pkgver-src/"

build() {
	# Note: The CI was running into OOM while building this package
	# See https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/14364#note_122336
	case "$CARCH" in x86*)
		export MAKEFLAGS="$MAKEFLAGS -j$((JOBS<4 ? JOBS : 4))"
		export DFLAGS="$DFLAGS -lowmem"
		;;
	esac
	# First, build LDC using GDC
	mkdir -p "$builddir/stage1"
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	unset DFLAGS
	cmake \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DD_COMPILER='gdmd' \
		-DLLVM_ROOT_DIR="/usr/lib/llvm11" \
		-DADDITIONAL_DEFAULT_LDC_SWITCHES=' "-linker=bfd", "-link-defaultlib-shared"' \
		$CMAKE_CROSSOPTS -S "$builddir" -B "$builddir/stage1"
	make -C "$builddir/stage1"

	# Then, self-build
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	# Don't use None buildtype for now, see
	# https://github.com/ldc-developers/ldc/issues/3386#issuecomment-603370855
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DD_COMPILER="$builddir/stage1/bin/ldmd2" \
		-DC_SYSTEM_LIBS="unwind;m;pthread;rt;dl" \
		-DADDITIONAL_DEFAULT_LDC_SWITCHES=' "-linker=bfd", "-link-defaultlib-shared"' \
		-DLLVM_ROOT_DIR="/usr/lib/llvm11" \
		$CMAKE_CROSSOPTS "$builddir"
	make

	# Build the test runners
	make all-test-runners

	# CMake added the rpaths to the shared libs (of stage1!) - strip them
	chrpath -d "$builddir"/lib/*.so*
	chrpath -d \
		"$builddir"/bin/ldc2 \
		"$builddir"/bin/ldmd2 \
		"$builddir"/bin/ldc-build-runtime \
		"$builddir"/bin/ldc-prune-cache
}

check() {
	# Find the libraries we just built as final (not stage1!)
	export LD_LIBRARY_PATH="$builddir"/lib

	case "$CARCH" in
		# Math & numeric related tests fail due to https://github.com/ldc-developers/ldc/issues/3270#issuecomment-613132406
		# druntime-test-thread fails due to https://github.com/ldc-developers/ldc/issues/3403
		aarch64)
			_tests_ignore="|core\.thread\.fiber|std.*math.*|std\.numeric.*|std\.format|std\.algorithm\.sorting.*|druntime-test-thread|std\.complex.*"
			;;
		# https://github.com/ldc-developers/ldc/issues/3404
		x86)
			_tests_ignore="|druntime-test-thread"
			;;
	esac


	# Note: The testsuite does not parallelize well, as the 'clean' target get run in parallel.
	# Hence '-j${JOBS}' was left out on purpose
	#
	# - dmd-testsuite takes too long to run and has more to do with language checks
	#	which are less relevant to us than platform integration tests
	# - lit-test disabled because 'TEST 'LDC :: debuginfo/print_gdb.d' FAILED'
	#	Something to do with TLS variables not being printable in GDB
	# - 'druntime-test-shared' fails, probably because it is using 'Object.factory'
	# - 'druntime-test-stdcpp' fails for an unknown reason and is temporarily disabled
	# - 'druntime-test-exceptions' fails for an unknown reason and is temporarily disabled
	ctest --output-on-failure -E "dmd-testsuite|lit-tests|druntime-test-exceptions|druntime-test-shared|druntime-test-stdcpp$_tests_ignore"
}

package() {
	# Use -j1, the install is flaky with too many build jobs
	make -j1 DESTDIR="$pkgdir" install

	mkdir -p "$pkgdir"/usr/share/bash-completion
	mv "$pkgdir"/etc/bash_completion.d "$pkgdir"/usr/share/bash-completion/completions
}

runtime() {
	depends="libexecinfo-dev"
	pkgdesc="Dynamic runtime library for D code compiled with $pkgname-$pkgver"

	mkdir -p "$subpkgdir/usr/lib/"
	for libn in "libdruntime" "libphobos2";
	do
		mv "$pkgdir"/usr/lib/$libn-ldc-shared.so* "$subpkgdir/usr/lib/"
	done
	mv "$pkgdir"/usr/lib/libldc-jit.so* "$subpkgdir/usr/lib"

	mv "$pkgdir"/usr/lib/*.so* "$subpkgdir/usr/lib/"
}

static() {
	depends="libexecinfo-static"
	pkgdesc="$pkgdesc (static library)"

	mkdir -p "$subpkgdir/usr/lib/"
	mv "$pkgdir"/usr/lib/*.a "$subpkgdir/usr/lib/"
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	amove usr/share/bash-completion/completions
}

sha512sums="7bb2aa464f5ba834c07f67743f4af01db6588d56611d6c9e250a6908ebe93a0dcd9d3a79f8f252fc92eeb4826bfa62de6c51c4db03ff80e60a8d993e4451f573  ldc-1.26.0-src.tar.gz"