Skip to content
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

Wasm32 unknown unknown support #1

Merged
merged 27 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
004cf26
Add `wasm32-unknown-unknown` support
trevyn Aug 4, 2021
82354cf
Null-terminate vfs name
trevyn May 26, 2023
b469dfa
Merge branch 'rusqlite:master' into wasm32-unknown-unknown
trevyn Sep 29, 2023
77af655
Merge branch 'rusqlite:master' into wasm32-unknown-unknown
trevyn Oct 17, 2023
463090d
Add `fabs` declaration and `strspn.c`
trevyn Oct 17, 2023
3f48d37
Merge remote-tracking branch 'upstream/master' into wasm32-unknown-un…
trevyn Jan 8, 2024
7c6cd3b
bring in minimum compiler-rt dependencies
carlsverre Jan 8, 2024
c0a8bbf
Merge pull request #1 from carlsverre/wasm32-unknown-unknown
trevyn Jan 8, 2024
1eb9e13
Revert "bring in minimum compiler-rt dependencies"
trevyn Jan 9, 2024
340b1ac
use `compiler-rt-builtins`
trevyn Jan 9, 2024
470344c
remove windows wasm-pack workaround
trevyn Jan 9, 2024
fe59054
use `wasm32-unknown-unknown-openbsd-libc`
trevyn Jan 9, 2024
c471180
remove unnecessary `allow(unused_imports)`
trevyn Jan 9, 2024
40547f6
qualify only use of `version_number()` instead of `use`
trevyn Jan 10, 2024
b4a0240
bump `actions/checkout` to match rest of `main.yml`
trevyn Jan 10, 2024
504eff5
Merge remote-tracking branch 'upstream/master' into wasm32-unknown-un…
trevyn Jan 17, 2024
92ad22f
Merge remote-tracking branch 'upstream/master' into wasm32-unknown-un…
trevyn Jan 28, 2024
3e1ee54
use `cargo:include` to pass libc include directory
trevyn Jan 28, 2024
4727aed
Forward target-feature flags to clang
jorgenpt Feb 17, 2024
e7cefe6
fix clippy
trevyn Feb 17, 2024
415cafe
Merge remote-tracking branch 'upstream/master' into wasm32-unknown-un…
trevyn Feb 17, 2024
c6a5205
Merge remote-tracking branch 'origin/master' into wasm32-unknown-unknown
ethe Nov 27, 2024
5da569d
remove compiler-rt-builtins requried
ethe Nov 27, 2024
304cca2
Always align to 8 bytes in wasm32
ethe Nov 28, 2024
a9caa65
make clippy happy
ethe Nov 28, 2024
df11016
revert alignment
ethe Nov 28, 2024
0dbdc88
Align to 8 byte on wasm32
ethe Nov 29, 2024
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
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ jobs:
RUSTFLAGS: -Ctarget-feature=+crt-static -Cdebuginfo=1
run: cargo build --features bundled

test-wasm32-unknown-unknown:
name: Test ${{ matrix.os }} (wasm32-unknown-unknown)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
# This has a matcher for test panics, so we use it even though elsewhere
# we use actions-rs/toolchain.
- uses: hecrj/setup-rust-action@v1
with:
rust-version: stable${{ matrix.host }}
targets: ${{ matrix.target }}

- name: Install Homebrew llvm on macOS
if: matrix.os == 'macos-latest'
run: brew install llvm

- name: Add llvm path on Windows
if: matrix.os == 'windows-latest'
run: echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- run: npm install -g wasm-pack

- name: Test wasm-pack ${{ matrix.host }}
run: wasm-pack test --node --features bundled

test-sqlcipher-bundled:
name: Test ${{ matrix.os }} (bundled SQLcipher + OpenSSL)
runs-on: ${{ matrix.os }}
Expand Down
89 changes: 45 additions & 44 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[package]
name = "rusqlite"
# Note: Update version in README.md when you change this.
version = "0.32.1"
authors = ["The rusqlite developers"]
edition = "2021"
categories = ["database"]
description = "Ergonomic wrapper for SQLite"
repository = "https://github.com/rusqlite/rusqlite"
documentation = "https://docs.rs/rusqlite/"
readme = "README.md"
keywords = ["sqlite", "database", "ffi"]
edition = "2021"
keywords = ["database", "ffi", "sqlite"]
license = "MIT"
categories = ["database"]
readme = "README.md"
repository = "https://github.com/rusqlite/rusqlite"
version = "0.32.1"

