Skip to content

Commit 5907bb6

Browse files
authored
Merge pull request #29 from emerge-lang/llvm-build-linux-x64
Also build LLVM for Linux x64
2 parents e33d219 + 94529c3 commit 5907bb6

6 files changed

Lines changed: 109 additions & 18 deletions

File tree

.github/workflows/build-emerge.yaml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ env:
2828
GCC_GIT_REF: "releases/gcc-14.1.0"
2929
LIBUNWIND_GIT_REF: "v1.8.1"
3030
LLVM_MAJOR_VERSION: "20"
31+
LLVM_MINOR_VERSION: "1"
3132
ZULU_JRE_URL: https://cdn.azul.com/zulu/bin/zulu21.36.17-ca-jre21.0.4-win_x64.zip
3233

3334
jobs:
@@ -138,6 +139,8 @@ jobs:
138139
- name: mvn clean verify
139140
if: steps.cache-emerge-toolchain-maven.outputs.cache-hit != 'true'
140141
run: mvn "-Demerge.llvm-tests.llvm-install-dir=/usr/lib/llvm-20" -B clean verify
142+
llvm-build-for-linux:
143+
uses: ./.github/workflows/build-llvm-linux.yaml
141144
linux-distributables:
142145
name: Linux distributable archives
143146
runs-on: ubuntu-22.04
@@ -148,11 +151,18 @@ jobs:
148151
- build-glibc-x86_64
149152
- build-libunwind-x86_64
150153
- emerge-toolchain-maven
154+
- llvm-build-for-linux
151155
steps:
152156
- name: checkout
153157
uses: actions/checkout@v4
154158
with:
155159
ref: "${{ inputs.ref || github.sha }}"
160+
- name: get LLVM binaries
161+
uses: actions/download-artifact@v4.1.8
162+
with:
163+
run-id: "${{ needs.llvm-build-for-linux.run-id }}"
164+
name: llvm-linux-gnu-x86_64
165+
path: ${{ github.workspace }}/llvm-install
156166
- name: get C-runtime binaries from glibc
157167
uses: actions/cache/restore@v4.2.2
158168
with:
@@ -193,6 +203,7 @@ jobs:
193203
mkdir bin && pushd $_
194204
cp "${{ github.workspace }}/toolchain/target/toolchain.jar" .
195205
popd
206+
196207
cp -r "${{ github.workspace }}/stdlib" .
197208
cp -ar "${{ github.workspace }}/dist/linux/all/." .
198209
@@ -217,7 +228,22 @@ jobs:
217228
cp "${{ github.workspace }}/glibc-build/csu/Scrt1.o" .
218229
cp "${{ github.workspace }}/glibc-build/libc.so" .
219230
popd
231+
popd
232+
233+
mkdir -p llvm/bin && pushd $_
234+
cp "${{ github.workspace }}/llvm-install/bin/lld" .
220235
popd
236+
mkdir llvm/lib && pushd $_
237+
cp "${{ github.workspace }}/llvm-install/lib/libLLVM.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" .
238+
ln -s "libLLVM.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" "libLLVM-$LLVM_MAJOR_VERSION.so"
239+
ln -s "libLLVM.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" "libLLVM.so"
240+
cp "${{ github.workspace }}/llvm-install/lib/libLTO.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" .
241+
ln -s "libLTO.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" "libLTO-$LLVM_MAJOR_VERSION.so"
242+
ln -s "libLTO.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" "libLTO.so"
243+
cp "${{ github.workspace }}/llvm-install/lib/libRemarks.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" .
244+
ln -s "libRemarks.so.$LLVM_MAJOR_VERSION.$LLVM_MINOR_VERSION" "libRemarks.so"
245+
popd
246+
cp -r "${{ github.workspace }}/llvm-install/share" llvm/share
221247
popd
222248
tar --create \
223249
--directory=tarball-root \
@@ -269,15 +295,19 @@ jobs:
269295
run-id: "${{ needs.llvm-build-for-windows.run-id }}"
270296
name: llvm-windows-x86_64
271297
path: ${{ github.workspace }}/llvm-install
272-
- name: prepare zip
298+
- name: build distributable archive
299+
id: pack-zip
273300
shell: pwsh
274301
run: |
275302
New-Item -Type Directory -Name "archive-root"
276303
277304
# first extract the linux tarball. It doesn't come with much linux-specific stuff, so we can reuse all the
278305
# code for building it
279-
tar --directory archive-root -xf "${{ needs.linux-distributables.outputs.tarball-filename }}"
306+
tar --no-same-owner --no-same-permissions --directory archive-root -xf "${{ needs.linux-distributables.outputs.tarball-filename }}"
307+
chown -R archive-root
308+
chmod -R u+w archive-root
280309
Remove-Item "archive-root/configure.sh" # this one is linux specific
310+
Remove-Item "archive-root/llvm" -Recurse # this one is linux specific
281311
282312
New-Item -Type Directory -Path "archive-root/llvm" -Name "bin"
283313
# the LLVM distribution for windows builds THE WHOLE thing. This is needed for development.
@@ -286,15 +316,10 @@ jobs:
286316
Move-Item -Path "llvm-install/bin/ld.lld.exe" "archive-root/llvm/bin/ld.lld.exe"
287317
Move-Item -Path "llvm-install/bin/llc.exe" "archive-root/llvm/bin/llc.exe"
288318
Move-Item -Path "llvm-install/bin/LLVM-C.dll" "archive-root/llvm/bin/LLVM-C.dll"
289-
# fix the reference to the LLVM installation directiory
290-
(Get-Content archive-root/toolchain-config.yml) -replace '(?<=\s*llvm-installation-directory: ).+','llvm' | Set-Content archive-root/toolchain-config.yml
291319
292320
# redistribute JRE
293321
Move-Item -Path "zulu-jre/jre" "archive-root/jre"
294-
- name: pack zip
295-
id: pack-zip
296-
shell: pwsh
297-
run: |
322+
298323
Get-ChildItem -Path "archive-root" | Compress-Archive -DestinationPath "emerge-toolchain.zip"
299324
$hash = (Get-FileHash -Algorithm SHA256 "emerge-toolchain.zip").Hash
300325
Add-Content -Path "$Env:GITHUB_OUTPUT" -Value "sha256=$hash"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copied from github.com/llvm/llvm-project Actions
2+
3+
env:
4+
LLVM_REF: llvmorg-20.1.8
5+
6+
name: "Build LLVM for Linux"
7+
on:
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
jobs:
12+
build-llvm-windows:
13+
name: "Build LLVM x86_64-unknown-linux-gnu"
14+
runs-on: ubuntu-24.04
15+
env:
16+
LLVM_INSTALL_PATH: ${{ github.workspace }}/llvm-install
17+
LLVM_BUILD_PATH: ${{ github.workspace }}/llvm-build
18+
steps:
19+
- name: cache
20+
id: cache
21+
uses: actions/cache@v4.2.2
22+
with:
23+
path: |
24+
${{ env.LLVM_INSTALL_PATH }}
25+
key: llvm-built-${{ env.LLVM_REF }}
26+
- name: Fetch LLVM sources
27+
if: steps.cache.outputs.cache-hit != 'true'
28+
uses: actions/checkout@v4
29+
with:
30+
repository: llvm/llvm-project
31+
ref: ${{ env.LLVM_REF }}
32+
fetch-depth: 2
33+
- name: install build tools
34+
id: setup
35+
if: steps.cache.outputs.cache-hit != 'true'
36+
run: |
37+
sudo apt-get update
38+
sudo apt-get install clang-19
39+
- name: Configure LLVM
40+
if: steps.cache.outputs.cache-hit != 'true'
41+
shell: bash
42+
run: |
43+
cmake \
44+
-G "Ninja" \
45+
-S llvm \
46+
-B $LLVM_BUILD_PATH \
47+
-DLLVM_USE_LINKER=gold \
48+
-DLLVM_BUILD_LLVM_C_DYLIB=Off \
49+
-DLLVM_BUILD_LLVM_DYLIB=On \
50+
-DLLVM_LINK_LLVM_DYLIB=On \
51+
-DCMAKE_INSTALL_PREFIX=$LLVM_INSTALL_PATH \
52+
-DCMAKE_BUILD_TYPE=Release \
53+
-DLLVM_ENABLE_ASSERTIONS=On \
54+
-DCMAKE_C_COMPILER="/usr/lib/llvm-19/bin/clang" \
55+
-DCMAKE_CXX_COMPILER="/usr/lib/llvm-19/bin/clang++" \
56+
-DLLVM_TARGETS_TO_BUILD=X86 \
57+
-DLLVM_ENABLE_DIA_SDK=OFF \
58+
-DLLVM_ENABLE_LIBXML2=OFF \
59+
-DLLVM_INCLUDE_TESTS=OFF \
60+
-DPYTHON_EXECUTABLE="$(where python.exe | head -1)" \
61+
-DLLVM_ENABLE_ZSTD=OFF \
62+
-DLLVM_ENABLE_PROJECTS="llvm;lld"
63+
- name: Build LLVM
64+
if: steps.cache.outputs.cache-hit != 'true'
65+
run: |
66+
cd "${{ env.LLVM_BUILD_PATH }}"
67+
ninja
68+
ninja install
69+
- name: Collect artifacts
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: llvm-linux-gnu-x86_64
73+
path: |
74+
${{ env.LLVM_INSTALL_PATH }}

