Skip to content

Commit

Permalink
Merge pull request #375 from NNPDF/oxidize-ci
Browse files Browse the repository at this point in the history
Rust/maturin CI
  • Loading branch information
felixhekhorn authored May 30, 2024
2 parents ca7112f + af02fad commit a76221d
Show file tree
Hide file tree
Showing 28 changed files with 337 additions and 65 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/crates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy Crates

on:
push:
tags:
- "*"
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install and configure Poetry
uses: snok/install-poetry@v1
- name: Install task runner
run: pip install poethepoet
- name: Bump versions
run: |
poetry install --only version
poe bump-version
- name: Publish crates
run: |
jq '.[]' crates/release.json | xargs -I _ cargo publish -p _ --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
123 changes: 123 additions & 0 deletions .github/workflows/maturin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Deploy Maturin wheels

on:
push:
tags:
- "*"
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter -m crates/eko/Cargo.toml
sccache: "true"
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter -m crates/eko/Cargo.toml
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-latest
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter -m crates/eko/Cargo.toml
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist -m crates/eko/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
8 changes: 7 additions & 1 deletion .github/workflows/unittests-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ name: Rust unit tests
on: push

jobs:
test-rust:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install task runner
run: pip install poethepoet
- name: Run fmt
run: |
poe fmtcheck
- name: Run clippy
run: |
poe clippy
- name: Run Rust unit tests
run: |
poe rtest
21 changes: 6 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
ci:
autofix_prs: false
skip: [fmt-eko, fmt-ekore]
skip: [fmt] # will be run by a separate CI
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down Expand Up @@ -45,21 +45,12 @@ repos:
- toml
- repo: local
hooks:
- id: fmt-eko
name: fmt-eko
description: Format eko files with cargo fmt.
entry: cargo fmt --manifest-path crates/eko/Cargo.toml --
- id: fmt
name: fmt
description: Format Rust files with cargo fmt.
entry: cargo fmt --
language: system
files: ^crates/eko/.*\.rs$
args: []
- repo: local
hooks:
- id: fmt-ekore
name: fmt-ekore
description: Format ekore files with cargo fmt.
entry: cargo fmt --manifest-path crates/ekore/Cargo.toml --
language: system
files: ^crates/ekore/.*\.rs$
files: ^crates/.*\.rs$
args: []
- repo: https://github.com/pre-commit/pre-commit
rev: v3.7.1
Expand Down
4 changes: 2 additions & 2 deletions crates/Cargo.lock → Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[workspace]
members = ["crates/*"]
resolver = "2"

[workspace.package]
authors = [
"A. Barontini <[email protected]>",
"A. Candido <[email protected]>",
"F. Hekhorn <[email protected]>",
"N. Laurenti <[email protected]>",
"G. Magni <[email protected]>",
"T. Sharma <[email protected]>",
]
description = "Evolution Kernel Operators"
readme = "README.md"
categories = ["science"]
edition = "2021"
keywords = ["physics"]
license = "GPL-3.0-or-later"
repository = "https://github.com/NNPDF/eko"
rust-version = "1.60.0"
version = "0.0.1"
3 changes: 0 additions & 3 deletions crates/Cargo.toml

This file was deleted.

18 changes: 18 additions & 0 deletions crates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Welcome to the rusty side of EKO!

Here, we develop the Rust components of the EKO library

## Crates

- `ekore` contains the underlying collinear anomalous dimensions and the operator matrix elements
- `eko` is the glue between the Python side and the `ekore` crate

## Files

- `release.json` defines the releasing order of crates
- only listed crates will be released
- dependent crates should follow those they are depending on
- `katex-header.html` is an HTML snippet to be included in every docs page to inject
KaTeX support
- `bump-versions.py` increases the Rust versions in all crates consistently
- `make_bib.py` generates the Rust function stubs which serve as fake bibliography system
40 changes: 40 additions & 0 deletions crates/bump-versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json
import sys
from pathlib import Path

import tomlkit

HERE = Path(__file__).parent
CRATES = json.loads((HERE / "release.json").read_text())


def workspace(manifest, version):
manifest["workspace"]["package"]["version"] = version
return manifest


def crate(manifest, version):
internals = set(manifest["dependencies"].keys()).intersection(CRATES)
for dep in internals:
manifest["dependencies"][dep]["version"] = version
return manifest


def update(path, version, edit):
path = HERE / Path(path) / "Cargo.toml"
manifest = tomlkit.parse(path.read_text())
manifest = edit(manifest, version)
path.write_text(tomlkit.dumps(manifest))


def main(version):
update("..", version, workspace)
for name in CRATES:
update(name, version, crate)


if __name__ == "__main__":
if len(sys.argv) < 2:
raise ValueError(f"Pass a version (e.g. v0.0.0) to {sys.argv[0]}")
# `git describe` starts with a `v` which we need to remove again
main(sys.argv[1][1:])
17 changes: 13 additions & 4 deletions crates/eko/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
[package]
name = "eko"
version = "0.1.0"
edition = "2021"

authors.workspace = true
description.workspace = true
readme.workspace = true
categories.workspace = true
edition.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "../katex-header.html" ]
rustdoc-args = ["--html-in-header", "katex-header.html"]

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

[dependencies]
num = "0.4.1"
ekore = { version = "0.1.0", path = "../ekore" }
ekore = { path = "../ekore", version = "0.0.1" }
1 change: 1 addition & 0 deletions crates/eko/katex-header.html
2 changes: 1 addition & 1 deletion crates/eko/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["maturin>=1.1,<2.0"]
build-backend = "maturin"

[project]
name = "ekors"
name = "eko-rs"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Rust",
Expand Down
Loading

0 comments on commit a76221d

Please sign in to comment.