From fa1ab68ef35f8b47ccead6f8dc56a00f962a53dc Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Fri, 22 Sep 2023 13:10:04 -0500 Subject: [PATCH] Python Bindings. Again. No, really! (#55) * - Cargo.toml: add `crate-type = ["cdylib"] to [lib]; lacking this is what was causing the executable to be put in wheels - pyproject.toml: add "python-binding" to features for conditional compilation - main.rs: `cargo build` was failing for the vtracer executable; I think the previous import scheme had an implicit dependency on the library being built and called 'vtracer'. The other way to do this would have been to add an explicit dependency to the [[bin]], but making explicit imports here solves things directly * re-enable linux builds; features are defined in the pyproject.toml now rather than in the workflow arguments * And publish Linux, too! --- .github/workflows/python.yml | 50 ++++++++++++++++++------------------ cmdapp/Cargo.toml | 6 ++++- cmdapp/pyproject.toml | 2 +- cmdapp/src/main.rs | 8 +++--- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 5cd9dd3..8f7b682 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -16,28 +16,28 @@ permissions: contents: read jobs: - # linux: - # runs-on: ubuntu-latest - # strategy: - # matrix: - # target: [x86_64, x86, aarch64, armv7, s390x, ppc64le] - # steps: - # - uses: actions/checkout@v3 - # - uses: actions/setup-python@v4 - # with: - # python-version: '3.10' - # - name: Build wheels - # uses: PyO3/maturin-action@v1 - # with: - # target: ${{ matrix.target }} - # args: -m cmdapp/Cargo.toml --release --features=python-binding --out dist --find-interpreter - # sccache: 'true' - # manylinux: auto - # - name: Upload wheels - # uses: actions/upload-artifact@v3 - # with: - # name: wheels - # path: dist + linux: + runs-on: ubuntu-latest + strategy: + matrix: + target: [x86_64, x86, aarch64, armv7, s390x, ppc64le] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + args: -m cmdapp/Cargo.toml --release --out dist --find-interpreter + sccache: 'true' + manylinux: auto + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist windows: runs-on: windows-latest @@ -54,7 +54,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.target }} - args: -m cmdapp/Cargo.toml --release --features=python-binding --out dist --find-interpreter + args: -m cmdapp/Cargo.toml --release --out dist --find-interpreter sccache: 'true' - name: Upload wheels uses: actions/upload-artifact@v3 @@ -76,7 +76,7 @@ jobs: uses: PyO3/maturin-action@v1 with: target: ${{ matrix.target }} - args: -m cmdapp/Cargo.toml --release --features=python-binding --out dist --find-interpreter + args: -m cmdapp/Cargo.toml --release --out dist --find-interpreter sccache: 'true' - name: Upload wheels uses: actions/upload-artifact@v3 @@ -108,7 +108,7 @@ jobs: # IMPORTANT: this permission is mandatory for trusted publishing id-token: write if: "startsWith(github.ref, 'refs/tags/')" - needs: [windows, macos, sdist] # linux + needs: [windows, macos, sdist, linux] steps: - uses: actions/download-artifact@v3 with: diff --git a/cmdapp/Cargo.toml b/cmdapp/Cargo.toml index b775d9e..82f80e4 100644 --- a/cmdapp/Cargo.toml +++ b/cmdapp/Cargo.toml @@ -18,4 +18,8 @@ fastrand = "1.8" pyo3 = { version = "0.19.0", optional = true } [features] -python-binding = ["pyo3"] \ No newline at end of file +python-binding = ["pyo3"] + +[lib] +name = "vtracer" +crate-type = ["cdylib"] \ No newline at end of file diff --git a/cmdapp/pyproject.toml b/cmdapp/pyproject.toml index f5c4a5a..4f2a6d4 100644 --- a/cmdapp/pyproject.toml +++ b/cmdapp/pyproject.toml @@ -23,6 +23,6 @@ requires = ["maturin>=1.2,<2.0"] build-backend = "maturin" [tool.maturin] -features = ["pyo3/extension-module"] +features = ["pyo3/extension-module", "python-binding"] compatibility = "manylinux2014" sdist-include = ["LICENSE-MIT", "vtracer/README.md"] \ No newline at end of file diff --git a/cmdapp/src/main.rs b/cmdapp/src/main.rs index 230d524..07a3c80 100644 --- a/cmdapp/src/main.rs +++ b/cmdapp/src/main.rs @@ -1,8 +1,10 @@ -use vtracer::{Config, convert_image_to_svg}; +mod config; +mod converter; +mod svg; fn main() { - let config = Config::from_args(); - let result = convert_image_to_svg(config); + let config = config::Config::from_args(); + let result = converter::convert_image_to_svg(config); match result { Ok(()) => { println!("Conversion successful.");