-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a stub Rust crate #12595
Add a stub Rust crate #12595
Changes from 11 commits
178d866
09bc570
b4f8dcd
e9a887e
6f7d07c
9e50d78
7c6c3fc
fb841d4
7ae6651
d1216ff
d29b599
0ce8a1d
bc119dd
1036994
0c21782
7f3924b
6bf07a5
18f9052
4f868cf
792da37
d268681
88bd752
77088ab
176a3c9
fcf4b4e
a7721b5
2fe560a
bbb13b6
8befab2
73c9af9
58cc839
d84eade
fce0ea8
70d860c
3e72a1c
6564423
d632a40
017176a
2177d3f
1ebd913
1df9d07
fa0c98d
fc02d33
9df5d41
edbc9ea
2f4e01b
c8b9209
7073bee
66e0568
e78aeba
ef1b7e2
fa36b74
6f28d8e
bf3e845
ae3ef4c
171d0b0
5b21216
24deebc
5e44342
1e5056c
673d14d
025953e
fc899fc
334ab75
4aa84fe
bb753a1
571470c
a0673ac
d5af3e5
72ab0c4
717b8b4
3573887
d2796b2
19d0a2a
b39669b
1e04a3c
0577408
03c6fa2
2c17042
60461d4
5da41e6
85e85c2
1ed7322
6a06805
871caa4
11b0ded
68d63b5
93fd366
6283b47
830b061
4785cfe
b8a291e
2b81696
519cc2c
08c464b
f2a8668
48186b3
aa5bb1c
bfeab18
349bb96
bdfec46
54894b5
680681d
40c8f9c
1a275b4
00fcc83
6ff918b
3c19a48
2126cf7
479a595
60bbd62
eddf98e
ac7269d
1b504aa
96c7cdb
c74a7af
20f90b1
d5234f7
3953ab0
19279b4
bff7fb4
22ea18b
70f3ffd
4604d51
646e4b0
ca584b4
86248cf
0359401
1c25715
1818f14
7c5d4ad
f62405a
24360df
e11f2ba
6225fd5
362ab60
74b015e
eae0143
dbdb3b0
435342d
77eada8
702818a
f5b21f3
96b8bb0
54d4a10
bb2a6df
c9acee4
9353e82
e829e94
25cf13f
7f47134
4fe4bc4
5205d05
fb1364d
737a827
f4b582d
4756c35
12378a3
e407242
b401fe1
de3af72
38c1019
d9f3ff5
d39dba2
aa216fc
45864b8
0687d7f
53bbe54
f6f3d4f
c32cc41
0eb1aa7
2a8e23d
88edb96
0b833c2
1c7929d
5eab0cd
62847c5
2cad84d
a4574b7
4925f6f
5a5fb3d
641ed32
1a601fa
fa8f079
bbd3d09
43e38a9
fa57b03
bc8f80a
19c6a5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ on: | |
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: write | ||
|
||
|
@@ -91,7 +91,34 @@ jobs: | |
|
||
build-sdist: | ||
name: "Build pypi distribution files" | ||
uses: "matrix-org/backend-meta/.github/workflows/packaging.yml@v1" | ||
steps: | ||
- 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need No objections to using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For whatever reason |
||
|
||
- 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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,10 @@ book/ | |
# complement | ||
/complement-* | ||
/master.tar.gz | ||
|
||
# rust | ||
/target/ | ||
/synapse/*.so | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we care about ... dylibs? dlls? Whatever those other OS people do :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, probably I guess? Though do we support other OSes? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, pretty much There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On macOS this did seem to only generate a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Poetry will create a setup.py, which we don't want to include. | ||
/setup.py |
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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No corresponding There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a stub Rust crate. |
Large diffs are not rendered by default.
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"] } |
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(()) | ||
} |
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 |
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 |
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
|
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) |
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.
should whatever changed here be folded back into the backend-meta repo?
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.
Ah yup, probably. The change is using
poetry build
rather thanpip build