exclude = [
"/.github/*",
"/.gitattributes",
"/appveyor.yml",
"/.github/*",
"/Changelog.md",
"/appveyor.yml",
"/clippy.toml",
"/codecov.yml",
]
Expand Down Expand Up @@ -44,42 +44,42 @@ functions = []
# sqlite3_log: 3.6.23 (2010-03-09)
trace = []
# sqlite3_db_release_memory: 3.7.10 (2012-01-16)
release_memory = []
buildtime_bindgen = ["libsqlite3-sys/buildtime_bindgen"]
bundled = ["libsqlite3-sys/bundled", "modern_sqlite"]
bundled-sqlcipher = ["libsqlite3-sys/bundled-sqlcipher", "bundled"]
bundled-sqlcipher = ["bundled", "libsqlite3-sys/bundled-sqlcipher"]
bundled-sqlcipher-vendored-openssl = [
"libsqlite3-sys/bundled-sqlcipher-vendored-openssl",
"bundled-sqlcipher",
"libsqlite3-sys/bundled-sqlcipher-vendored-openssl",
]
buildtime_bindgen = ["libsqlite3-sys/buildtime_bindgen"]
limits = []
loadable_extension = ["libsqlite3-sys/loadable_extension"]
hooks = []
preupdate_hook = ["libsqlite3-sys/preupdate_hook", "hooks"]
i128_blob = []
limits = []
loadable_extension = ["libsqlite3-sys/loadable_extension"]
preupdate_hook = ["hooks", "libsqlite3-sys/preupdate_hook"]
release_memory = []
sqlcipher = ["libsqlite3-sys/sqlcipher"]
unlock_notify = ["libsqlite3-sys/unlock_notify"]
# xSavepoint, xRelease and xRollbackTo: 3.7.7 (2011-06-23)
vtab = []
csvtab = ["csv", "vtab"]
vtab = []
# pointer passing interfaces: 3.20.0
array = ["vtab"]
# session extension: 3.13.0
session = ["libsqlite3-sys/session", "hooks"]
session = ["hooks", "libsqlite3-sys/session"]
# window functions: 3.25.0
window = ["functions"]
# 3.9.0
series = ["vtab"]
# check for invalid query.
extra_check = []
# ]3.14.0, last]
modern_sqlite = ["libsqlite3-sys/bundled_bindings"]
in_gecko = ["modern_sqlite", "libsqlite3-sys/in_gecko"]
bundled-windows = ["libsqlite3-sys/bundled-windows"]
in_gecko = ["libsqlite3-sys/in_gecko", "modern_sqlite"]
modern_sqlite = ["libsqlite3-sys/bundled_bindings"]
# Build bundled sqlite with -fsanitize=address
with-asan = ["libsqlite3-sys/with-asan"]
column_decltype = []
wasm32-wasi-vfs = ["libsqlite3-sys/wasm32-wasi-vfs"]
with-asan = ["libsqlite3-sys/with-asan"]
# 3.23.0
serialize = ["modern_sqlite"]

