Skip to content

Commit

Permalink
Version management #1: introducing pavexc (#163)
Browse files Browse the repository at this point in the history
# What's wrong

For Pavex to work as expected, the version of the CLI used when
compiling a project with `cargo px [...]` must match the version of the
`pavex` library crate used in the project.
Currently, there's no mechanism to ensure this is the case. As a result,
you'll get version mismatches, resulting in confusing errors (see
@m1guelpf in #131).
The problem is even worse if you have multiple Pavex projects, each
using a different library version: you'd have to juggle multiple CLI
versions on your own since they can't all be in the `PATH`.

# The solution

To eliminate the problem, this PR reworks the `pavex` CLI: it is now a
_version manager_.
All the meaty functionality (server SDK generation, project generation)
is moved into another binary, `pavexc` (**pavex** **c**ompiler).
`pavex` introduces the concept of toolchains, in the same vein of
`rustup`. There can be multiple toolchains installed and it'll pick the
most appropriate one for each command:

- For `new`, it'll check the default toolchain. If none has been
defined, it'll use the corresponding version of `pavexc`.
- For `generate`, it'll match the version of `pavex` (the library) used
in the project. If the corresponding `pavexc` toolchain is not
installed, it'll be installed on the fly.

## Missing pieces

The `pavex` CLI needs to grow a few commands to manage toolchains:
`pavex toolchain default set`, `pavex toolchain default show`, `pavex
toolchain list` and something for removal.
Since they are only relevant for `pavex new`, that's deferred to a later
PR.
  • Loading branch information
LukeMathWalker committed Jan 16, 2024
1 parent f21fd49 commit 325626f
Show file tree
Hide file tree
Showing 56 changed files with 2,638 additions and 234 deletions.
43 changes: 34 additions & 9 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- main

jobs:
build_pavex_cli:
build_clis:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -25,12 +25,17 @@ jobs:
- name: Build CLI
run: |
cd libs
cargo build --package pavex_cli --bin pavex --release
- name: Store CLI artifact
cargo build --bin pavex --bin pavexc --release
- name: Store pavex CLI artifact
uses: actions/upload-artifact@v4
with:
name: pavex_cli
path: libs/target/release/pavex
- name: Store pavexc CLI artifact
uses: actions/upload-artifact@v4
with:
name: pavexc_cli
path: libs/target/release/pavexc

build_tutorial_generator:
runs-on: ubuntu-latest
Expand All @@ -55,20 +60,23 @@ jobs:

tests:
runs-on: ubuntu-latest
env:
PAVEX_PAVEXC: "/home/runner/.cargo/bin/pavexc"
needs:
- build_pavex_cli
- build_clis
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust nightly toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rust-docs-json
components: rust-docs-json, rustfmt
rustflags: ""
- name: Install Rust stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
with:
components: rustfmt
rustflags: ""
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
Expand All @@ -80,8 +88,15 @@ jobs:
with:
name: pavex_cli
path: ~/.cargo/bin
- name: Mark as executable
- name: Download pavexc CLI artifact
uses: actions/download-artifact@v4
with:
name: pavexc_cli
path: ~/.cargo/bin
- name: Mark pavex as executable
run: chmod +x ~/.cargo/bin/pavex
- name: Mark pavexc as executable
run: chmod +x ~/.cargo/bin/pavexc
- name: Run tests
run: |
cd libs
Expand All @@ -91,8 +106,10 @@ jobs:
is_up_to_date:
runs-on: ubuntu-latest
env:
PAVEX_PAVEXC: "/home/runner/.cargo/bin/pavexc"
needs:
- build_pavex_cli
- build_clis
- build_tutorial_generator
steps:
- name: Checkout repository
Expand All @@ -105,19 +122,27 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rust-docs-json
components: rust-docs-json, rustfmt
rustflags: ""
- name: Install Rust stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
with:
rustflags: ""
components: rustfmt
- name: Download pavex CLI artifact
uses: actions/download-artifact@v4
with:
name: pavex_cli
path: ~/.cargo/bin
- name: Mark as executable
- name: Download pavexc CLI artifact
uses: actions/download-artifact@v4
with:
name: pavexc_cli
path: ~/.cargo/bin
- name: Mark pavex as executable
run: chmod +x ~/.cargo/bin/pavex
- name: Mark pavexc as executable
run: chmod +x ~/.cargo/bin/pavexc
- name: Download tutorial_generator CLI artifact
uses: actions/download-artifact@v4
with:
Expand Down

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

31 changes: 20 additions & 11 deletions doc_examples/guide/middleware/core_concepts/project/Cargo.lock

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

23 changes: 20 additions & 3 deletions doc_examples/guide/request_data/buffered_body/project/Cargo.lock

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

23 changes: 20 additions & 3 deletions doc_examples/guide/request_data/json/project/Cargo.lock

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

0 comments on commit 325626f

Please sign in to comment.