Skip to content

Use static libpowersync to simplify build #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/actions/build-wasm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ runs:
using: "composite"
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
Expand All @@ -24,11 +22,6 @@ runs:
tar x -zf - -C /opt/homebrew/opt/llvm@18/lib/clang/18*
curl -sS -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sysroot-22.0.tar.gz | \
sudo tar x -zf - -C /opt
- name: Install Rust Nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-05-18
components: rust-src
- name: Set environment variable
shell: bash
run: |
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

36 changes: 5 additions & 31 deletions sqlite3/assets/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ FetchContent_MakeAvailable(sqlite3)

file(DOWNLOAD https://raw.githubusercontent.com/sqlite/sqlite/master/src/test_vfstrace.c "${CMAKE_BINARY_DIR}/vfstrace.c")

get_filename_component(RS_LIB_DIR "${CMAKE_BINARY_DIR}/../../powersync-sqlite-core/" ABSOLUTE)
set(RS_LIB "powersync")
set(RS_WASM_TGT "wasm32-wasi")
set(RS_WASM_TGT_DIR "${RS_LIB_DIR}/target/${RS_WASM_TGT}")

set(RS_RELEASE_OUT "${RS_WASM_TGT_DIR}/wasm/")
set(RS_RELEASE_OUT_DEPS "${RS_WASM_TGT_DIR}/wasm/deps")
set(RS_RELEASE_EXTENSION_OUT "${RS_RELEASE_OUT}/powersync-extension.o")
set(POWERSYNC_VERSION "0.3.0")
set(POWERSYNC_A "${CMAKE_BINARY_DIR}/libpowersync-wasm.a")
file(DOWNLOAD "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v${POWERSYNC_VERSION}/libpowersync-wasm.a" "${POWERSYNC_A}")

# Generate symbols we need to export from the sqlite3.wasm build
add_custom_command(
Expand All @@ -47,7 +42,6 @@ macro(base_sqlite3_target name debug)
${CMAKE_CURRENT_SOURCE_DIR}/os_web.c
${CMAKE_CURRENT_SOURCE_DIR}/helpers.c
${sqlite3_SOURCE_DIR}/sqlite3.c
${RS_RELEASE_EXTENSION_OUT}
)
set(flags -Wall -Wextra -Wno-unused-parameter -Wno-unused-function)

Expand All @@ -71,6 +65,7 @@ macro(base_sqlite3_target name debug)
-Wl,--import-memory
--sysroot ${wasi_sysroot}
${sources}
${POWERSYNC_A}
@${CMAKE_CURRENT_BINARY_DIR}/required_symbols.txt
DEPENDS ${sources} required_symbols
VERBATIM
Expand All @@ -97,31 +92,10 @@ macro(base_sqlite3_target name debug)
add_custom_target(${name} DEPENDS ${output})
endmacro()

# Script to use llc to get object code from bytecode
set(objectcode_script "${CMAKE_CURRENT_BINARY_DIR}/loop_objectcode_script.sh")
file(WRITE ${objectcode_script}
"cd ${RS_RELEASE_OUT_DEPS}\n"
"for filename in *.bc; do llc -march=wasm32 -filetype=obj $filename -o $filename.o; done\n"
"wasm-ld -relocatable *.o -o ../powersync-extension.o"
)

add_custom_target(
powersync_core_bytecode
COMMAND ${CMAKE_COMMAND} -E env
"RUSTFLAGS=--emit=llvm-bc -C linker=true"
cargo build -p powersync_loadable --profile wasm --no-default-features --features \"powersync_core/static powersync_core/omit_load_extension sqlite_nostd/static sqlite_nostd/omit_load_extension\" -Z build-std=panic_abort,core,alloc --target ${RS_WASM_TGT}
WORKING_DIRECTORY ${RS_LIB_DIR}
# Converts bytecode to wasm object files
COMMAND sh ${objectcode_script}
)

base_sqlite3_target(sqlite3_debug true)
base_sqlite3_target(sqlite3_opt false)

add_dependencies(sqlite3_opt powersync_core_bytecode)
add_dependencies(sqlite3_debug powersync_core_bytecode)

add_custom_target(output)
add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3_opt.wasm ${PROJECT_SOURCE_DIR}/../../example/web/sqlite3.wasm)
add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3_debug.init.wasm ${PROJECT_SOURCE_DIR}/../../example/web/sqlite3.debug.wasm)
add_dependencies(output sqlite3_debug sqlite3_opt powersync_core_bytecode)
add_dependencies(output sqlite3_debug sqlite3_opt)
6 changes: 4 additions & 2 deletions sqlite3/assets/wasm/os_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include "bridge.h"
#include "sqlite3.h"

extern int __rust_no_alloc_shim_is_unstable = 0;
extern int sqlite3_powersync_init(sqlite3 *db, char **pzErrMsg,
const sqlite3_api_routines *pApi);

int sqlite3_os_init(void) {
sqlite3_auto_extension((void (*)(void)) & sqlite3_powersync_init);
int rc = sqlite3_auto_extension((void (*)(void)) & sqlite3_powersync_init);
if (rc != SQLITE_OK) {
return rc;
}
return SQLITE_OK;
}

Expand Down
1 change: 0 additions & 1 deletion sqlite3/powersync-sqlite-core
Submodule powersync-sqlite-core deleted from 053f7f
Loading