Skip to content

Commit 7de2c20

Browse files
maxwellflittontsunyokutsunyokuCaedenPHMaoMaoCake
authored
Rust remove tokio (#76)
Co-authored-by: James <tsunyoku@gmail.com> Co-authored-by: tsunyoku <mbruhyo@gmail.com> Co-authored-by: Caeden <caedenperelliharris@gmail.com> Co-authored-by: Jirapong Pansak <55589246+MaoMaoCake@users.noreply.github.com> Co-authored-by: Tobie Morgan Hitchcock <tobie@abcum.com> Co-authored-by: Fábio Tramasoli <fabio@tramasoli.com> Co-authored-by: Joel <jyooru+github@protonmail.ch> Co-authored-by: Tudor Andrei Dumitrascu <TudorAndrei@users.noreply.github.com> Co-authored-by: Sam Kenney <83219365+sam-kenney@users.noreply.github.com> Co-authored-by: FrostyTheSouthernSnowman <92753960+FrostyTheSouthernSnowman@users.noreply.github.com> Co-authored-by: Grzegorz Koperwas <grzes869@gmail.com> Co-authored-by: Cellan Hall <60790416+Ce11an@users.noreply.github.com> Co-authored-by: Alexander <post@alexanderfridriksson.com> Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com> Co-authored-by: Alexander <post@alexanderfridiksson.com> Co-authored-by: Dimension <to.hitesh.gorana@gmail.com> Co-authored-by: Hitesh <hitesh.g@smarter.codes> Co-authored-by: Tudor Andrei Dumitrascu <107496172+TudorAndrei-Pythia@users.noreply.github.com>
1 parent 89bdd36 commit 7de2c20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+6120
-226
lines changed

.cargo/config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.x86_64-apple-darwin]
2+
rustflags = [
3+
"-C", "link-arg=-undefined",
4+
"-C", "link-arg=dynamic_lookup",
5+
]
6+
7+
[target.aarch64-apple-darwin]
8+
rustflags = [
9+
"-C", "link-arg=-undefined",
10+
"-C", "link-arg=dynamic_lookup",
11+
]