dist/linux/all/configure.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#!/bin/bash
22
set -e
33
SELFDIR="$( realpath "$( dirname "${BASH_SOURCE[0]}" )" )"
4-
LLC="$(realpath "$(which llc-20)")"
5-
LLVM_DIR="${LLC%/bin/llc}"
6-
echo "Using LLVM installation in $LLVM_DIR"
7-
LLVM_DIR_FOR_SED=$(echo "$LLVM_DIR" | sed 's/\//\\\//g')
8-
9-
sed --regexp-extended --in-place 's/llvm-installation-directory: \~/llvm-installation-directory: "'$LLVM_DIR_FOR_SED'"/' "$SELFDIR/toolchain-config.yml"
104

115
jre_link="$SELFDIR/jre"
126
if [[ ! -e "$jre_link" ]]

dist/linux/all/toolchain-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ backends:
88
ffi-c-sources: backends/native/emerge-ffi-c
99
libc-sources: backends/linux-gnu/emerge-linux-libc
1010
platform-sources: backends/linux-gnu/emerge-platform-linux
11-
llvm-installation-directory: ~
11+
llvm-installation-directory: llvm
1212
static-libs:
1313
crtbeginS: backends/x86_64-pc-linux-gnu/lib/crtbeginS.o
1414
crtendS: backends/x86_64-pc-linux-gnu/lib/crtendS.o

dist/linux/deb/DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: ${DEB_NAME}
22
Version: ${DEB_VERSION}
33
Maintainer: Tobias Marstaller
4-
Depends: llvm-20, lld-20, java-runtime-headless (>= 21)
4+
Depends: java-runtime-headless (>= 21)
55
Section: devel
66
Priority: optional
77
Homepage: https://github.com/emerge-lang/compiler

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ sudo apt install -f ~/Downloads/emerge-toolchain-{INSERT VERSION}.deb
4242

4343
Install the dependencies manually:
4444

45-
* `llvm-20`
46-
* `lld-20`
4745
* a Java runtime >= 21
4846

4947
Download the latest `.tar.gz` package from the [releases page][1]. Then run **after filling in**:

0 commit comments

Comments
 (0)