Skip to content

Commit d561480

Browse files
authored
Merge pull request #203 from gerardcl/feat/enable-rust-crate-binary-build
Feat/enable rust crate binary build
2 parents a4e8fa4 + 718ffec commit d561480

9 files changed

Lines changed: 159 additions & 50 deletions

File tree

.github/workflows/CICD.yml

Lines changed: 120 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name: CICD
88
on:
99
push:
1010
branches:
11-
- 'main'
11+
- main
1212
tags:
1313
- '*'
1414
pull_request:
@@ -18,6 +18,9 @@ on:
1818
permissions:
1919
contents: read
2020

21+
env:
22+
CARGO_TERM_COLOR: always
23+
2124
jobs:
2225

2326
test:
@@ -75,101 +78,179 @@ jobs:
7578
args: -- -D warnings
7679

7780
linux:
78-
runs-on: ubuntu-latest
81+
runs-on: ${{ matrix.platform.runner }}
7982
strategy:
80-
matrix:
81-
target: [x86_64, x86, armv7, s390x, ppc64le]
83+
matrix:
84+
platform:
85+
- runner: ubuntu-latest
86+
target: x86_64
87+
- runner: ubuntu-latest
88+
target: x86
89+
# skipping until ring update/fix compile issue: include/ring-core/asm_base.h:73:2: error: #error "ARM assembler must define __ARM_ARCH"
90+
# - runner: ubuntu-latest
91+
# target: aarch64
92+
- runner: ubuntu-latest
93+
target: armv7
94+
- runner: ubuntu-latest
95+
target: s390x
96+
- runner: ubuntu-latest
97+
target: ppc64le
8298
steps:
83-
- uses: actions/checkout@v3
84-
- uses: actions/setup-python@v4
99+
- uses: actions/checkout@v4
100+
- uses: actions/setup-python@v5
85101
with:
86-
python-version: '3.10'
102+
python-version: 3.x
87103
- name: Build wheels
88104
uses: PyO3/maturin-action@v1
89105
with:
90-
target: ${{ matrix.target }}
91-
args: --release --out dist --find-interpreter
106+
target: ${{ matrix.platform.target }}
107+
args: --release --out dist
92108
sccache: 'true'
93109
manylinux: auto
94110
- name: Upload wheels
95-
uses: actions/upload-artifact@v3
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: wheels-linux-${{ matrix.platform.target }}
114+
path: dist
115+
116+
musllinux:
117+
runs-on: ${{ matrix.platform.runner }}
118+
strategy:
119+
matrix:
120+
platform:
121+
- runner: ubuntu-latest
122+
target: x86_64
123+
- runner: ubuntu-latest
124+
target: x86
125+
# skipping until ring update/fix compile issue: include/ring-core/asm_base.h:73:2: error: #error "ARM assembler must define __ARM_ARCH"
126+
# - runner: ubuntu-latest
127+
# target: aarch64
128+
- runner: ubuntu-latest
129+
target: armv7
130+
steps:
131+
- uses: actions/checkout@v4
132+
- uses: actions/setup-python@v5
133+
with:
134+
python-version: 3.x
135+
- name: Build wheels
136+
uses: PyO3/maturin-action@v1
137+
with:
138+
target: ${{ matrix.platform.target }}
139+
args: --release --out dist
140+
sccache: 'true'
141+
manylinux: musllinux_1_2
142+
- name: Upload wheels
143+
uses: actions/upload-artifact@v4
96144
with:
97-
name: wheels
145+
name: wheels-musllinux-${{ matrix.platform.target }}
98146
path: dist
99147

100148
windows:
101-
runs-on: windows-latest
149+
runs-on: ${{ matrix.platform.runner }}
102150
strategy:
103151
matrix:
104-
target: [x64, x86]
152+
platform:
153+
- runner: windows-latest
154+
target: x64
155+
- runner: windows-latest
156+
target: x86
105157
steps:
106-
- uses: actions/checkout@v3
107-
- uses: actions/setup-python@v4
158+
- uses: actions/checkout@v4
159+
- uses: actions/setup-python@v5
108160
with:
109-
python-version: '3.10'
110-
architecture: ${{ matrix.target }}
161+
python-version: 3.x
162+
architecture: ${{ matrix.platform.target }}
111163
- name: Build wheels
112164
uses: PyO3/maturin-action@v1
113165
with:
114-
target: ${{ matrix.target }}
115-
args: --release --out dist --find-interpreter
166+
target: ${{ matrix.platform.target }}
167+
args: --release --out dist
116168
sccache: 'true'
117169
- name: Upload wheels
118-
uses: actions/upload-artifact@v3
170+
uses: actions/upload-artifact@v4
119171
with:
120-
name: wheels
172+
name: wheels-windows-${{ matrix.platform.target }}
121173
path: dist
122174

