Skip to content

Commit aa09d5d

Browse files
authored
Merge pull request #34 from powersync-ja/build-fixes
Build fixes and improvements
2 parents 276cc52 + 89693a7 commit aa09d5d

File tree

11 files changed

+108
-90
lines changed

11 files changed

+108
-90
lines changed

.cargo/config.toml

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1-
# On Linux, if we don't link to gcc_eh, we get can get this error when loading the loadable extension:
2-
# undefined symbol: _Unwind_Resume
3-
# This adds around 29KB to the loadable extension.
4-
# It may also be an option to just define _Unwind_Resume, but it causes crashes on errors on e.g. iOS, so rather avoid it.
51

6-
[target.x86_64-unknown-linux-gnu]
7-
rustflags = [
8-
"-C", "link-arg=-lgcc_eh",
9-
]
2+
# Previously we added this to rustflags for all linux builds:
3+
# "-C", "link-arg=-lgcc_eh"
4+
# It was to fix this error when loading the loadable extension:
5+
# undefined symbol: _Unwind_Resume
6+
# Now, we instead build using:
7+
# -Z build-std=panic_abort,core,alloc
8+
# This fixes the same issue. We still keep -lgcc_eh,
9+
# to support manual builds without -Z build-std.
10+
11+
# Without -Z build-std, with -lgcc_eh:
12+
# 241KB, loading works
13+
# Without -Z build-std, without -lgcc_eh:
14+
# 207KB, undefined symbol: _Unwind_Resume
15+
# With -Z build-std, without -lgcc_eh:
16+
# 173K, loading works
17+
# With -Z build-std, with -lgcc_eh:
18+
# 173K, loading works
19+
# Conclusion: -lgcc_eh has no effect when using -Z build-std.
1020

11-
[target.i686-linux-unknown-linux-gnu]
21+
[target.x86_64-unknown-linux-gnu]
1222
rustflags = [
1323
"-C", "link-arg=-lgcc_eh",
1424
]
1525

16-
[target.aarch64-linux-unknown-linux-gnu]
26+
[target.i686-unknown-linux-gnu]
1727
rustflags = [
1828
"-C", "link-arg=-lgcc_eh",
1929
]
2030

2131
[target.aarch64-unknown-linux-gnu]
32+
linker = "aarch64-linux-gnu-gcc"
2233
rustflags = [
2334
"-C", "link-arg=-lgcc_eh",
2435
]

.github/actions/upload/action.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ runs:
1515
using: "composite"
1616
steps:
1717
- name: Upload binary
18-
uses: svenstaro/upload-release-action@v2
19-
with:
20-
repo_token: ${{ inputs.repo-token }}
21-
overwrite: true
22-
file: ${{ inputs.file-name }}
23-
asset_name: ${{ inputs.file-name }}
24-
tag: ${{ inputs.tag }}
18+
shell: bash
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
GH_REPO: ${{ github.repository }}
22+
run: |
23+
gh release upload "${{ inputs.tag }}" "${{ inputs.file-name }}"

.github/workflows/linux.yml

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
on:
22
push:
3-
workflow_dispatch:
43
name: "linux"
54
jobs:
65
build_x86_64:
@@ -18,15 +17,7 @@ jobs:
1817
components: rust-src
1918

2019
- name: Build binaries
21-
run: bash tool/build_linux.sh x64
22-
23-
- name: Upload binary
24-
if: github.event_name == 'workflow_dispatch'
25-
uses: ./.github/actions/upload
26-
with:
27-
repo-token: ${{ secrets.GITHUB_TOKEN }}
28-
file-name: libpowersync_x64.so
29-
tag: ${{ github.ref_name }}
20+
run: ./tool/build_linux.sh x64
3021

3122
build_aarch64:
3223
name: Building Linux aarch64
@@ -43,12 +34,4 @@ jobs:
4334
components: rust-src
4435

4536
- name: Build binaries
46-
run: bash tool/build_linux.sh aarch64
47-
48-
- name: Upload binary
49-
if: github.event_name == 'workflow_dispatch'
50-
uses: ./.github/actions/upload
51-
with:
52-
repo-token: ${{ secrets.GITHUB_TOKEN }}
53-
file-name: libpowersync_aarch64.so
54-
tag: ${{ github.ref_name }}
37+
run: ./tool/build_linux.sh aarch64