.github/workflows/cross_build.yml

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
name: cross-build
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
14+
wait-for-other-workflow:
15+
name: Wait for Other Workflow
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Wait for Other Workflow to Complete
19+
run: "echo 'Waiting for other workflow to complete...'"
20+
21+
build: # Workflow credit to https://github.com/samuelcolvin/rtoml/blob/main/.github/workflows/ci.yml
22+
if: github.event.pull_request.merged == true
23+
name: >
24+
build ${{ matrix.python-version }} on ${{ matrix.platform || matrix.os }}
25+
(${{ matrix.alt_arch_name || matrix.arch }})
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
os: [ubuntu, macos, windows]
30+
python-version: ["cp310", "pp37", "pp38", "pp39"]
31+
arch: [main, alt]
32+
include:
33+
- os: ubuntu
34+
platform: linux
35+
- os: windows
36+
ls: dir
37+
- os: macos
38+
arch: alt
39+
alt_arch_name: "arm64 universal2"
40+
exclude:
41+
- os: macos
42+
python-version: "pp37"
43+
arch: alt
44+
- os: macos
45+
python-version: "pp38"
46+
arch: alt
47+
- os: macos
48+
python-version: "pp39"
49+
arch: alt
50+
runs-on: ${{ format('{0}-latest', matrix.os) }}
51+
steps:
52+
- uses: actions/checkout@v3
53+
54+
- name: set up python
55+
uses: actions/setup-python@v4
56+
with:
57+
python-version: "3.9"
58+
59+
- name: set up rust
60+
uses: dtolnay/rust-toolchain@stable
61+
with:
62+
toolchain: stable
63+
64+
- name: update pip version
65+
run: |
66+
pip install requests
67+
python get_latest_version.py
68+
69+
- name: Setup Rust cache
70+
uses: Swatinem/rust-cache@v2
71+
with:
72+
key: ${{ matrix.alt_arch_name }}
73+
74+
- run: rustup target add aarch64-apple-darwin
75+
if: matrix.os == 'macos'
76+
77+
- run: rustup toolchain install stable-i686-pc-windows-msvc
78+
if: matrix.os == 'windows'
79+
80+
- run: rustup target add i686-pc-windows-msvc
81+
if: matrix.os == 'windows'
82+
83+
- name: Get pip cache dir
84+
id: pip-cache
85+
if: matrix.os != 'windows'
86+
run: |
87+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
88+
89+
- name: Get pip cache dir
90+
id: pip-cache-win
91+
if: matrix.os == 'windows'
92+
run: |
93+
"dir=$(pip cache dir)" >> $env:GITHUB_OUTPUT
94+
95+
- name: Cache python dependencies
96+
uses: actions/cache@v3
97+
with:
98+
path: ${{ steps.pip-cache.outputs.dir || steps.pip-cache-win.outputs.dir }}
99+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}
100+
101+
- name: install python dependencies
102+
run: pip install -U setuptools wheel twine cibuildwheel platformdirs
103+
104+
- name: Display cibuildwheel cache dir
105+
id: cibuildwheel-cache
106+
run: |
107+
from platformdirs import user_cache_path
108+
import os
109+
with open(os.getenv('GITHUB_OUTPUT'), 'w') as f:
110+
f.write(f"dir={str(user_cache_path(appname='cibuildwheel', appauthor='pypa'))}")
111+
shell: python
112+
113+
- name: Cache cibuildwheel tools
114+
uses: actions/cache@v3
115+
with:
116+
path: ${{ steps.cibuildwheel-cache.outputs.dir }}
117+
key: ${{ runner.os }}-cibuildwheel-${{ matrix.python-version }}
118+
119+
- name: Install LLVM and Clang # required for bindgen to work, see https://github.com/rust-lang/rust-bindgen/issues/1797
120+
uses: KyleMayes/install-llvm-action@v1
121+
if: runner.os == 'Windows'
122+
with:
123+
version: "11.0"
124+
directory: ${{ runner.temp }}/llvm
125+
126+
- name: Set LIBCLANG_PATH
127+
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
128+
if: runner.os == 'Windows'
129+
130+
- name: build_sdist
131+
if: matrix.os == 'ubuntu' && matrix.python-version == 'cp310'
132+
run: |
133+
pip install maturin build
134+
python -m build --sdist -o wheelhouse
135+
- name: build ${{ matrix.platform || matrix.os }} binaries
136+
run: cibuildwheel --output-dir wheelhouse
137+
env:
138+
CIBW_BUILD: "${{ matrix.python-version }}-*"
139+
# rust doesn't seem to be available for musl linux on i686
140+
CIBW_SKIP: "*-musllinux_i686"
141+
# we build for "alt_arch_name" if it exists, else 'auto'
142+
CIBW_ARCHS: ${{ matrix.alt_arch_name || 'auto' }}
143+
CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH" CARGO_TERM_COLOR="always"'
144+
CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$PATH"'
145+
CIBW_BEFORE_BUILD: rustup show
146+
CIBW_BEFORE_BUILD_LINUX: >
147+
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y &&
148+
rustup show
149+
CIBW_BUILD_VERBOSITY: 1
150+
151+
- run: ${{ matrix.ls || 'ls -lh' }} wheelhouse/
152+
153+
- uses: actions/upload-artifact@v3
154+
with:
155+
name: wheels
156+
path: wheelhouse
157+
158+
release:
159+
if: github.event.pull_request.merged == true
160+
needs: build
161+
runs-on: ubuntu-latest
162+
steps:
163+
- uses: actions/download-artifact@v2
164+
with:
165+
name: wheels
166+
path: wheelhouse
167+
168+
- name: Install twine
169+
run: python -m pip install --upgrade twine
170+
171+
- name: Create pypirc file
172+
run: |
173+
echo "[distutils]" > ~/.pypirc
174+
echo "index-servers =" >> ~/.pypirc
175+
echo " pypi" >> ~/.pypirc
176+
echo "" >> ~/.pypirc
177+
echo "[pypi]" >> ~/.pypirc
178+
echo "username: __token__" >> ~/.pypirc
179+
echo "password: \${{ secrets.PYPI_TOKEN }}" >> ~/.pypirc
180+
env:
181+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
182+
183+
- name: Publish to PyPI
184+
run: twine upload wheelhouse/*
185+
env:
186+
TWINE_USERNAME: __token__
187+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

.github/workflows/stability.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ jobs:
2727

2828
- id: ruff
2929
if: always()
30+
<<<<<<< HEAD
31+
run: poetry run ruff --format=github python_package/surrealdb/
32+
33+
- id: Black
34+
if: always()
35+
run: poetry run black python_package/surrealdb/ --check --verbose --diff --color
36+
37+
- id: mypy
38+
if: always()
39+
run: poetry run mypy python_package/surrealdb/
40+
=======
3041
run: poetry run ruff check surrealdb/
3142

3243
- id: Black
@@ -36,3 +47,4 @@ jobs:
3647
- id: mypy
3748
if: always()
3849
run: poetry run mypy surrealdb/
50+
>>>>>>> 89bdd361d0a92f69deff137958279ab21161f00c

.github/workflows/unit_tests.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: unit-tests
2+
3+
on:
4+
pull_request:
5+
# push:
6+
branches:
7+
- "*"
8+
9+
jobs:
10+
run-unit-tests:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Build for tests
23+
run: |
24+
python tests/scripts/local_build_ci.py
25+
pip install docker
26+
pip install requests
27+
# docker-compose build
28+
# docker-compose up -d
29+
# sleep 2
30+
31+
- name: Run Tests
32+
run: sh scripts/run_tests.sh
33+
34+
run-rust-unit-tests:
35+
needs: run-unit-tests
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v2
40+
41+
- name: Set up Rust
42+
uses: actions-rs/toolchain@v1
43+
with:
44+
toolchain: stable
45+
46+
- name: Build and Run Unit Tests
47+
run: cargo test

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,28 @@ cover/
5757
.vscode/
5858
__pycache__/
5959
dist/
60+
build/
6061

6162
# -----------------------------------
6263
# IDE
6364
# -----------------------------------
6465
.idea/
66+
# -----------------------------------
67+
# Rust
68+
# -----------------------------------
69+
/target/
70+
Cargo.lock
71+
# -----------------------------------
72+
# Packaging
73+
# -----------------------------------
74+
*.egg-info/
75+
*.egg
76+
.eggs/
77+
*.so
78+
/build/
79+
# -----------------------------------
80+
# server tests
81+
# -----------------------------------
82+
integration_tests/flask/app/surreal.py/
83+
integration_tests/package-lock.json
84+
integration_tests/node_modules/

Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
name = "surrealdb"
3+
version = "0.1.0"
4+
authors = ["Maxwell Flitton <maxwellflitton@gmail.com>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
surrealdb = { version = "1.2.0", features = ["protocol-ws", "protocol-http", "kv-mem"] }
9+
serde = "^1.0.164"
10+
futures = { version="0.3.30", features = ["executor"] }
11+
once_cell = "1.19.0"
12+
serde_json = "^1.0.97"
13+
crossbeam-channel = "^0.5"
14+
thiserror = "^1.0.43"
15+
16+
[dev-dependencies]
17+
tokio = { version = "1.36.0", features = ["full"] }
18+
bollard = "*"
19+
futures-util-preview = "0.2.2"
20+
21+
[lib]
22+
name = "rust_surrealdb"
23+
crate-type=["cdylib"]
24+
25+
[dependencies.pyo3]
26+
version = "0.20.0"
27+
features = ["extension-module"]
28+
29+
[dependencies.pyo3-asyncio]
30+
version = "0.20"
31+
features = ["unstable-streams", "attributes", "tokio-runtime"]
32+
33+
[dependencies.uuid]
34+
version = "1.3.4"
35+
features = [
36+
"v4", # Lets you generate random UUIDs
37+
"fast-rng", # Use a faster (but still sufficiently random) RNG
38+
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
39+
]

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM ubuntu:latest
2+
3+
# Set the working directory
4+
WORKDIR /app
5+
6+
# Copy the source code
7+
COPY src /app/src
8+
9+
# Copy the .cargo directory
10+
COPY .cargo /app/.cargo
11+
12+
# Copy the surrealdb directory
13+
COPY surrealdb /app/surrealdb
14+
15+
# Copy the Cargo.toml file
16+
COPY Cargo.toml /app/Cargo.toml
17+
18+
# Copy the pyproject.toml file
19+
COPY pyproject.toml /app/pyproject.toml
20+
21+
# Copy the setup.py file
22+
COPY setup.py /app/setup.py
23+
24+
RUN apt update
25+
RUN apt install -y clang
26+
RUN apt-get install -y libclang-dev
27+
RUN apt install -y python3
28+
RUN apt install -y python3-pip
29+
RUN apt install -y curl
30+
RUN apt install -y vim
31+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
32+
RUN export PATH="$HOME/.cargo/bin:$PATH"
33+
RUN pip3 install setuptools_rust
34+
RUN python3 setup.py bdist_wheel
35+
36+
# docker build . -t package-test
37+
# docker run -d -p 18000:18000 package-test
38+
39+
EXPOSE 18000
40+
41+
CMD ["bash", "-c", "trap : TERM INT; sleep infinity & wait"]
42+

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
recursive-include surrealdb *.so
2+
recursive-include surrealdb *.txt

0 commit comments

Comments
 (0)