123175
macos:
124-
runs-on: macos-latest
176+
runs-on: ${{ matrix.platform.runner }}
125177
strategy:
126178
matrix:
127-
target: [x86_64, aarch64]
179+
platform:
180+
- runner: macos-12
181+
target: x86_64
182+
- runner: macos-14
183+
target: aarch64
128184
steps:
129-
- uses: actions/checkout@v3
130-
- uses: actions/setup-python@v4
185+
- uses: actions/checkout@v4
186+
- uses: actions/setup-python@v5
131187
with:
132-
python-version: '3.10'
188+
python-version: 3.x
133189
- name: Build wheels
134190
uses: PyO3/maturin-action@v1
135191
with:
136-
target: ${{ matrix.target }}
137-
args: --release --out dist --find-interpreter
192+
target: ${{ matrix.platform.target }}
193+
args: --release --out dist
138194
sccache: 'true'
139195
- name: Upload wheels
140-
uses: actions/upload-artifact@v3
196+
uses: actions/upload-artifact@v4
141197
with:
142-
name: wheels
198+
name: wheels-macos-${{ matrix.platform.target }}
143199
path: dist
144200

145201
sdist:
146202
runs-on: ubuntu-latest
147203
steps:
148-
- uses: actions/checkout@v3
204+
- uses: actions/checkout@v4
149205
- name: Build sdist
150206
uses: PyO3/maturin-action@v1
151207
with:
152208
command: sdist
153209
args: --out dist
154210
- name: Upload sdist
155-
uses: actions/upload-artifact@v3
211+
uses: actions/upload-artifact@v4
156212
with:
157-
name: wheels
213+
name: wheels-sdist
158214
path: dist
159215

