Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add a stub Rust crate #12595

Merged
merged 189 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
178d866
Add a stub Rust crate
erikjohnston Apr 29, 2022
09bc570
Ignore the .so lib
erikjohnston Apr 29, 2022
b4f8dcd
Add explicit setuptools_rust dep
erikjohnston Aug 18, 2022
e9a887e
Merge remote-tracking branch 'origin/develop' into erikj/rust_app
erikjohnston Aug 18, 2022
6f7d07c
Fix lock file
erikjohnston Aug 18, 2022
9e50d78
Use poetry build
erikjohnston Aug 18, 2022
7c6c3fc
Fix type hints
erikjohnston Aug 18, 2022
fb841d4
Fix debian packaging
erikjohnston Aug 18, 2022
7ae6651
Newsfile
erikjohnston Aug 18, 2022
d1216ff
Make a workspace
erikjohnston Aug 18, 2022
d29b599
Add rust to docker build deps
erikjohnston Aug 18, 2022
0ce8a1d
Use recent poetry
erikjohnston Aug 23, 2022
bc119dd
Install rust toolchains
erikjohnston Aug 24, 2022
1036994
Set toolchain
erikjohnston Aug 24, 2022
0c21782
Move setuptools_rust to main dep
erikjohnston Aug 24, 2022
7f3924b
Fix complement
erikjohnston Aug 25, 2022
6bf07a5
Fix up Dockerfile-dhvirtualenv
erikjohnston Aug 25, 2022
18f9052
Lock file
erikjohnston Aug 25, 2022
4f868cf
Fix trial-olddeps
erikjohnston Aug 25, 2022
792da37
Use poetry 1.2.0rc1 in docker
erikjohnston Aug 25, 2022
d268681
Drop explicit setuptools dep
erikjohnston Aug 25, 2022
88bd752
Reinstate setuptools explicit dependency
erikjohnston Aug 25, 2022
77088ab
Update deprecation policy
erikjohnston Aug 30, 2022
176a3c9
Bump poetry version in trial-olddeps
erikjohnston Aug 30, 2022
fcf4b4e
Merge remote-tracking branch 'origin/develop' into erikj/rust_app
erikjohnston Aug 30, 2022
a7721b5
Bump poetry to 1.2.0rc2
erikjohnston Aug 30, 2022
2fe560a
Bump bcrypt to 3.2.0 to make it work with new poetry
erikjohnston Aug 30, 2022
bbb13b6
Define a minimum version of Rust
erikjohnston Aug 30, 2022
8befab2
Bump lock file
erikjohnston Aug 30, 2022
73c9af9
Fix lockfile
erikjohnston Aug 30, 2022
58cc839
fix lockfile take2
erikjohnston Aug 30, 2022
d84eade
Bump setuptools
erikjohnston Aug 30, 2022
fce0ea8
Restore deps
erikjohnston Aug 30, 2022
70d860c
Lock??
erikjohnston Aug 30, 2022
3e72a1c
Lock???
erikjohnston Aug 30, 2022
6564423
Revert changes to lock file?
erikjohnston Aug 30, 2022
d632a40
Remove spurious setting of python-version
erikjohnston Aug 30, 2022
017176a
Upgrade setuptools
erikjohnston Aug 30, 2022
2177d3f
Fix updating setuptools
erikjohnston Aug 30, 2022
1ebd913
Fix complement docker
erikjohnston Aug 30, 2022
1df9d07
Merge remote-tracking branch 'origin/develop' into erikj/rust_app
erikjohnston Aug 30, 2022
fa0c98d
Try reverting back to using python -m build
erikjohnston Aug 31, 2022
fc02d33
Remove explicit dep on setuptools
erikjohnston Aug 31, 2022
9df5d41
More wheels
erikjohnston Aug 31, 2022
edbc9ea
Fix release gha
erikjohnston Aug 31, 2022
2f4e01b
Fix release gha
erikjohnston Aug 31, 2022
c8b9209
Fix release gha
erikjohnston Aug 31, 2022
7073bee
Fix release gha
erikjohnston Aug 31, 2022
66e0568
Fix release gha
erikjohnston Aug 31, 2022
e78aeba
Fix release gha
erikjohnston Aug 31, 2022
ef1b7e2
Fix release gha
erikjohnston Aug 31, 2022
fa36b74
Fix release gha
erikjohnston Aug 31, 2022
6f28d8e
Fix release gha
erikjohnston Aug 31, 2022
bf3e845
Fix release gha
erikjohnston Aug 31, 2022
ae3ef4c
Fix release gha
erikjohnston Aug 31, 2022
171d0b0
Fix release gha
erikjohnston Aug 31, 2022
5b21216
Fix rust-version
erikjohnston Aug 31, 2022
24deebc
Fix release gha
erikjohnston Aug 31, 2022
5e44342
Fix release gha
erikjohnston Aug 31, 2022
1e5056c
Fix release gha
erikjohnston Aug 31, 2022
673d14d
Try using cibuildwheel
erikjohnston Aug 31, 2022
025953e
Fix release gha
erikjohnston Aug 31, 2022
fc899fc
Fix release gha
erikjohnston Aug 31, 2022
334ab75
Fix release gha
erikjohnston Aug 31, 2022
4aa84fe
Fix release gha
erikjohnston Aug 31, 2022
bb753a1
Fix release gha
erikjohnston Aug 31, 2022
571470c
Fix release gha
erikjohnston Aug 31, 2022
a0673ac
Fix release gha
erikjohnston Aug 31, 2022
d5af3e5
Fix release gha
erikjohnston Aug 31, 2022
72ab0c4
Fix release gha
erikjohnston Aug 31, 2022
717b8b4
Fix release gha
erikjohnston Aug 31, 2022
3573887
Fix release gha
erikjohnston Aug 31, 2022
d2796b2
Fix release gha
erikjohnston Aug 31, 2022
19d0a2a
Add back in setuptools to lock file
erikjohnston Aug 31, 2022
b39669b
Revert "Add back in setuptools to lock file"
erikjohnston Aug 31, 2022
1e04a3c
Try building more wheels
erikjohnston Aug 31, 2022
0577408
Fix debian package
erikjohnston Aug 31, 2022
03c6fa2
Add verbose flag
erikjohnston Aug 31, 2022
2c17042
Fix release gha
erikjohnston Aug 31, 2022
60461d4
Fix release gha
erikjohnston Aug 31, 2022
5da41e6
Fix release gha
erikjohnston Aug 31, 2022
85e85c2
Fix release gha
erikjohnston Aug 31, 2022
1ed7322
Fix release gha
erikjohnston Aug 31, 2022
6a06805
Debian newsfile
erikjohnston Aug 31, 2022
871caa4
Fix release gha
erikjohnston Aug 31, 2022
11b0ded
Fix release gha
erikjohnston Aug 31, 2022
68d63b5
Fix release gha
erikjohnston Aug 31, 2022
93fd366
Fix release gha
erikjohnston Aug 31, 2022
6283b47
Fix debian?
erikjohnston Aug 31, 2022
830b061
Fix debian?
erikjohnston Aug 31, 2022
4785cfe
Fix releases
erikjohnston Aug 31, 2022
b8a291e
Fix releases
erikjohnston Aug 31, 2022
2b81696
Fix releases
erikjohnston Aug 31, 2022
519cc2c
Release
erikjohnston Aug 31, 2022
08c464b
Try fully updating lockfile
erikjohnston Sep 1, 2022
f2a8668
Add notes about needing a rust compiler
erikjohnston Sep 1, 2022
48186b3
Use stable poetry
erikjohnston Sep 1, 2022
aa5bb1c
Update pyproject
erikjohnston Sep 1, 2022
bfeab18
Remove unused build wheels scripts
erikjohnston Sep 1, 2022
349bb96
Use latest poetry in sytest?
erikjohnston Sep 1, 2022
bdfec46
Don't overwrite poetry
erikjohnston Sep 1, 2022
54894b5
Update lock file for Poetry v1.2.0
erikjohnston Sep 1, 2022
680681d
Newsfile
erikjohnston Sep 1, 2022
40c8f9c
Merge branch 'develop' into erikj/update_poetry_lock
erikjohnston Sep 1, 2022
1a275b4
Doc that min version of poetry is 1.2
erikjohnston Sep 1, 2022
00fcc83
Merge remote-tracking branch 'origin/develop' into erikj/update_poetr…
erikjohnston Sep 1, 2022
6ff918b
Forgot to save this file...
erikjohnston Sep 1, 2022
3c19a48
Merge remote-tracking branch 'origin/develop' into erikj/update_poetr…
erikjohnston Sep 1, 2022
2126cf7
Merge branch 'erikj/update_poetry_lock' into erikj/rust_app
erikjohnston Sep 1, 2022
479a595
Fix lock file
erikjohnston Sep 2, 2022
60bbd62
Update trial old deps CI to use poetry 1.2.0
erikjohnston Sep 2, 2022
eddf98e
Newsfile
erikjohnston Sep 2, 2022
ac7269d
Also build source package
erikjohnston Sep 2, 2022
1b504aa
Move cbuildwheel configuration to pyproject.toml
erikjohnston Sep 2, 2022
96c7cdb
Merge branch 'develop' into erikj/old_deps
erikjohnston Sep 2, 2022
c74a7af
Fix?
erikjohnston Sep 2, 2022
20f90b1
Try rejigging old-deps
erikjohnston Sep 2, 2022
d5234f7
Fix?
erikjohnston Sep 2, 2022
3953ab0
fix
erikjohnston Sep 2, 2022
19279b4
Fix??
erikjohnston Sep 2, 2022
bff7fb4
FIX ONESEFLF!!!
erikjohnston Sep 2, 2022
22ea18b
JUST RUN
erikjohnston Sep 2, 2022
70f3ffd
:(
erikjohnston Sep 2, 2022
4604d51
Make it work with maturin
erikjohnston Sep 5, 2022
646e4b0
Limit to ABI3
erikjohnston Sep 5, 2022
ca584b4
Merge branch 'develop' into erikj/old_deps
erikjohnston Sep 5, 2022
86248cf
Add some debugging
erikjohnston Sep 5, 2022
0359401
More debugging details
erikjohnston Sep 5, 2022
1c25715
Try py3.8
erikjohnston Sep 5, 2022
1818f14
Try shelling out
erikjohnston Sep 5, 2022
7c5d4ad
Activate virtual env
erikjohnston Sep 5, 2022
f62405a
Fix?
erikjohnston Sep 5, 2022
24360df
Try the shell again
erikjohnston Sep 5, 2022
e11f2ba
Try just activating the virtualenv
erikjohnston Sep 5, 2022
6225fd5
try uninstall tests
erikjohnston Sep 5, 2022
362ab60
More debugging
erikjohnston Sep 5, 2022
74b015e
Add some caching
erikjohnston Sep 5, 2022
eae0143
Add current directory to path
erikjohnston Sep 5, 2022
dbdb3b0
Try single job
erikjohnston Sep 5, 2022
435342d
Try
erikjohnston Sep 5, 2022
77eada8
Try a different tack
erikjohnston Sep 5, 2022
702818a
Add and populate cache
erikjohnston Sep 5, 2022
f5b21f3
Re-enable tests
erikjohnston Sep 5, 2022
96b8bb0
Update cache
erikjohnston Sep 5, 2022
54d4a10
Fix
erikjohnston Sep 5, 2022
bb2a6df
Run tests
erikjohnston Sep 5, 2022
c9acee4
Install build deps
erikjohnston Sep 5, 2022
9353e82
Update deps
erikjohnston Sep 5, 2022
e829e94
list bcrypt files
erikjohnston Sep 5, 2022
25cf13f
Try manually installing bcrypt
erikjohnston Sep 5, 2022
7f47134
Reinstall bcrypt
erikjohnston Sep 5, 2022
4fe4bc4
fix
erikjohnston Sep 5, 2022
5205d05
Install all deps
erikjohnston Sep 5, 2022
fb1364d
Install all deps
erikjohnston Sep 5, 2022
737a827
Install test deps too
erikjohnston Sep 5, 2022
f4b582d
Try not reinstalling bcrypt
erikjohnston Sep 5, 2022
4756c35
Make it ready for review
erikjohnston Sep 5, 2022
12378a3
Merge remote-tracking branch 'origin/erikj/old_deps' into erikj/rust_app
erikjohnston Sep 5, 2022
e407242
install rust
erikjohnston Sep 5, 2022
b401fe1
Mention maturin
erikjohnston Sep 5, 2022
de3af72
Set minimum rust version to 1.61
erikjohnston Sep 6, 2022
38c1019
Revert bcrypt change
erikjohnston Sep 6, 2022
d9f3ff5
Docstrings
erikjohnston Sep 6, 2022
d39dba2
Remove python-source directive
erikjohnston Sep 6, 2022
aa216fc
Rename build_wheels
erikjohnston Sep 6, 2022
45864b8
Fix contributing guide?
erikjohnston Sep 6, 2022
0687d7f
Remove unneeded setuptools upgrade
erikjohnston Sep 6, 2022
53bbe54
Don't build all the wheels on PR CI
erikjohnston Sep 6, 2022
f6f3d4f
Apply suggestions from code review
erikjohnston Sep 6, 2022
c32cc41
Merge remote-tracking branch 'origin/develop' into erikj/rust_app
erikjohnston Sep 6, 2022
0eb1aa7
Fix release-artifacts?
erikjohnston Sep 6, 2022
2a8e23d
Fix poetry.lock
erikjohnston Sep 6, 2022
88edb96
Temporarily reduce jobs from trial-olddeps for debugging
erikjohnston Sep 6, 2022
0b833c2
Bump minimum bcrypt to see if that compiles
erikjohnston Sep 6, 2022
1c7929d
Update wording
erikjohnston Sep 6, 2022
5eab0cd
Merge remote-tracking branch 'origin/develop' into erikj/rust_app
erikjohnston Sep 6, 2022
62847c5
Apply suggestions from code review
erikjohnston Sep 6, 2022
2cad84d
Fix up line wrapping
erikjohnston Sep 6, 2022
a4574b7
Fix release-artifact.yml
erikjohnston Sep 6, 2022
4925f6f
Move sdist to separate step
erikjohnston Sep 6, 2022
5a5fb3d
Fix release-artifact.yml
erikjohnston Sep 6, 2022
641ed32
Code review
erikjohnston Sep 6, 2022
1a601fa
Use a specific rustc version in tests
erikjohnston Sep 6, 2022
fa8f079
Add typing
erikjohnston Sep 6, 2022
bbd3d09
Temporarily always build sdist
erikjohnston Sep 6, 2022
43e38a9
Fix sdist
erikjohnston Sep 6, 2022
fa57b03
Fix sdist
erikjohnston Sep 6, 2022
bc8f80a
Fix sdist warning
erikjohnston Sep 6, 2022
19c6a5f
Only build sdist on non-PRs CI
erikjohnston Sep 6, 2022
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
31 changes: 29 additions & 2 deletions .github/workflows/release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write

Expand Down Expand Up @@ -91,7 +91,34 @@ jobs:

build-sdist:
name: "Build pypi distribution files"
uses: "matrix-org/backend-meta/.github/workflows/packaging.yml@v1"
steps:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should whatever changed here be folded back into the backend-meta repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yup, probably. The change is using poetry build rather than pip build

- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2

- name: Install tools
run: python -m pip install build twine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need build here, if we're using poetry build instead.

No objections to using poetry build instead of python -m build in the backend meta repo. (It should hopefully be equivalent anyway---I think build should invoke poetry-core via pyproject.toml?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason python -m build wasn't installing the build deps iirc?


- name: Build wheel and sdist
run: poetry build

# This checks that the "long description" fields renders correctly on PyPI.
# We don't upload to PyPI, but the two steps below only upload artifacts to GitHub.
- name: Run twine check
run: python -m twine check dist/*

- uses: actions/upload-artifact@v2
with:
name: Wheel
path: dist/*.whl

- uses: actions/upload-artifact@v2
with:
name: Sdist
path: dist/*.tar.gz


# if it's a tag, create a release and attach the artifacts to it
attach-assets:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ book/
# complement
/complement-*
/master.tar.gz

# rust
/target/
/synapse/*.so
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we care about ... dylibs? dlls? Whatever those other OS people do :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably I guess? Though do we support other OSes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @clokep is on Mac at least. Perhaps he can comment about what that looks like over there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm on macOS (and others who occasionally contribute to Synapse use macOS too) -- are you mostly just hoping I run this and make sure it doesn't break / what other files we might need to ignore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, pretty much

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On macOS this did seem to only generate a .so file, but it was under the build/ directory. This was when installing an editable install via pip, so might be OK if you use poetry?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/build/ is ignored separately fwiw, so thats fine.


# Poetry will create a setup.py, which we don't want to include.
/setup.py
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# We make the whole Synapse folder a workspace so that we can run `cargo`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No corresponding Cargo.lock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point!

# commands from the root (rather than having to cd into rust/).

[workspace]
members = ["rust"]
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# A build script for poetry that adds the rust extension.

import os

from setuptools_rust import Binding, RustExtension


def build(setup_kwargs):
original_project_dir = os.path.dirname(os.path.realpath(__file__))
cargo_toml_path = os.path.join(original_project_dir, "rust", "Cargo.toml")

extension = RustExtension(
target="synapse.synapse_rust", path=cargo_toml_path, binding=Binding.PyO3
)
setup_kwargs.setdefault("rust_extensions", []).append(extension)
setup_kwargs["zip_safe"] = False
1 change: 1 addition & 0 deletions changelog.d/12595.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a stub Rust crate.
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ RUN \
rustc \
zlib1g-dev \
git \
rustc cargo \
&& rm -rf /var/lib/apt/lists/*

# To speed up rebuilds, install all of the dependencies before we copy over
Expand Down
41 changes: 21 additions & 20 deletions docker/Dockerfile-dhvirtualenv
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ FROM ${distro} as builder

RUN apt-get update -qq -o Acquire::Languages=none
RUN env DEBIAN_FRONTEND=noninteractive apt-get install \
-yqq --no-install-recommends \
build-essential \
ca-certificates \
devscripts \
equivs \
wget
-yqq --no-install-recommends \
build-essential \
ca-certificates \
devscripts \
equivs \
wget

# fetch and unpack the package
RUN mkdir /dh-virtualenv
Expand Down Expand Up @@ -70,20 +70,21 @@ ENV LANG C.UTF-8
# TODO: it would be nice to do that automatically.
RUN apt-get update -qq -o Acquire::Languages=none \
&& env DEBIAN_FRONTEND=noninteractive apt-get install \
-yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \
build-essential \
debhelper \
devscripts \
libsystemd-dev \
lsb-release \
pkg-config \
python3-dev \
python3-pip \
python3-setuptools \
python3-venv \
sqlite3 \
libpq-dev \
xmlsec1
-yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \
build-essential \
debhelper \
devscripts \
libsystemd-dev \
lsb-release \
pkg-config \
python3-dev \
python3-pip \
python3-setuptools \
python3-venv \
sqlite3 \
libpq-dev \
xmlsec1 \
rustc cargo

COPY --from=builder /dh-virtualenv_1.2.2-1_all.deb /

Expand Down
123 changes: 42 additions & 81 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ include = [
{ path = "sytest-blacklist", format = "sdist" },
{ path = "tests", format = "sdist" },
{ path = "UPGRADE.rst", format = "sdist" },
{ path = "rust/Cargo.toml", format = "sdist" },
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
{ path = "rust/Cargo.lock", format = "sdist" },
{ path = "rust/src/**", format = "sdist" },
]

build = "build.py"

[tool.poetry.scripts]
synapse_homeserver = "synapse.app.homeserver:main"
synapse_worker = "synapse.app.generic_worker:main"
Expand Down Expand Up @@ -284,6 +289,17 @@ twine = "*"
# Towncrier min version comes from #3425. Rationale unclear.
towncrier = ">=18.6.0rc1"

# This is for building the rust components during "poetry install", which
# currently ignores the `build-system.requires` directive (c.f.
# https://github.com/python-poetry/poetry/issues/6154). Both `pip install` and
# `poetry build` do the right thing without this explicit dependency.
#
# This isn't really a dev-dependency, as `poetry install --no-dev` will fail,
# but the alternative is to add it to the main list of deps where it isn't
# needed.
setuptools_rust = ">=1.3"
setuptools = ">=62.4"

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core>=1.0.0", "setuptools_rust>=1.3"]
build-backend = "poetry.core.masonry.api"
11 changes: 11 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "synapse-rust"
version = "0.1.0"
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
edition = "2021"

[lib]
name = "synapse_rust"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.16.5", features = ["extension-module", "macros"] }
17 changes: 17 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use pyo3::prelude::*;
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved

/// Formats the sum of two numbers as string.
#[pyfunction]
#[pyo3(text_signature = "(a, b, /)")]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}

/// A Python module implemented in Rust. The name of this function must match
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
/// import the module.
#[pymodule]
fn synapse_rust(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
Ok(())
}
7 changes: 7 additions & 0 deletions scripts-dev/build_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -ex

cd $(dirname "$0")/..

docker run --rm -it -v $( pwd ):/io quay.io/pypa/manylinux2014_x86_64 bash /io/scripts-dev/build_wheels_inner.sh
33 changes: 33 additions & 0 deletions scripts-dev/build_wheels_inner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Builds wheels when run in a manylinux container

set -ex

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
export PATH="$HOME/.cargo/bin:$PATH"

# Compile wheels
for PYBIN in /opt/python/cp{37,38,39,310}*/bin; do
rm -rf /io/build/

# Until https://github.com/python-poetry/poetry/pull/5401 lands we need to
# manually install setuptools_rust
rm -rf /tmp/venv
"${PYBIN}/python" -m venv /tmp/venv
source /tmp/venv/bin/activate

pip install -U poetry setuptools_rust
cd /io
poetry build -f wheel
done

# Bundle external shared libraries into the wheels
for whl in /io/dist/*{cp37,cp38,cp39,cp310}*.whl; do
auditwheel repair "$whl" -w /io/dist/
done

# Install packages and test
for PYBIN in /opt/python/cp{37,38,39,310}*/bin; do
"${PYBIN}/pip" install synapse -f /io/dist/
done
Empty file added stubs/synapse/__init__.pyi
Empty file.
1 change: 1 addition & 0 deletions stubs/synapse/synapse_rust.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def sum_as_string(a: int, b: int) -> str: ...
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions tests/test_rust.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from tests import unittest
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved


class RustTestCase(unittest.TestCase):
def test_basic(self):
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
from synapse.synapse_rust import sum_as_string

result = sum_as_string(1, 2)
self.assertEqual("3", result)