.github/workflows/macos.yml

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
on:
22
push:
3-
workflow_dispatch:
43
name: "macos"
54
jobs:
65
build_macOS_aarch64:
@@ -11,16 +10,14 @@ jobs:
1110
with:
1211
submodules: true
1312

14-
- name: Build binary
15-
run: bash tool/build_macos.sh aarch64
16-
17-
- name: Upload binary
18-
if: github.event_name == 'workflow_dispatch'
19-
uses: ./.github/actions/upload
13+
- name: Install Rust Nightly
14+
uses: dtolnay/rust-toolchain@stable
2015
with:
21-
repo-token: ${{ secrets.GITHUB_TOKEN }}
22-
file-name: libpowersync_aarch64.dylib
23-
tag: ${{ github.ref_name }}
16+
toolchain: nightly-2024-05-18
17+
components: rust-src
18+
19+
- name: Build binary
20+
run: ./tool/build_macos.sh aarch64
2421

2522
build_macOS_x64:
2623
name: Building macOS x64
@@ -30,13 +27,11 @@ jobs:
3027
with:
3128
submodules: true
3229

33-
- name: Build binary
34-
run: bash tool/build_macos.sh x64
35-
36-
- name: Upload binary
37-
if: github.event_name == 'workflow_dispatch'
38-
uses: ./.github/actions/upload
30+
- name: Install Rust Nightly
31+
uses: dtolnay/rust-toolchain@stable
3932
with:
40-
repo-token: ${{ secrets.GITHUB_TOKEN }}
41-
file-name: libpowersync_x64.dylib
42-
tag: ${{ github.ref_name }}
33+
toolchain: nightly-2024-05-18
34+
components: rust-src
35+
36+
- name: Build binary
37+
run: ./tool/build_macos.sh x64

.github/workflows/release.yml

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
name: release
22
on:
33
workflow_dispatch:
4-
push:
4+
inputs:
5+
publish:
6+
type: boolean
7+
required: false
8+
default: false
9+
description: Set to true to publish artifacts to external targets such as Maven Central
510
jobs:
611
draft_release:
712
if: github.event_name == 'workflow_dispatch'
@@ -57,6 +62,7 @@ jobs:
5762
cargo install cargo-ndk
5863
5964
- name: Publish for Android
65+
if: ${{ inputs.publish }}
6066
run: |
6167
cd android
6268
./gradlew publish
@@ -123,7 +129,7 @@ jobs:
123129
components: rust-src
124130

125131
- name: Build binaries
126-
run: bash tool/build_linux.sh x64
132+
run: ./tool/build_linux.sh x64
127133

128134
- name: Upload binary
129135
uses: ./.github/actions/upload
@@ -135,7 +141,7 @@ jobs:
135141
publish_linux_aarch64:
136142
name: Publish Linux aarch64
137143
needs: [draft_release]
138-
runs-on: ubuntu-latest
144+
runs-on: ubuntu-arm64
139145
steps:
140146
- uses: actions/checkout@v3
141147
with:
@@ -148,7 +154,7 @@ jobs:
148154
components: rust-src
149155

150156
- name: Build binaries
151-
run: bash tool/build_linux.sh aarch64
157+
run: ./tool/build_linux.sh aarch64
152158

153159
- name: Upload binary
154160
uses: ./.github/actions/upload
@@ -166,6 +172,12 @@ jobs:
166172
with:
167173
submodules: true
168174

175+
- name: Install Rust Nightly
176+
uses: dtolnay/rust-toolchain@stable
177+
with:
178+
toolchain: nightly-2024-05-18
179+
components: rust-src
180+
169181
- name: Build binary
170182
run: bash tool/build_windows.sh x64
171183

@@ -185,8 +197,14 @@ jobs:
185197
with:
186198
submodules: true
187199

200+
- name: Install Rust Nightly
201+
uses: dtolnay/rust-toolchain@stable
202+
with:
203+
toolchain: nightly-2024-05-18
204+
components: rust-src
205+
188206
- name: Build binary
189-
run: bash tool/build_macos.sh aarch64
207+
run: ./tool/build_macos.sh aarch64
190208

191209
- name: Upload binary
192210
uses: ./.github/actions/upload
@@ -204,8 +222,14 @@ jobs:
204222
with:
205223
submodules: true
206224

225+
- name: Install Rust Nightly
226+
uses: dtolnay/rust-toolchain@stable
227+
with:
228+
toolchain: nightly-2024-05-18
229+
components: rust-src
230+
207231
- name: Build binary
208-
run: bash tool/build_macos.sh x64
232+
run: ./tool/build_macos.sh x64
209233