160216
release:
161-
name: Release
217+
name: Release (PyPI)
162218
runs-on: ubuntu-latest
163-
if: "startsWith(github.ref, 'refs/tags/')"
164-
needs: [linux, windows, macos, sdist]
219+
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
220+
needs: [linux, musllinux, windows, macos, sdist]
221+
permissions:
222+
# Use to sign the release artifacts
223+
id-token: write
224+
# Used to upload release artifacts
225+
contents: write
226+
# Used to generate artifact attestation
227+
attestations: write
165228
steps:
166-
- uses: actions/download-artifact@v3
229+
- uses: actions/download-artifact@v4
230+
- name: Generate artifact attestation
231+
uses: actions/attest-build-provenance@v1
167232
with:
168-
name: wheels
233+
subject-path: 'wheels-*/*'
169234
- name: Publish to PyPI
235+
if: "startsWith(github.ref, 'refs/tags/')"
170236
uses: PyO3/maturin-action@v1
171237
env:
172238
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
173239
with:
174240
command: upload
175-
args: --non-interactive --skip-existing *
241+
args: --non-interactive --skip-existing wheels-*/*
242+
243+
publish:
244+
name: Publish (crates.io)
245+
if: startsWith(github.ref, 'refs/tags/')
246+
needs: [release]
247+
runs-on: ubuntu-latest
248+
steps:
249+
- uses: actions/checkout@v3
250+
- uses: actions-rs/toolchain@v1
251+
with:
252+
profile: minimal
253+
toolchain: stable
254+
override: true
255+
- name: Publish
256+
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v5.2.0 (2024-10-03)
4+
5+
* Publish Rust crate binary via crates.io [#202](https://github.com/gerardcl/renfe-cli/issues/202)
6+
37
## v5.1.0 (2024-10-02)
48

59
* Enable Renfe Cercanías GTFS dataset [#200](https://github.com/gerardcl/renfe-cli/issues/200)

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
[package]
22
name = "renfe-cli"
3-
version = "5.1.0"
3+
version = "5.2.0"
44
edition = "2021"
5+
authors = ["Gerard C.L. <gerardcl@gmail.com>"]
56
license = "BSD-3-Clause"
67
description = "CLI for searching Renfe train timetables in the Spanish country"
78
readme = "README.md"
89
homepage = "https://github.com/gerardcl/renfe-cli"
910
repository = "https://github.com/gerardcl/renfe-cli"
10-
keywords = ["cli", "timetables", "schedules", "trains", "renfe", "spain"]
11+
keywords = ["cli", "timetables", "trains", "renfe", "spain"]
1112
categories = ["command-line-utilities"]
1213
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1314

1415
[lib]
1516
name = "renfe_cli"
16-
crate-type = ["cdylib"]
17+
# https://doc.rust-lang.org/reference/linkage.html
18+
crate-type = ["cdylib", "lib"]
1719

1820
[dependencies]
1921
pyo3 = { version = "0.22", features = ["abi3-py37"] }

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
# Renfe Timetables CLI
44

5-
Get faster Renfe trains timetables in your terminal, with Python3.7+ support.
5+
Get faster Renfe trains timetables in your terminal, with Python3.8+ support.
66
No longer need to open the browser! Just keep using your terminal 😀
77

88
It supports both [Horarios de alta velocidad, larga distancia y media distancia](https://data.renfe.com/dataset/horarios-de-alta-velocidad-larga-distancia-y-media-distancia) (default option, as in the web) and [Renfe Cercanías](https://data.renfe.com/dataset/horarios-cercanias) GTFS datasets.
99

1010
`renfe-cli` is written in [Rust](https://www.rust-lang.org/) (since v4.0.0) and published to [pypi.org](https://pypi.org/project/renfe-cli/) as a Python package (CLI and library).
1111

12+
It is provided as a Python package due to historical reasons, but was ported to Rust to showcase Rust's interoperability and performance improvements that can offer to the Python ecosystem. Nevertheless, one can optionally use the built [renfe-cli](https://crates.io/crates/renfe-cli) crate that is publised to crates.io.
13+
1214
See the [changelog](https://github.com/gerardcl/renfe-cli/blob/master/CHANGELOG.md).
1315

1416
**NOTE** since I am more often using Rodalies trains I have created [rodalies-cli](https://github.com/gerardcl/rodalies-cli). I hope you like it too!
@@ -17,12 +19,22 @@ See the [changelog](https://github.com/gerardcl/renfe-cli/blob/master/CHANGELOG.
1719

1820
## Installation
1921

22+
### Python package
23+
2024
Install Python CLI package [renfe-cli](https://pypi.org/project/renfe-cli/)
2125

2226
```bash
2327
pip install renfe-cli --upgrade
2428
```
2529

30+
### Rust crate (optional)
31+
32+
Install the Rust crate [renfe-cli](https://crates.io/crates/renfe-cli)
33+
34+
```bash
35+
cargo install renfe-cli
36+
```
37+
2638
## Usage (CLI)
2739

2840
The CLI uses the official and latest Renfe's GTFS dataset, from [Horarios de alta velocidad, larga distancia y media distancia](https://data.renfe.com/dataset/horarios-de-alta-velocidad-larga-distancia-y-media-distancia), by default. Optionally, one can enable searching over [Renfe Cercanías GTFS dataset](https://data.renfe.com/dataset/horarios-cercanias) (expect longer load time in this case).

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "renfe-cli"
7-
requires-python = ">=3.7"
7+
requires-python = ">=3.8"
88
authors = [
99
{name = "Gerard Castillo Lasheras", email = "gerardcl@gmail.com"},
1010
]

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
pub mod cli;
2+
pub mod renfe;
3+
14
use pyo3::prelude::*;
25

3-
mod renfe;
4-
use renfe::{Renfe, Schedule, Station};
5-
mod cli;
66
use cli::main;
7+
use renfe::{Renfe, Schedule, Station};
78

89
/// A Python module implemented in Rust. The name of this function must match
910
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to

src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use renfe_cli::cli;
2+
3+
fn main() -> Result<(), pyo3::PyErr> {
4+
// Initialize the Python interpreter required
5+
pyo3::prepare_freethreaded_python();
6+
7+
cli::main()?;
8+
9+
Ok(())
10+
}

src/renfe.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::io::Read;
2-
31
use chrono::{Datelike, NaiveDate, NaiveTime, TimeDelta, Timelike};
42
use gtfs_structures::Gtfs;
53
use pyo3::{exceptions::PyValueError, pyclass, pymethods, PyResult};
4+
use std::io::Read;
65

76
#[pyclass]
87
pub struct Renfe {

0 commit comments

Comments
 (0)