-
Notifications
You must be signed in to change notification settings - Fork 83
Add duckdb recipe for emscripten #4983
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
Open
wolfv
wants to merge
10
commits into
emscripten-forge:main
Choose a base branch
from
wolfv:duckdb-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4304f6
Add duckdb recipe for emscripten
wolfv 6f7e023
Fix duckdb build: set SETUPTOOLS_SCM_PRETEND_VERSION
wolfv 401acd9
Fix duckdb version scheme for dirty source trees
wolfv 2843089
Fix _duckdb.so install location
wolfv 850d504
Build _duckdb.so as wasm side module
wolfv 39606be
Use CMAKE_PROJECT_INCLUDE for proper side module build
wolfv 826e708
Skip --export-dynamic-symbol linker flags on Emscripten
wolfv 7017caa
Disable LTO to fix duplicate symbol errors with wasm-ld
wolfv cd0a0b5
Allow multiple definitions for wasm-ld
wolfv f83efd9
Keep .dist-info so importlib.metadata can find duckdb
wolfv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| # Setup emscripten toolchain for scikit-build-core | ||
| emscripten_root=$(em-config EMSCRIPTEN_ROOT) | ||
| toolchain_path="${emscripten_root}/cmake/Modules/Platform/Emscripten.cmake" | ||
|
|
||
| export CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${toolchain_path} -DCMAKE_PROJECT_INCLUDE=${RECIPE_DIR}/overwriteProp.cmake" | ||
|
|
||
| # DuckDB-specific CMake flags for wasm passed via scikit-build-core config settings | ||
| ${PYTHON} -m pip install . ${PIP_ARGS} \ | ||
| -Ccmake.define.OVERRIDE_GIT_DESCRIBE="v${PKG_VERSION}" \ | ||
| -Ccmake.define.BUILD_EXTENSIONS="parquet;json;autocomplete" \ | ||
| -Ccmake.define.BUILD_SHELL=OFF \ | ||
| -Ccmake.define.BUILD_UNITTESTS=OFF \ | ||
| -Ccmake.define.ENABLE_EXTENSION_AUTOLOADING=OFF \ | ||
| -Ccmake.define.ENABLE_EXTENSION_AUTOINSTALL=OFF \ | ||
| -Ccmake.define.CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) | ||
| set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sSIDE_MODULE=1 -sWASM_BIGINT") | ||
| set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sSIDE_MODULE=1 -sWASM_BIGINT") | ||
| set(CMAKE_STRIP FALSE) | ||
|
|
||
| # DuckDB links libduckdb_static.a twice to resolve circular dependencies | ||
| # between the core and extensions. Native linkers handle this but wasm-ld | ||
| # does not. Allow multiple definitions to work around this. | ||
| add_link_options("LINKER:--allow-multiple-definition") |
29 changes: 29 additions & 0 deletions
29
recipes/recipes_emscripten/duckdb/patches/emscripten-python-target.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
| index abcdef1..1234567 100644 | ||
| --- a/CMakeLists.txt | ||
| +++ b/CMakeLists.txt | ||
| @@ -36,6 +36,15 @@ endif() | ||
| # Dependencies | ||
| # ──────────────────────────────────────────── | ||
| # PyBind11 | ||
| + | ||
| +# On Emscripten, FindPython only provides Python::Module, not Python::Python | ||
| +# (there is no shared libpython to link against). pybind11_add_module internally | ||
| +# calls python_add_library which expects Python::Python, so we provide a dummy | ||
| +# IMPORTED target to satisfy that requirement. | ||
| +if(EMSCRIPTEN AND NOT TARGET Python::Python) | ||
| + add_library(Python::Python INTERFACE IMPORTED) | ||
| +endif() | ||
| + | ||
| find_package(pybind11 REQUIRED CONFIG) | ||
|
|
||
| # DuckDB | ||
| @@ -100,7 +109,7 @@ if(APPLE) | ||
| target_link_options( | ||
| _duckdb PRIVATE "LINKER:-exported_symbol,_duckdb_adbc_init" | ||
| "LINKER:-exported_symbol,_PyInit__duckdb") | ||
| -elseif(UNIX AND NOT APPLE) | ||
| +elseif(UNIX AND NOT APPLE AND NOT EMSCRIPTEN) | ||
| target_link_options( | ||
| _duckdb PRIVATE "LINKER:--export-dynamic-symbol=duckdb_adbc_init" | ||
| "LINKER:--export-dynamic-symbol=PyInit__duckdb") |
13 changes: 13 additions & 0 deletions
13
recipes/recipes_emscripten/duckdb/patches/fix-dirty-version-scheme.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| diff --git a/duckdb_packaging/setuptools_scm_version.py b/duckdb_packaging/setuptools_scm_version.py | ||
| index 1234567..abcdef0 100644 | ||
| --- a/duckdb_packaging/setuptools_scm_version.py | ||
| +++ b/duckdb_packaging/setuptools_scm_version.py | ||
| @@ -53,7 +53,7 @@ def version_scheme(version: _VersionObject) -> str: | ||
|
|
||
| distance = int(version.distance or 0) | ||
| try: | ||
| - if distance == 0 and not version.dirty: | ||
| + if distance == 0: | ||
| return _tag_to_version(str(version.tag)) | ||
| return _bump_dev_version(str(version.tag), distance) | ||
| except Exception as e: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| context: | ||
| version: 1.4.4 | ||
|
|
||
| package: | ||
| name: python-duckdb | ||
| version: ${{ version }} | ||
|
|
||
| source: | ||
| git: https://github.com/duckdb/duckdb-python.git | ||
| tag: v${{ version }} | ||
| # expected_commit: a12f36ca411007f5eb48919448f61c7498112553 | ||
| patches: | ||
| - patches/emscripten-python-target.patch | ||
| - patches/fix-dirty-version-scheme.patch | ||
|
|
||
| build: | ||
| number: 0 | ||
| script: build.sh | ||
|
|
||
| files: | ||
| exclude: | ||
| - '**/__pycache__/**' | ||
| - '**/*.pyc' | ||
| - '**/test_*.py' | ||
| - 'duckdb_build/**' | ||
| python: | ||
| skip_pyc_compilation: | ||
| - '**/*.py' | ||
|
|
||
| requirements: | ||
| build: | ||
| - python | ||
| - cross-python_${{ target_platform }} | ||
| - ${{ compiler('cxx') }} | ||
| - pip | ||
| - setuptools | ||
| - setuptools-scm | ||
| - pybind11 | ||
| - scikit-build-core | ||
| - cmake | ||
| - ninja | ||
| host: | ||
| - python | ||
| - pybind11 | ||
| run: | ||
| - python | ||
|
|
||
| tests: | ||
| - script: pytester | ||
| files: | ||
| recipe: | ||
| - test_duckdb.py | ||
| requirements: | ||
| build: | ||
| - pytester | ||
| run: | ||
| - pytester-run | ||
|
|
||
| about: | ||
| homepage: https://duckdb.org/ | ||
| license: MIT | ||
| license_file: LICENSE | ||
| summary: DuckDB is an analytical in-process SQL database management system | ||
| description: | | ||
| DuckDB is an in-process SQL OLAP database management system. | ||
| It is designed to support analytical query workloads (OLAP) while | ||
| being embeddable in Python and other languages. | ||
| repository: https://github.com/duckdb/duckdb-python | ||
|
|
||
| extra: | ||
| recipe-maintainers: | ||
| - wolfv | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import duckdb | ||
|
|
||
|
|
||
| def test_import(): | ||
| assert duckdb is not None | ||
|
|
||
|
|
||
| def test_basic_query(): | ||
| con = duckdb.connect() | ||
| result = con.execute("SELECT 42 AS answer").fetchall() | ||
| assert result == [(42,)] | ||
|
|
||
|
|
||
| def test_create_table(): | ||
| con = duckdb.connect() | ||
| con.execute("CREATE TABLE t (x INTEGER, y VARCHAR)") | ||
| con.execute("INSERT INTO t VALUES (1, 'hello'), (2, 'world')") | ||
| result = con.execute("SELECT * FROM t ORDER BY x").fetchall() | ||
| assert result == [(1, "hello"), (2, "world")] | ||
|
|
||
|
|
||
| def test_aggregation(): | ||
| con = duckdb.connect() | ||
| con.execute("CREATE TABLE nums AS SELECT * FROM range(10) t(i)") | ||
| result = con.execute("SELECT SUM(i), COUNT(*) FROM nums").fetchone() | ||
| assert result == (45, 10) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you allow
--experimental, this would work and "pin" the tag to a commit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do allow experimental for a couple of recipes, you could add this package too
recipes/emci/rattler_build.py
Lines 19 to 20 in 2e05d5e