From f9f1775e63c430d711c2d3457f0424da75a8f85a Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 11:54:44 +0200 Subject: [PATCH 01/23] Setup CI to build wheels --- .github/workflows/python.yaml | 111 ++++++++++++++++++++++++++++++++++ synapse/Cargo.toml | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/python.yaml diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml new file mode 100644 index 0000000..b62d8b7 --- /dev/null +++ b/.github/workflows/python.yaml @@ -0,0 +1,111 @@ +name: Python + +on: + push: + branches: [ main ] + tags: + - "*" + pull_request: + +jobs: + build-wheels: + strategy: + matrix: + include: + - os: macos-latest + target: x86_64-macos-darwin + compatibility: ignored + + - os: macos-latest + target: aarch64-macos-darwin + compatibility: ignored + + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + compatibility: manylinux2014 + + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + compatibility: manylinux2014 + + - os: ubuntu-latest + target: aarch64-unknown-linux-musl + compatibility: musllinux_1_2 + + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + compatibility: musllinux_1_2 + + - os: windows-latest + target: x86_64-pc-windows-msvc + compatibility: ignored + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout the code + uses: actions/checkout@v3 + + - name: Install Python 3.7 + uses: actions/setup-python@v4 + id: cpy37 + with: + python-version: "3.7" + architecture: x64 + update-environment: false + + - name: Install Python 3.8 + uses: actions/setup-python@v4 + id: cpy38 + with: + python-version: "3.8" + architecture: x64 + update-environment: false + + - name: Install Python 3.9 + uses: actions/setup-python@v4 + id: cpy39 + with: + python-version: "3.9" + architecture: x64 + update-environment: false + + - name: Install Python 3.10 + uses: actions/setup-python@v4 + id: cpy310 + with: + python-version: "3.10" + architecture: x64 + update-environment: false + + - name: Setup Zig + uses: goto-bus-stop/setup-zig@v1 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + default: true + target: ${{ matrix.target }} + + - name: Install maturin + run: pip install maturin[zig] --user + + - name: Build wheels + run: | + maturin build \ + --release \ + --out dist \ + --manifest-path synapse/Cargo.toml \ + -i ${{ steps.cpy37.outputs.python-path }} \ + -i ${{ steps.cpy38.outputs.python-path }} \ + -i ${{ steps.cpy39.outputs.python-path }} \ + -i ${{ steps.cpy310.outputs.python-path }} \ + --compatibility ${{ matrix.compatibility }} \ + --zig + + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist diff --git a/synapse/Cargo.toml b/synapse/Cargo.toml index 32de06f..ebdb207 100644 --- a/synapse/Cargo.toml +++ b/synapse/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.65" http-body = "0.4.5" -pyo3 = { version = "0.17.2", features = ["extension-module", "anyhow"] } +pyo3 = { version = "0.17.2", features = ["extension-module", "abi3-py37", "anyhow"] } pyo3-log = "0.7.0" pyo3-matrix-synapse-module = "0.1.0" serde = { version = "1.0.145", features = ["derive"] } From 8e10fa3d268abc75632f2cf819b45e555d9bfbff Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 11:59:24 +0200 Subject: [PATCH 02/23] Fix apple darwin targets --- .github/workflows/python.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index b62d8b7..1600074 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -13,11 +13,11 @@ jobs: matrix: include: - os: macos-latest - target: x86_64-macos-darwin + target: x86_64-apple-darwin compatibility: ignored - os: macos-latest - target: aarch64-macos-darwin + target: aarch64-apple-darwin compatibility: ignored - os: ubuntu-latest From 207f96ea66350bc541842794d748886e4b4a3de2 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 12:01:51 +0200 Subject: [PATCH 03/23] Actually use Python 3.10 to run maturin --- .github/workflows/python.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 1600074..1225e25 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -75,7 +75,7 @@ jobs: with: python-version: "3.10" architecture: x64 - update-environment: false + update-environment: true - name: Setup Zig uses: goto-bus-stop/setup-zig@v1 From 983e5e8a95e47f8bcd752f8c3dbb653d7b3d19dd Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 12:17:49 +0200 Subject: [PATCH 04/23] Install maturin from GitHub releases --- .github/workflows/python.yaml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 1225e25..db53822 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -10,6 +10,7 @@ on: jobs: build-wheels: strategy: + fail-fast: false matrix: include: - os: macos-latest @@ -36,10 +37,6 @@ jobs: target: x86_64-unknown-linux-musl compatibility: musllinux_1_2 - - os: windows-latest - target: x86_64-pc-windows-msvc - compatibility: ignored - runs-on: ${{ matrix.os }} steps: - name: Checkout the code @@ -75,7 +72,21 @@ jobs: with: python-version: "3.10" architecture: x64 - update-environment: true + update-environment: false + + - name: Install maturin (macOS) + if: runner.os == 'macOS' + run: + mkdir -p "${HOME}/.local/bin" + curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-apple-darwin.tar.gz | tar jxf - -C "${HOME}/.local/bin" + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Install maturin (Linux) + if: runner.os == 'Linux' + run: + mkdir -p "${HOME}/.local/bin" + curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-unknown-linux-musl.tar.gz | tar jxf - -C "${HOME}/.local/bin" + echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Setup Zig uses: goto-bus-stop/setup-zig@v1 @@ -88,9 +99,6 @@ jobs: default: true target: ${{ matrix.target }} - - name: Install maturin - run: pip install maturin[zig] --user - - name: Build wheels run: | maturin build \ From 90d53014a22810d48a2921f7214f49cedb252b3e Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 12:18:39 +0200 Subject: [PATCH 05/23] Fix workflow syntax --- .github/workflows/python.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index db53822..95bb29a 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -76,14 +76,14 @@ jobs: - name: Install maturin (macOS) if: runner.os == 'macOS' - run: + run: | mkdir -p "${HOME}/.local/bin" curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-apple-darwin.tar.gz | tar jxf - -C "${HOME}/.local/bin" echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Install maturin (Linux) if: runner.os == 'Linux' - run: + run: | mkdir -p "${HOME}/.local/bin" curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-unknown-linux-musl.tar.gz | tar jxf - -C "${HOME}/.local/bin" echo "$HOME/.local/bin" >> $GITHUB_PATH From ac757ccda4404c6fa7fd96bfccd03ece01d0e331 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 12:19:17 +0200 Subject: [PATCH 06/23] Fix maturin unarchive --- .github/workflows/python.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 95bb29a..ea07a49 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -78,14 +78,14 @@ jobs: if: runner.os == 'macOS' run: | mkdir -p "${HOME}/.local/bin" - curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-apple-darwin.tar.gz | tar jxf - -C "${HOME}/.local/bin" + curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-apple-darwin.tar.gz | tar xzf - -C "${HOME}/.local/bin" echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Install maturin (Linux) if: runner.os == 'Linux' run: | mkdir -p "${HOME}/.local/bin" - curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-unknown-linux-musl.tar.gz | tar jxf - -C "${HOME}/.local/bin" + curl -sL https://github.com/PyO3/maturin/releases/download/v0.13.6/maturin-x86_64-unknown-linux-musl.tar.gz | tar xzf - -C "${HOME}/.local/bin" echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Setup Zig From 5e649004694714bc2b4645a6076b73a751b3bfcc Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 12:21:08 +0200 Subject: [PATCH 07/23] Pass a proper --compatibility flag to maturin on macOS --- .github/workflows/python.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index ea07a49..d6bc76f 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -15,11 +15,11 @@ jobs: include: - os: macos-latest target: x86_64-apple-darwin - compatibility: ignored + compatibility: manylinux2014 # Ignored on macOS - os: macos-latest target: aarch64-apple-darwin - compatibility: ignored + compatibility: manylinux2014 # Ignored on macOS - os: ubuntu-latest target: aarch64-unknown-linux-gnu From b33d27448112d5fd8a4ca58a157c201b560aefb8 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 12:24:48 +0200 Subject: [PATCH 08/23] Use zig v0.9.0 --- .github/workflows/python.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index d6bc76f..ae94405 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -90,6 +90,8 @@ jobs: - name: Setup Zig uses: goto-bus-stop/setup-zig@v1 + with: + version: 0.9.1 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 From d592926295eecbe88f9d852ad2fa1afc181145d0 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 12:32:08 +0200 Subject: [PATCH 09/23] Specify the right rust --target --- .github/workflows/python.yaml | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index ae94405..1152b0c 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -50,30 +50,6 @@ jobs: architecture: x64 update-environment: false - - name: Install Python 3.8 - uses: actions/setup-python@v4 - id: cpy38 - with: - python-version: "3.8" - architecture: x64 - update-environment: false - - - name: Install Python 3.9 - uses: actions/setup-python@v4 - id: cpy39 - with: - python-version: "3.9" - architecture: x64 - update-environment: false - - - name: Install Python 3.10 - uses: actions/setup-python@v4 - id: cpy310 - with: - python-version: "3.10" - architecture: x64 - update-environment: false - - name: Install maturin (macOS) if: runner.os == 'macOS' run: | @@ -108,10 +84,8 @@ jobs: --out dist \ --manifest-path synapse/Cargo.toml \ -i ${{ steps.cpy37.outputs.python-path }} \ - -i ${{ steps.cpy38.outputs.python-path }} \ - -i ${{ steps.cpy39.outputs.python-path }} \ - -i ${{ steps.cpy310.outputs.python-path }} \ --compatibility ${{ matrix.compatibility }} \ + --target ${{ matrix.target }} \ --zig - name: Upload wheels From fdd1546fbfb05ac52d74e78a7ce1f14920d81e25 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 13:24:49 +0200 Subject: [PATCH 10/23] Don't use python abi3, publish a wheel for each python version --- .github/workflows/python.yaml | 27 +++++++++++++++++++++++++++ synapse/Cargo.toml | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 1152b0c..2b8dbb8 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -50,6 +50,30 @@ jobs: architecture: x64 update-environment: false + - name: Install Python 3.8 + uses: actions/setup-python@v4 + id: cpy38 + with: + python-version: "3.8" + architecture: x64 + update-environment: false + + - name: Install Python 3.9 + uses: actions/setup-python@v4 + id: cpy39 + with: + python-version: "3.9" + architecture: x64 + update-environment: false + + - name: Install Python 3.10 + uses: actions/setup-python@v4 + id: cpy310 + with: + python-version: "3.10" + architecture: x64 + update-environment: false + - name: Install maturin (macOS) if: runner.os == 'macOS' run: | @@ -84,6 +108,9 @@ jobs: --out dist \ --manifest-path synapse/Cargo.toml \ -i ${{ steps.cpy37.outputs.python-path }} \ + -i ${{ steps.cpy38.outputs.python-path }} \ + -i ${{ steps.cpy39.outputs.python-path }} \ + -i ${{ steps.cpy310.outputs.python-path }} \ --compatibility ${{ matrix.compatibility }} \ --target ${{ matrix.target }} \ --zig diff --git a/synapse/Cargo.toml b/synapse/Cargo.toml index ebdb207..32de06f 100644 --- a/synapse/Cargo.toml +++ b/synapse/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.65" http-body = "0.4.5" -pyo3 = { version = "0.17.2", features = ["extension-module", "abi3-py37", "anyhow"] } +pyo3 = { version = "0.17.2", features = ["extension-module", "anyhow"] } pyo3-log = "0.7.0" pyo3-matrix-synapse-module = "0.1.0" serde = { version = "1.0.145", features = ["derive"] } From 49d98f2d5f6f0a2f8b9a4f2b012cac98c94f7d5e Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:28:46 +0200 Subject: [PATCH 11/23] Rename modules, prepare for publishing on crates.io and pypi This adds some package metadata, changes the module names and prepare the CI to publish on both crates.io and pypi when pushing tags --- .github/workflows/ci.yaml | 32 ++++++ .github/workflows/python.yaml | 73 +++++++------- Cargo.toml | 8 +- LICENSE | 177 ++++++++++++++++++++++++++++++++++ server/Cargo.toml | 11 ++- server/src/main.rs | 2 +- synapse/Cargo.toml | 12 ++- synapse/pyproject.toml | 18 ++-- synapse/src/lib.rs | 10 +- 9 files changed, 285 insertions(+), 58 deletions(-) create mode 100644 LICENSE diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b65838..f193f5e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,6 +3,8 @@ name: CI on: push: branches: [ main ] + tags: + - '*' pull_request: branches: [ main ] @@ -162,3 +164,33 @@ jobs: with: files: target/coverage/*.lcov flags: unit + + publish: + name: Publish on crates.io + needs: [rustfmt, clippy, minimal-versions, test, coverage] + runs-on: ubuntu-latest + + # Publish on tags + if: startsWith(github.ref, 'refs/tags/') + + permissions: + contents: read + + steps: + - name: Checkout the code + uses: actions/checkout@v3 + + - name: Install toolchain + id: toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + profile: minimal + + - name: Publish on crates.io + uses: actions-rs/cargo@v1 + with: + command: publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 2b8dbb8..069b344 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -9,6 +9,7 @@ on: jobs: build-wheels: + name: "Build Python wheels" strategy: fail-fast: false matrix: @@ -50,30 +51,6 @@ jobs: architecture: x64 update-environment: false - - name: Install Python 3.8 - uses: actions/setup-python@v4 - id: cpy38 - with: - python-version: "3.8" - architecture: x64 - update-environment: false - - - name: Install Python 3.9 - uses: actions/setup-python@v4 - id: cpy39 - with: - python-version: "3.9" - architecture: x64 - update-environment: false - - - name: Install Python 3.10 - uses: actions/setup-python@v4 - id: cpy310 - with: - python-version: "3.10" - architecture: x64 - update-environment: false - - name: Install maturin (macOS) if: runner.os == 'macOS' run: | @@ -102,17 +79,15 @@ jobs: target: ${{ matrix.target }} - name: Build wheels - run: | - maturin build \ - --release \ - --out dist \ - --manifest-path synapse/Cargo.toml \ - -i ${{ steps.cpy37.outputs.python-path }} \ - -i ${{ steps.cpy38.outputs.python-path }} \ - -i ${{ steps.cpy39.outputs.python-path }} \ - -i ${{ steps.cpy310.outputs.python-path }} \ - --compatibility ${{ matrix.compatibility }} \ - --target ${{ matrix.target }} \ + run: >- + maturin build + --sdist + --release + --out dist + --manifest-path synapse/Cargo.toml + -i ${{ steps.cpy37.outputs.python-path }} + --compatibility ${{ matrix.compatibility }} + --target ${{ matrix.target }} --zig - name: Upload wheels @@ -120,3 +95,31 @@ jobs: with: name: wheels path: dist + + upload: + name: "Upload to PyPI" + runs-on: ubuntu-latest + + # Publish on test PyPI on all push, and on regular PyPI on tags + if: github.event_name == 'push' + + permissions: {} + + needs: [ build-wheels ] + steps: + - name: Download wheels + uses: actions/download-artifact@v3 + with: + name: wheels + + - name: Publish distribution to Test PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + + - name: Publish distribution to PyPI + if: startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 59a3b25..6be13a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,13 @@ [package] -name = "rendezvous" +name = "matrix-http-rendezvous" version = "0.1.0" +authors = ["Quentin Gliech "] edition = "2021" +license = "Apache-2.0" +description = "A Tower service which implements MSC3886" +repository = "https://github.com/matrix-org/rust-http-rendezvous-server/" +rust-version = "1.61" +exclude = ["/.github", ".gitignore"] [dependencies] axum = { version = "0.6.0-rc.2", features = ["headers"] } diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f433b1a --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/server/Cargo.toml b/server/Cargo.toml index 5f88f44..c038dc1 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,13 +1,16 @@ [package] -name = "server" +name = "matrix-http-rendezvous-server" version = "0.1.0" +authors = ["Quentin Gliech "] edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +license = "Apache-2.0" +description = "A standalone server which implements MSC3886" +repository = "https://github.com/matrix-org/rust-http-rendezvous-server/" +rust-version = "1.61" [dependencies] hyper = { version = "0.14.20", features = ["server"] } tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] } tracing-subscriber = "0.3.16" -rendezvous = { path = "../" } +matrix-http-rendezvous = { path = "../", version = "0.1.0" } diff --git a/server/src/main.rs b/server/src/main.rs index 0bf07fa..68b5458 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -22,7 +22,7 @@ use std::net::SocketAddr; async fn main() { tracing_subscriber::fmt::init(); - let app = rendezvous::router(""); + let app = matrix_http_rendezvous::router(""); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); diff --git a/synapse/Cargo.toml b/synapse/Cargo.toml index 32de06f..48549d8 100644 --- a/synapse/Cargo.toml +++ b/synapse/Cargo.toml @@ -1,12 +1,16 @@ [package] -name = "synapse_rendezvous" +name = "matrix-http-rendezvous-synapse" version = "0.1.0" +authors = ["Quentin Gliech "] edition = "2021" +license = "Apache-2.0" +description = "A Matrix Synapse module which implements MSC3886" +repository = "https://github.com/matrix-org/rust-http-rendezvous-server/" +rust-version = "1.61" publish = false -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -name = "synapse_rendezvous" +name = "matrix_http_rendezvous_synapse" crate-type = ["cdylib"] [dependencies] @@ -19,4 +23,4 @@ serde = { version = "1.0.145", features = ["derive"] } tower = { version = "0.4.13", features = ["util"] } tracing = { version = "0.1.37", features = ["log", "log-always"] } -rendezvous = { path = "../" } +matrix-http-rendezvous = { path = "../", version = "0.1.0" } diff --git a/synapse/pyproject.toml b/synapse/pyproject.toml index 9648005..23205cd 100644 --- a/synapse/pyproject.toml +++ b/synapse/pyproject.toml @@ -3,20 +3,26 @@ requires = ["maturin>=0.13,<0.14"] build-backend = "maturin" [project] -name = "synapse_rendezvous" -version = "0.0.1" +name = "matrix_http_rendezvous_synapse" +version = "0.1.0" requires-python = ">=3.7" classifiers = [ + "Development Status :: 3 - Alpha", "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", + "License :: OSI Approved :: Apache Software License", + "Environment :: Plugins", +] +description = "A Matrix Synapse module which implements MSC3886" +authors = [ + { name = "Quentin Gliech", email = "quenting@element.io" } ] - [tool.poetry] -name = "synapse_rendezvous" -version = "0.0.1" -description = "A Rendez-Vous server module for Synapse" +name = "matrix_http_rendezvous_synapse" +version = "0.1.0" +description = "A Matrix Synapse module which implements MSC3886" authors = ["Quentin Gliech "] [tool.poetry.dependencies] diff --git a/synapse/src/lib.rs b/synapse/src/lib.rs index c7e7ba3..e8beddc 100644 --- a/synapse/src/lib.rs +++ b/synapse/src/lib.rs @@ -15,11 +15,7 @@ #![forbid(unsafe_code)] #![deny(clippy::all)] #![warn(clippy::pedantic)] -#![allow( - clippy::borrow_deref_ref, - clippy::used_underscore_binding, - clippy::needless_pass_by_value -)] +#![allow(clippy::needless_pass_by_value)] use anyhow::anyhow; use http_body::Body; @@ -42,7 +38,7 @@ pub struct SynapseRendezvousModule; impl SynapseRendezvousModule { #[new] fn new(config: &Config, module_api: ModuleApi) -> PyResult { - let service = rendezvous::router(&config.prefix) + let service = matrix_http_rendezvous::router(&config.prefix) .map_response(|res| res.map(|b| b.map_err(|e| anyhow!(e)))); module_api.register_web_service(&config.prefix, service)?; @@ -56,7 +52,7 @@ impl SynapseRendezvousModule { } #[pymodule] -fn synapse_rendezvous(_py: Python, m: &PyModule) -> PyResult<()> { +fn matrix_http_rendezvous_synapse(_py: Python, m: &PyModule) -> PyResult<()> { pyo3_log::init(); m.add_class::()?; From d9a9cdfee82408eeb304a83395bbd02c2d0ae2d7 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:30:23 +0200 Subject: [PATCH 12/23] Fix Rust publish job --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f193f5e..3ed070e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -167,7 +167,7 @@ jobs: publish: name: Publish on crates.io - needs: [rustfmt, clippy, minimal-versions, test, coverage] + needs: [rustfmt, clippy, test, coverage] runs-on: ubuntu-latest # Publish on tags From 10e49e88636f1b2d4abddfa2d04e5665f9c7aeb8 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:33:33 +0200 Subject: [PATCH 13/23] Fix python package name --- synapse/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/Cargo.toml b/synapse/Cargo.toml index 48549d8..1f25e1b 100644 --- a/synapse/Cargo.toml +++ b/synapse/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "matrix-http-rendezvous-synapse" +name = "matrix_http_rendezvous_synapse" version = "0.1.0" authors = ["Quentin Gliech "] edition = "2021" From 810d71d24b676a6eb69e4b446c4af7111ab58dd5 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:33:47 +0200 Subject: [PATCH 14/23] Rename Rust CI workflow --- .github/workflows/{ci.yaml => rust.yaml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{ci.yaml => rust.yaml} (99%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/rust.yaml similarity index 99% rename from .github/workflows/ci.yaml rename to .github/workflows/rust.yaml index 3ed070e..5370986 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/rust.yaml @@ -1,4 +1,4 @@ -name: CI +name: Rust on: push: From 96eb60b0726159d038515749b784b86244aba1be Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:34:08 +0200 Subject: [PATCH 15/23] add /dist in .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4fffb2f..9f9b51c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /Cargo.lock +/dist From 0547798c49d159b95a8e8e139f205a86bc885630 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:34:28 +0200 Subject: [PATCH 16/23] Limit Python workflow concurrency --- .github/workflows/python.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 069b344..ddb4f2b 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -7,6 +7,10 @@ on: - "*" pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build-wheels: name: "Build Python wheels" From 729a238690df9b5f0a1d881127f1b72eb298f654 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:36:15 +0200 Subject: [PATCH 17/23] Setup Rust build cache in Python CI --- .github/workflows/python.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index ddb4f2b..6950b17 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -82,6 +82,11 @@ jobs: default: true target: ${{ matrix.target }} + - name: Setup Rust build cache + uses: Swatinem/rust-cache@v2 + with: + shared-key: ${{ matrix.target }} + - name: Build wheels run: >- maturin build From 30de20a11d26a464205ffbcb88d923a529a86f03 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:40:12 +0200 Subject: [PATCH 18/23] Try fixing maturin build in CI --- .github/workflows/python.yaml | 18 +++++++++--------- synapse/Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 6950b17..d907719 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -88,15 +88,15 @@ jobs: shared-key: ${{ matrix.target }} - name: Build wheels - run: >- - maturin build - --sdist - --release - --out dist - --manifest-path synapse/Cargo.toml - -i ${{ steps.cpy37.outputs.python-path }} - --compatibility ${{ matrix.compatibility }} - --target ${{ matrix.target }} + run: | + maturin build \ + --sdist \ + --release \ + --out dist \ + --manifest-path synapse/Cargo.toml \ + -i ${{ steps.cpy37.outputs.python-path }} \ + --compatibility ${{ matrix.compatibility }} \ + --target ${{ matrix.target }} \ --zig - name: Upload wheels diff --git a/synapse/Cargo.toml b/synapse/Cargo.toml index 1f25e1b..48549d8 100644 --- a/synapse/Cargo.toml +++ b/synapse/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "matrix_http_rendezvous_synapse" +name = "matrix-http-rendezvous-synapse" version = "0.1.0" authors = ["Quentin Gliech "] edition = "2021" From 3e5cd964ff588c35d81eaf3ec4df7ec65e98d7b6 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:43:19 +0200 Subject: [PATCH 19/23] Run CI with Python 3.10 --- .github/workflows/python.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index d907719..65f9d06 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -47,11 +47,11 @@ jobs: - name: Checkout the code uses: actions/checkout@v3 - - name: Install Python 3.7 + - name: Install Python 3.10 uses: actions/setup-python@v4 - id: cpy37 + id: cpy310 with: - python-version: "3.7" + python-version: "3.10" architecture: x64 update-environment: false @@ -94,7 +94,7 @@ jobs: --release \ --out dist \ --manifest-path synapse/Cargo.toml \ - -i ${{ steps.cpy37.outputs.python-path }} \ + -i ${{ steps.cpy310.outputs.python-path }} \ --compatibility ${{ matrix.compatibility }} \ --target ${{ matrix.target }} \ --zig From d27a1468028c635f7032323cfebe39b76e976124 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 15:58:53 +0200 Subject: [PATCH 20/23] Collect sdist in a separate job --- .github/workflows/python.yaml | 40 ++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 65f9d06..1a976ec 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -12,6 +12,32 @@ concurrency: cancel-in-progress: true jobs: + collect-sdist: + name: "Collect sdist" + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v3 + + - name: Install Python 3.10 + uses: actions/setup-python@v4 + id: cpy310 + with: + python-version: "3.10" + architecture: x64 + + - name: Install build + run: pip install build + + - name: Collect sdist + run: python -m build -o dist --sdist synapse + + - name: Upload sdist + uses: actions/upload-artifact@v3 + with: + name: sdist + path: dist + build-wheels: name: "Build Python wheels" strategy: @@ -90,7 +116,6 @@ jobs: - name: Build wheels run: | maturin build \ - --sdist \ --release \ --out dist \ --manifest-path synapse/Cargo.toml \ @@ -109,20 +134,25 @@ jobs: name: "Upload to PyPI" runs-on: ubuntu-latest - # Publish on test PyPI on all push, and on regular PyPI on tags - if: github.event_name == 'push' - permissions: {} - needs: [ build-wheels ] + needs: [ collect-sdist, build-wheels ] steps: - name: Download wheels uses: actions/download-artifact@v3 with: name: wheels + - name: Download sdist + uses: actions/download-artifact@v3 + with: + name: sdist + + - run: find . + - name: Publish distribution to Test PyPI uses: pypa/gh-action-pypi-publish@release/v1 + if: github.event_name == 'push' with: password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository_url: https://test.pypi.org/legacy/ From 283fd2781d31328771b6a9d10d41d47326a83c87 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 16:05:39 +0200 Subject: [PATCH 21/23] Re-enable abi3-py37 --- synapse/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/Cargo.toml b/synapse/Cargo.toml index 48549d8..05daf5c 100644 --- a/synapse/Cargo.toml +++ b/synapse/Cargo.toml @@ -16,7 +16,7 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.65" http-body = "0.4.5" -pyo3 = { version = "0.17.2", features = ["extension-module", "anyhow"] } +pyo3 = { version = "0.17.2", features = ["extension-module", "abi3-py37", "anyhow"] } pyo3-log = "0.7.0" pyo3-matrix-synapse-module = "0.1.0" serde = { version = "1.0.145", features = ["derive"] } From d6823b90df1c6cb861f9a336f0eda993b97581a8 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 16:11:52 +0200 Subject: [PATCH 22/23] Collect the artifacts to the right directory --- .github/workflows/python.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 1a976ec..130d76e 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -142,11 +142,13 @@ jobs: uses: actions/download-artifact@v3 with: name: wheels + path: dist - name: Download sdist uses: actions/download-artifact@v3 with: name: sdist + path: dist - run: find . From da5d124d0ddf73ce8d3a7e56251acc3a77c8d670 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sat, 8 Oct 2022 16:14:00 +0200 Subject: [PATCH 23/23] Cleanup the PyPI upload --- .github/workflows/python.yaml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml index 130d76e..914ecda 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/python.yaml @@ -135,6 +135,7 @@ jobs: runs-on: ubuntu-latest permissions: {} + if: startsWith(github.ref, 'refs/tags') needs: [ collect-sdist, build-wheels ] steps: @@ -150,15 +151,6 @@ jobs: name: sdist path: dist - - run: find . - - - name: Publish distribution to Test PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - if: github.event_name == 'push' - with: - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository_url: https://test.pypi.org/legacy/ - - name: Publish distribution to PyPI if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1