aboutsummaryrefslogtreecommitdiffstats
path: root/community/crystal/APKBUILD
blob: 8aadf1a06ffbb9c2e3b7a05ad8a9f41a24d05287 (plain)
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
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: Milan P. Stanić <mps@arvanta.net>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=crystal
pkgver=1.10.1
pkgrel=0
_bootver=1.9.2
_llvmver=16
pkgdesc="The Crystal Programming Language"
url="https://crystal-lang.org/"
arch="x86_64 aarch64"
license="Apache-2.0"
depends="
	gc-dev
	gcc
	gmp-dev
	libatomic_ops
	libevent-dev
	libevent-static
	musl-dev
	pcre2-dev
	"
checkdepends="
	openssl-dev
	tzdata
	yaml-dev
	zlib-dev
	"
makedepends="
	libxml2-dev
	llvm$_llvmver-dev
	"
[ "${BUILD_STATIC:-0}" -eq 1 ] && makedepends="$makedepends
	libxml2-static
	llvm$_llvmver-static
	zlib-static
	zstd-static
	"
subpackages="$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/crystal-lang/$pkgname/archive/$pkgver.tar.gz
	https://dev.alpinelinux.org/archive/crystal/crystal-$_bootver-x86_64-alpine-linux-musl.tar.gz
	https://dev.alpinelinux.org/archive/crystal/crystal-$_bootver-aarch64-alpine-linux-musl.tar.gz
	"

_coredir="/usr/lib/$pkgname/core"
_shardsdir="/usr/lib/$pkgname/shards"

export CRYSTAL_CONFIG_VERSION="$pkgver"
export CRYSTAL_CACHE_DIR="$srcdir/.cache"
export LLVM_CONFIG="/usr/lib/llvm$_llvmver/bin/llvm-config"

# Build static crystal binary and upload it to dev.a.o, so it can be used
# for building crystal next time (needed for bootstrapping).
# NOTE: After https://github.com/crystal-lang/crystal/issues/5689 is fixed,
# we can also use prebuilt binary from upstream if needed.
snapshot() {
	local binary="$builddir/.build/crystal"
	local tarname="$pkgname-$pkgver-$CTARGET"

	if [ ! -f "$binary" ] || ! file "$binary" | grep -qw 'statically linked'; then
		msg "Building statically linked crystal..."
		BUILD_STATIC=1 \
			abuild deps clean unpack prepare build
	fi

	cd "$srcdir"

	strip "$builddir"/.build/crystal
	install -D -m 755 "$builddir"/.build/crystal "$tarname"/bin/crystal
	tar -czf "$tarname.tar.gz" "$tarname"

	msg "Uploading $tarname.tar.gz to dev.alpinelinux.org"
	scp "$tarname.tar.gz" dev.alpinelinux.org:/archive/$pkgname/

	APKBUILD="../APKBUILD" abuild undeps
}

prepare() {
	default_prepare

	# FIXME: These specs fail with invalid memory access.
	rm spec/compiler/compiler_spec.cr

	cat > Makefile.local <<-EOF
		progress = 1
		threads = ${JOBS:-2}
		verbose = 1
		FLAGS = --verbose --target $CTARGET ${BUILD_STATIC:+"--link-flags=-no-pie"}
		LLVM_CONFIG = $LLVM_CONFIG
	EOF
}

build() {
	make crystal \
		CRYSTAL_CONFIG_BUILD_COMMIT= \
		CRYSTAL_CONFIG_PATH="lib:$_shardsdir:$_coredir" \
		PATH="$srcdir/$pkgname-$_bootver-$CBUILD/bin:$PATH" \
		release=1 \
		static=${BUILD_STATIC:-}
}

check() {
	make std_spec threads=1 SPEC_FLAGS='--no-color --verbose'

	find samples -name '*.cr' -print0 | xargs -0 -tn 1 ./bin/crystal build --no-codegen

	# Takes ~1 hour on x86_64, ~1.5 hour on aarch64.
	#make compiler_spec threads=1 SPEC_FLAGS='--no-color --verbose'
}

package() {
	install -D -m 755 .build/crystal "$pkgdir"/usr/bin/crystal
	install -D -m 644 man/crystal.1 "$pkgdir"/usr/share/man/man1/crystal.1

	mkdir -p "$pkgdir$_coredir" "$pkgdir$_shardsdir"
	cp -r src/* "$pkgdir$_coredir"/

	install -D -m 644 etc/completion.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -D -m 644 etc/completion.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname

	rm "$pkgdir$_coredir"/llvm/ext/llvm_ext.o
}

sha512sums="
2e26d6e366ea5c8b7abe3457608a0a0eca60b5d15f3c9079a58c3855302c7c07cd705d04fb6aa1bec2681fe40799609cab77a8b8e6fc10be7a8e545c5b0ecfc1  crystal-1.10.1.tar.gz
6a2a25e3206cc21fab93f3bd451e92d42b3676791089ac3ab7a816e1a2b1592cf7ea999b6b2ea36c31f9f9ae2c961de44d39d4baf202304ea1b324d7b0ba41b2  crystal-1.9.2-x86_64-alpine-linux-musl.tar.gz
2dbce0137d657ad8982e44ae121633ea9406d845348b9eb7e887c1d4761fab08fe6c807c0c38def6e4144516f1c35a809a4bcea9496af53ad26cccafa80d981b  crystal-1.9.2-aarch64-alpine-linux-musl.tar.gz
"