Expand All @@ -91,7 +91,6 @@ modern-full = [
"array",
"backup",
"blob",
"modern_sqlite",
"chrono",
"collation",
"column_decltype",
Expand All @@ -103,6 +102,7 @@ modern-full = [
"jiff",
"limits",
"load_extension",
"modern_sqlite",
"serde_json",
"serialize",
"series",
Expand All @@ -115,37 +115,38 @@ modern-full = [
"window",
]

bundled-full = ["modern-full", "bundled"]
bundled-full = ["bundled", "modern-full"]

[dependencies]
bitflags = "2.6.0"
chrono = { version = "0.4.38", optional = true, default-features = false, features = [
"clock",
] }
csv = { version = "1.1", optional = true }
fallible-iterator = "0.3"
fallible-streaming-iterator = "0.1"
hashlink = "0.9"
jiff = { version = "0.1", optional = true, default-features = false, features = [
"std",
] }
rusqlite-macros = { path = "rusqlite-macros", version = "0.3.0", optional = true }
serde_json = { version = "1.0", optional = true }
smallvec = "1.6.1"
time = { version = "0.3.36", features = [
"formatting",
"macros",
"parsing",
], optional = true }
bitflags = "2.6.0"
hashlink = "0.9"
chrono = { version = "0.4.38", optional = true, default-features = false, features = [
"clock",
] }
serde_json = { version = "1.0", optional = true }
csv = { version = "1.1", optional = true }
url = { version = "2.1", optional = true }
fallible-iterator = "0.3"
fallible-streaming-iterator = "0.1"
uuid = { version = "1.0", optional = true }
smallvec = "1.6.1"
rusqlite-macros = { path = "rusqlite-macros", version = "0.3.0", optional = true }

[dev-dependencies]
doc-comment = "0.3"
tempfile = "3.1.0"
regex = "1.5.5"
uuid = { version = "1.0", features = ["v4"] }
tempfile = "3.1.0"
unicase = "2.6.0"
uuid = { version = "1.0", features = ["v4"] }
wasm-bindgen-test = "0.3"
# Use `bencher` over criterion because it builds much faster,
# and we don't have many benchmarks
bencher = "0.1"
Expand All @@ -158,8 +159,8 @@ version = "0.30.1"
name = "auto_ext"

[[test]]
name = "config_log"
harness = false
name = "config_log"

[[test]]
name = "deny_single_threaded_sqlite_config"
Expand All @@ -168,29 +169,29 @@ name = "deny_single_threaded_sqlite_config"
name = "vtab"

[[bench]]
name = "cache"
harness = false
name = "cache"

[[bench]]
name = "exec"
harness = false
name = "exec"

[[example]]
name = "loadable_extension"
crate-type = ["cdylib"]
required-features = ["loadable_extension", "functions", "trace"]
name = "loadable_extension"
required-features = ["functions", "loadable_extension", "trace"]

[[example]]
name = "load_extension"
required-features = ["load_extension", "bundled", "functions", "trace"]
required-features = ["bundled", "functions", "load_extension", "trace"]

[package.metadata.docs.rs]
features = ["modern-full", "rusqlite-macros"]
all-features = false
no-default-features = true
default-target = "x86_64-unknown-linux-gnu"
features = ["modern-full", "rusqlite-macros"]
no-default-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
features = ["bundled-full"]
all-features = false
features = ["bundled-full"]
52 changes: 33 additions & 19 deletions libsqlite3-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
[package]
name = "libsqlite3-sys"
version = "0.30.1"
authors = ["The rusqlite developers"]
edition = "2021"
repository = "https://github.com/rusqlite/rusqlite"
build = "build.rs"
categories = ["external-ffi-bindings"]
description = "Native bindings to the libsqlite3 library"
edition = "2021"
keywords = ["ffi", "sqlcipher", "sqlite"]
license = "MIT"
links = "sqlite3"
build = "build.rs"
keywords = ["sqlite", "sqlcipher", "ffi"]
categories = ["external-ffi-bindings"]
name = "libsqlite3-sys"
repository = "https://github.com/rusqlite/rusqlite"
version = "0.30.1"

[features]
default = ["min_sqlite_version_3_14_0"]
bundled = ["cc", "bundled_bindings"]
bundled-windows = ["cc", "bundled_bindings"]
bundled-sqlcipher = ["bundled"]
bundled-sqlcipher-vendored-openssl = ["bundled-sqlcipher", "openssl-sys/vendored"]
buildtime_bindgen = ["bindgen", "pkg-config", "vcpkg"]
sqlcipher = []
bundled = ["bundled_bindings", "cc"]
bundled-sqlcipher = ["bundled"]
bundled-sqlcipher-vendored-openssl = [
"bundled-sqlcipher",
"openssl-sys/vendored",
]
bundled-windows = ["bundled_bindings", "cc"]
default = ["min_sqlite_version_3_14_0"]
min_sqlite_version_3_14_0 = ["pkg-config", "vcpkg"]
sqlcipher = []
# Bundle only the bindings file. Note that this does nothing if
# `buildtime_bindgen` is enabled.
bundled_bindings = []
Expand All @@ -29,22 +32,33 @@ unlock_notify = []
# 3.13.0
preupdate_hook = ["buildtime_bindgen"]
# 3.13.0
session = ["preupdate_hook", "buildtime_bindgen"]
in_gecko = []
with-asan = []
session = ["buildtime_bindgen", "preupdate_hook"]
wasm32-wasi-vfs = []
with-asan = []

[dependencies]
openssl-sys = { version = "0.9.103", optional = true }

[target.wasm32-unknown-unknown.dependencies]
getrandom = { version = "0.2", features = ["js"] }
js-sys = "0.3"
wasm32-unknown-unknown-openbsd-libc = "0.2"

[build-dependencies]
bindgen = { version = "0.70", optional = true, default-features = false, features = ["runtime"] }
pkg-config = { version = "0.3.19", optional = true }
bindgen = { version = "0.70", optional = true, default-features = false, features = [
"runtime",
] }
cc = { version = "1.1.6", optional = true }
pkg-config = { version = "0.3.19", optional = true }
vcpkg = { version = "0.2.15", optional = true }
# for loadable_extension:
prettyplease = {version = "0.2.20", optional = true }
prettyplease = { version = "0.2.20", optional = true }
# like bindgen
quote = { version = "1.0.36", optional = true, default-features = false }
# like bindgen
syn = { version = "2.0.72", optional = true, features = ["full", "extra-traits", "visit-mut"] }
syn = { version = "2.0.72", optional = true, features = [
"extra-traits",
"full",
"visit-mut",
] }
55 changes: 54 additions & 1 deletion libsqlite3-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ mod build_bundled {
.flag("-DSQLITE_THREADSAFE=1")
.flag("-DSQLITE_USE_URI")
.flag("-DHAVE_USLEEP=1")
.flag("-DHAVE_ISNAN")
.flag("-D_POSIX_THREAD_SAFE_FUNCTIONS") // cross compile with MinGW
.warnings(false);

Expand Down Expand Up @@ -236,6 +235,10 @@ mod build_bundled {
cfg.static_crt(true);
}

if env::var("TARGET") != Ok("wasm32-unknown-unknown".to_string()) {
cfg.flag("-DHAVE_ISNAN");
}

if !win_target() {
cfg.flag("-DHAVE_LOCALTIME_R");
}
Expand All @@ -253,6 +256,56 @@ mod build_bundled {
cfg.file("sqlite3/wasm32-wasi-vfs.c");
}
}
if env::var("TARGET") == Ok("wasm32-unknown-unknown".to_string()) {
// Apple clang doesn't support wasm32, so use Homebrew clang by default.
if env::var("HOST") == Ok("x86_64-apple-darwin".to_string()) {
if env::var("CC").is_err() {
std::env::set_var("CC", "/usr/local/opt/llvm/bin/clang");
}
if env::var("AR").is_err() {
std::env::set_var("AR", "/usr/local/opt/llvm/bin/llvm-ar");
}
} else if env::var("HOST") == Ok("aarch64-apple-darwin".to_string()) {
if env::var("CC").is_err() {
std::env::set_var("CC", "/opt/homebrew/opt/llvm/bin/clang");
}
if env::var("AR").is_err() {
std::env::set_var("AR", "/opt/homebrew/opt/llvm/bin/llvm-ar");
}
}

cfg.flag("-DSQLITE_OS_OTHER")
.flag("-DSQLITE_TEMP_STORE=3")
.flag("-DSQLITE_OMIT_LOCALTIME")
.flag("-Wno-incompatible-library-redeclaration");

let supported_features = [
"atomics",
"bulk-memory",
"exception-handling",
"multivalue",
"mutable-globals",
"nontrapping-fptoint",
"reference-types",
"relaxed-simd",
"sign-ext",
"simd128",
];
for feature in env::var("CARGO_CFG_TARGET_FEATURE")
.unwrap_or_default()
.split(',')
{
if supported_features.contains(&feature) {
cfg.flag(format!("-m{feature}"));
}
}

cfg.include(
std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE").unwrap(),
);

println!("cargo:rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}
if cfg!(feature = "unlock_notify") {
cfg.flag("-DSQLITE_ENABLE_UNLOCK_NOTIFY");
}
Expand Down
Loading
Loading