From d1465a8c4a6c4292079350ff4775f58166a1333b Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 8 Oct 2024 17:07:34 +0200 Subject: [PATCH 1/7] Use build-std. --- .cargo/config.toml | 31 +++++++++++++++++++++---------- .github/workflows/linux.yml | 4 ++-- .github/workflows/tests.yml | 4 ++-- tool/build_linux.sh | 13 +++++++------ tool/build_macos.sh | 14 +++++++------- tool/build_windows.sh | 13 +++++++------ 6 files changed, 46 insertions(+), 33 deletions(-) mode change 100644 => 100755 tool/build_linux.sh mode change 100644 => 100755 tool/build_macos.sh mode change 100644 => 100755 tool/build_windows.sh diff --git a/.cargo/config.toml b/.cargo/config.toml index 7c2058e..caa816c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,24 +1,35 @@ -# On Linux, if we don't link to gcc_eh, we get can get this error when loading the loadable extension: -# undefined symbol: _Unwind_Resume -# This adds around 29KB to the loadable extension. -# 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. -[target.x86_64-unknown-linux-gnu] -rustflags = [ - "-C", "link-arg=-lgcc_eh", -] +# Previously we added this to rustflags for all linux builds: +# "-C", "link-arg=-lgcc_eh" +# It was to fix this error when loading the loadable extension: +# undefined symbol: _Unwind_Resume +# Now, we instead build using: +# -Z build-std=panic_abort,core,alloc +# This fixes the same issue. We still keep -lgcc_eh, +# to support manual builds without -Z build-std. + +# Without -Z build-std, with -lgcc_eh: +# 241KB, loading works +# Without -Z build-std, without -lgcc_eh: +# 207KB, undefined symbol: _Unwind_Resume +# With -Z build-std, without -lgcc_eh: +# 173K, loading works +# With -Z build-std, with -lgcc_eh: +# 173K, loading works +# Conclusion: -lgcc_eh has no effect when using -Z build-std. -[target.i686-linux-unknown-linux-gnu] +[target.x86_64-unknown-linux-gnu] rustflags = [ "-C", "link-arg=-lgcc_eh", ] -[target.aarch64-linux-unknown-linux-gnu] +[target.i686-unknown-linux-gnu] rustflags = [ "-C", "link-arg=-lgcc_eh", ] [target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" rustflags = [ "-C", "link-arg=-lgcc_eh", ] diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index b3f11d3..9425e73 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -18,7 +18,7 @@ jobs: components: rust-src - name: Build binaries - run: bash tool/build_linux.sh x64 + run: ./tool/build_linux.sh x64 - name: Upload binary if: github.event_name == 'workflow_dispatch' @@ -43,7 +43,7 @@ jobs: components: rust-src - name: Build binaries - run: bash tool/build_linux.sh aarch64 + run: ./tool/build_linux.sh aarch64 - name: Upload binary if: github.event_name == 'workflow_dispatch' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1277c0e..8d9dd43 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,12 +20,12 @@ jobs: - name: Ubuntu setup if: matrix.os == 'ubuntu-24.04' run: | - sudo apt install libreadline-dev + sudo apt install libreadline-dev gcc-aarch64-linux-gnu - name: Build run: | # Need a debug build for the dart tests - cargo build -p powersync_loadable + cargo build -p powersync_loadable -Z build-std=panic_abort,core,alloc --release --target x86_64-unknown-linux-gnu cargo build -p powersync_loadable --release cargo build -p powersync_core --release --features static diff --git a/tool/build_linux.sh b/tool/build_linux.sh old mode 100644 new mode 100755 index b7f904f..ed19841 --- a/tool/build_linux.sh +++ b/tool/build_linux.sh @@ -1,9 +1,10 @@ +#!/bin/sh +set -e + if [ "$1" = "x64" ]; then - rustup target add target x86_64-unknown-linux-gnu - cargo build -p powersync_loadable --release - mv "target/release/libpowersync.so" "libpowersync_x64.so" + cargo build -p powersync_loadable -Z build-std=panic_abort,core,alloc --release --target x86_64-unknown-linux-gnu + mv "target/x86_64-unknown-linux-gnu/release/libpowersync.so" "libpowersync_x64.so" else - rustup target add aarch64-unknown-linux-gnu - cargo build -p powersync_loadable --release - mv "target/release/libpowersync.so" "libpowersync_aarch64.so" + cargo build -p powersync_loadable -Z build-std=panic_abort,core,alloc --release --target aarch64-unknown-linux-gnu + mv "target/aarch64-unknown-linux-gnu/release/libpowersync.so" "libpowersync_aarch64.so" fi diff --git a/tool/build_macos.sh b/tool/build_macos.sh old mode 100644 new mode 100755 index 18428bc..01e3bd3 --- a/tool/build_macos.sh +++ b/tool/build_macos.sh @@ -1,10 +1,10 @@ +#!/bin/sh +set -e + if [ "$1" = "x64" ]; then - #Note: x86_64-apple-darwin has not been tested. - rustup target add target x86_64-apple-darwin - cargo build -p powersync_loadable --release - mv "target/release/libpowersync.dylib" "libpowersync_x64.dylib" + cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target x86_64-apple-darwin + mv "target/x86_64-apple-darwin/release/libpowersync.dylib" "libpowersync_x64.dylib" else - rustup target add aarch64-apple-darwin - cargo build -p powersync_loadable --release - mv "target/release/libpowersync.dylib" "libpowersync_aarch64.dylib" + cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target aarch64-apple-darwin + mv "target/aarch64-apple-darwin/release/libpowersync.dylib" "libpowersync_aarch64.dylib" fi diff --git a/tool/build_windows.sh b/tool/build_windows.sh old mode 100644 new mode 100755 index 64c8b8f..fd94325 --- a/tool/build_windows.sh +++ b/tool/build_windows.sh @@ -1,10 +1,11 @@ +#!/bin/sh +set -e + if [ "$1" = "x64" ]; then - rustup target add x86_64-pc-windows-msvc - cargo build -p powersync_loadable --release - mv "target/release/powersync.dll" "powersync_x64.dll" + cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target x86_64-pc-windows-msvc + mv "target/x86_64-pc-windows-msvc/release/powersync.dll" "powersync_x64.dll" else #Note: aarch64-pc-windows-msvc has not been tested. - rustup target add aarch64-pc-windows-msvc - cargo build -p powersync_loadable --release - mv "target/release/powersync.dll" "powersync_aarch64.dll" + cargo build -Z build-std=panic_abort,core,alloc -p powersync_loadable --release --target aarch64-pc-windows-msvc + mv "target/aarch64-pc-windows-msvc/release/powersync.dll" "powersync_aarch64.dll" fi \ No newline at end of file From ae385065eefc7aadece315df3437defd6994e796 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 8 Oct 2024 17:17:43 +0200 Subject: [PATCH 2/7] Add missing toolchains. --- .github/workflows/macos.yml | 14 ++++++++++++-- .github/workflows/windows.yml | 7 ++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index ff513f8..a995f05 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -11,8 +11,13 @@ jobs: with: submodules: true + - name: Setup + run: | + rustup toolchain install nightly-2024-05-18-aarch64-apple-darwin + rustup component add rust-src --toolchain nightly-2024-05-18-aarch64-apple-darwin + - name: Build binary - run: bash tool/build_macos.sh aarch64 + run: ./tool/build_macos.sh aarch64 - name: Upload binary if: github.event_name == 'workflow_dispatch' @@ -30,8 +35,13 @@ jobs: with: submodules: true + - name: Setup + run: | + rustup toolchain install nightly-2024-05-18-x86_64-apple-darwin + rustup component add rust-src --toolchain nightly-2024-05-18-x86_64-apple-darwin + - name: Build binary - run: bash tool/build_macos.sh x64 + run: ./tool/build_macos.sh x64 - name: Upload binary if: github.event_name == 'workflow_dispatch' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 1e659e2..2388c27 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -10,8 +10,13 @@ jobs: with: submodules: true + - name: Setup + run: | + rustup toolchain install nightly-2024-05-18-x86_64-pc-windows-msvc + rustup component add rust-src --toolchain nightly-2024-05-18-x86_64-pc-windows-msvc + - name: Build binary - run: bash tool/build_windows.sh x64 + run: ./tool/build_windows.sh x64 - name: Upload binary if: github.event_name == 'workflow_dispatch' From 4389315681343de913b7b6720df33c5c521c073e Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 8 Oct 2024 17:40:50 +0200 Subject: [PATCH 3/7] More consistent rust-toolchain setup. --- .github/workflows/macos.yml | 18 ++++++++++-------- .github/workflows/tests.yml | 8 +++++++- .github/workflows/windows.yml | 9 +++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index a995f05..2acd41a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -11,10 +11,11 @@ jobs: with: submodules: true - - name: Setup - run: | - rustup toolchain install nightly-2024-05-18-aarch64-apple-darwin - rustup component add rust-src --toolchain nightly-2024-05-18-aarch64-apple-darwin + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2024-05-18 + components: rust-src - name: Build binary run: ./tool/build_macos.sh aarch64 @@ -35,10 +36,11 @@ jobs: with: submodules: true - - name: Setup - run: | - rustup toolchain install nightly-2024-05-18-x86_64-apple-darwin - rustup component add rust-src --toolchain nightly-2024-05-18-x86_64-apple-darwin + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2024-05-18 + components: rust-src - name: Build binary run: ./tool/build_macos.sh x64 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8d9dd43..a1e6c99 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,13 @@ jobs: - name: Ubuntu setup if: matrix.os == 'ubuntu-24.04' run: | - sudo apt install libreadline-dev gcc-aarch64-linux-gnu + sudo apt install libreadline-dev + + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2024-05-18 + components: rust-src - name: Build run: | diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2388c27..346e21d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -10,10 +10,11 @@ jobs: with: submodules: true - - name: Setup - run: | - rustup toolchain install nightly-2024-05-18-x86_64-pc-windows-msvc - rustup component add rust-src --toolchain nightly-2024-05-18-x86_64-pc-windows-msvc + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2024-05-18 + components: rust-src - name: Build binary run: ./tool/build_windows.sh x64 From 3c366542769df38ccc6158a853b79da3ba94d231 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 8 Oct 2024 17:46:16 +0200 Subject: [PATCH 4/7] Revert test build. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a1e6c99..70e9193 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: - name: Build run: | # Need a debug build for the dart tests - cargo build -p powersync_loadable -Z build-std=panic_abort,core,alloc --release --target x86_64-unknown-linux-gnu + cargo build -p powersync_loadable cargo build -p powersync_loadable --release cargo build -p powersync_core --release --features static From 9958fbe611d4db30532552af48c58d2f7b9f241f Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 8 Oct 2024 18:06:37 +0200 Subject: [PATCH 5/7] Make publishing optional. --- .github/actions/upload/action.yml | 13 +++++------ .github/workflows/linux.yml | 17 -------------- .github/workflows/release.yml | 38 +++++++++++++++++++++++++------ RELEASING.md | 2 +- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/.github/actions/upload/action.yml b/.github/actions/upload/action.yml index e0c4bc9..60f4d23 100644 --- a/.github/actions/upload/action.yml +++ b/.github/actions/upload/action.yml @@ -15,10 +15,9 @@ runs: using: "composite" steps: - name: Upload binary - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ inputs.repo-token }} - overwrite: true - file: ${{ inputs.file-name }} - asset_name: ${{ inputs.file-name }} - tag: ${{ inputs.tag }} + shell: bash + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + gh release upload "${{ inputs.tag }}" "${{ inputs.file-name }}" diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 9425e73..68b0618 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -1,6 +1,5 @@ on: push: - workflow_dispatch: name: "linux" jobs: build_x86_64: @@ -20,14 +19,6 @@ jobs: - name: Build binaries run: ./tool/build_linux.sh x64 - - name: Upload binary - if: github.event_name == 'workflow_dispatch' - uses: ./.github/actions/upload - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - file-name: libpowersync_x64.so - tag: ${{ github.ref_name }} - build_aarch64: name: Building Linux aarch64 runs-on: ubuntu-arm64 @@ -44,11 +35,3 @@ jobs: - name: Build binaries run: ./tool/build_linux.sh aarch64 - - - name: Upload binary - if: github.event_name == 'workflow_dispatch' - uses: ./.github/actions/upload - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - file-name: libpowersync_aarch64.so - tag: ${{ github.ref_name }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f75db75..04dc0a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,12 @@ name: release on: workflow_dispatch: - push: + inputs: + publish: + type: boolean + required: false + default: false + description: Set to true to publish artifacts to external targets such as Maven Central jobs: draft_release: if: github.event_name == 'workflow_dispatch' @@ -57,6 +62,7 @@ jobs: cargo install cargo-ndk - name: Publish for Android + if: ${{ inputs.publish }} run: | cd android ./gradlew publish @@ -123,7 +129,7 @@ jobs: components: rust-src - name: Build binaries - run: bash tool/build_linux.sh x64 + run: ./tool/build_linux.sh x64 - name: Upload binary uses: ./.github/actions/upload @@ -135,7 +141,7 @@ jobs: publish_linux_aarch64: name: Publish Linux aarch64 needs: [draft_release] - runs-on: ubuntu-latest + runs-on: ubuntu-arm64 steps: - uses: actions/checkout@v3 with: @@ -148,7 +154,7 @@ jobs: components: rust-src - name: Build binaries - run: bash tool/build_linux.sh aarch64 + run: ./tool/build_linux.sh aarch64 - name: Upload binary uses: ./.github/actions/upload @@ -166,8 +172,14 @@ jobs: with: submodules: true + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2024-05-18 + components: rust-src + - name: Build binary - run: bash tool/build_windows.sh x64 + run: ./tool/build_windows.sh x64 - name: Upload binary uses: ./.github/actions/upload @@ -185,8 +197,14 @@ jobs: with: submodules: true + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2024-05-18 + components: rust-src + - name: Build binary - run: bash tool/build_macos.sh aarch64 + run: ./tool/build_macos.sh aarch64 - name: Upload binary uses: ./.github/actions/upload @@ -204,8 +222,14 @@ jobs: with: submodules: true + - name: Install Rust Nightly + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2024-05-18 + components: rust-src + - name: Build binary - run: bash tool/build_macos.sh x64 + run: ./tool/build_macos.sh x64 - name: Upload binary uses: ./.github/actions/upload diff --git a/RELEASING.md b/RELEASING.md index 62b2a0e..7a181fa 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -21,7 +21,7 @@ git push --tags Build: ``` -gh workflow run release --ref v1.2.3 +gh workflow run release --ref v1.2.3 -f publish=true ``` The above does the following: From 3fcf07fec2fef95030ddc34f6e615aaed5f9d891 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 8 Oct 2024 18:07:40 +0200 Subject: [PATCH 6/7] Remove "upload binary" that we never triggered. --- .github/workflows/macos.yml | 17 ----------------- .github/workflows/windows.yml | 8 -------- 2 files changed, 25 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2acd41a..f56db31 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,6 +1,5 @@ on: push: - workflow_dispatch: name: "macos" jobs: build_macOS_aarch64: @@ -20,14 +19,6 @@ jobs: - name: Build binary run: ./tool/build_macos.sh aarch64 - - name: Upload binary - if: github.event_name == 'workflow_dispatch' - uses: ./.github/actions/upload - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - file-name: libpowersync_aarch64.dylib - tag: ${{ github.ref_name }} - build_macOS_x64: name: Building macOS x64 runs-on: macos-12 @@ -44,11 +35,3 @@ jobs: - name: Build binary run: ./tool/build_macos.sh x64 - - - name: Upload binary - if: github.event_name == 'workflow_dispatch' - uses: ./.github/actions/upload - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - file-name: libpowersync_x64.dylib - tag: ${{ github.ref_name }} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 346e21d..bfca14d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -18,11 +18,3 @@ jobs: - name: Build binary run: ./tool/build_windows.sh x64 - - - name: Upload binary - if: github.event_name == 'workflow_dispatch' - uses: ./.github/actions/upload - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - file-name: powersync_x64.dll - tag: ${{ github.ref_name }} From 89693a7edfe3623138d4621d095de1378f1ed950 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Tue, 8 Oct 2024 18:19:17 +0200 Subject: [PATCH 7/7] Bash for windows builds. --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 04dc0a8..2a0a40d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -179,7 +179,7 @@ jobs: components: rust-src - name: Build binary - run: ./tool/build_windows.sh x64 + run: bash tool/build_windows.sh x64 - name: Upload binary uses: ./.github/actions/upload