210234
- name: Upload binary
211235
uses: ./.github/actions/upload

.github/workflows/tests.yml

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ jobs:
2222
run: |
2323
sudo apt install libreadline-dev
2424
25+
- name: Install Rust Nightly
26+
uses: dtolnay/rust-toolchain@stable
27+
with:
28+
toolchain: nightly-2024-05-18
29+
components: rust-src
30+
2531
- name: Build
2632
run: |
2733
# Need a debug build for the dart tests

.github/workflows/windows.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ jobs:
1010
with:
1111
submodules: true
1212

13-
- name: Build binary
14-
run: bash tool/build_windows.sh x64
15-
16-
- name: Upload binary
17-
if: github.event_name == 'workflow_dispatch'
18-
uses: ./.github/actions/upload
13+
- name: Install Rust Nightly
14+
uses: dtolnay/rust-toolchain@stable
1915
with:
20-
repo-token: ${{ secrets.GITHUB_TOKEN }}
21-
file-name: powersync_x64.dll
22-
tag: ${{ github.ref_name }}
16+
toolchain: nightly-2024-05-18
17+
components: rust-src
18+
19+
- name: Build binary
20+
run: ./tool/build_windows.sh x64

RELEASING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ git push --tags
2121
Build:
2222

2323
```
24-
gh workflow run release --ref v1.2.3
24+
gh workflow run release --ref v1.2.3 -f publish=true
2525
```
2626

2727
The above does the following:

tool/build_linux.sh

100644100755
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#!/bin/sh
2+
set -e
3+
14
if [ "$1" = "x64" ]; then
2-
rustup target add target x86_64-unknown-linux-gnu
3-
cargo build -p powersync_loadable --release
4-
mv "target/release/libpowersync.so" "libpowersync_x64.so"
5+
cargo build -p powersync_loadable -Z build-std=panic_abort,core,alloc --release --target x86_64-unknown-linux-gnu
6+
mv "target/x86_64-unknown-linux-gnu/release/libpowersync.so" "libpowersync_x64.so"
57
else
6-
rustup target add aarch64-unknown-linux-gnu
7-
cargo build -p powersync_loadable --release
8-
mv "target/release/libpowersync.so" "libpowersync_aarch64.so"
8+
cargo build -p powersync_loadable -Z build-std=panic_abort,core,alloc --release --target aarch64-unknown-linux-gnu
9+
mv "target/aarch64-unknown-linux-gnu/release/libpowersync.so" "libpowersync_aarch64.so"
910
fi

tool/build_macos.sh

100644100755
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
#!/bin/sh
2+
set -e
3+
14
if [ "$1" = "x64" ]; then
2-
#Note: x86_64-apple-darwin has not been tested.
3-
rustup target add target x86_64-apple-darwin
4-
cargo build -p powersync_loadable --release
5-
mv "target/release/libpowersync.dylib" "libpowersync_x64.dylib"
5+
cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target x86_64-apple-darwin
6+
mv "target/x86_64-apple-darwin/release/libpowersync.dylib" "libpowersync_x64.dylib"
67
else
7-
rustup target add aarch64-apple-darwin
8-
cargo build -p powersync_loadable --release
9-
mv "target/release/libpowersync.dylib" "libpowersync_aarch64.dylib"
8+
cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target aarch64-apple-darwin
9+
mv "target/aarch64-apple-darwin/release/libpowersync.dylib" "libpowersync_aarch64.dylib"
1010
fi

tool/build_windows.sh

100644100755
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#!/bin/sh
2+
set -e
3+
14
if [ "$1" = "x64" ]; then
2-
rustup target add x86_64-pc-windows-msvc
3-
cargo build -p powersync_loadable --release
4-
mv "target/release/powersync.dll" "powersync_x64.dll"
5+
cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target x86_64-pc-windows-msvc
6+
mv "target/x86_64-pc-windows-msvc/release/powersync.dll" "powersync_x64.dll"
57
else
68
#Note: aarch64-pc-windows-msvc has not been tested.
7-
rustup target add aarch64-pc-windows-msvc
8-
cargo build -p powersync_loadable --release
9-
mv "target/release/powersync.dll" "powersync_aarch64.dll"
9+
cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target aarch64-pc-windows-msvc
10+
mv "target/aarch64-pc-windows-msvc/release/powersync.dll" "powersync_aarch64.dll"
1011
fi

0 commit comments

Comments
 (0)