Skip to content

Commit

Permalink
Isolate each example in its own workspace. (#50)
Browse files Browse the repository at this point in the history
It's time to make space for more than one example!

This PR adds a skeleton of what will become the `realworld` API
implementation for `pavex`.
To make examples realistic, I restructured the `examples` folder in such
a way that each example gets its own workspace. A new script (`ci.sh`)
has been added to make it easy to check all examples for correctness.
  • Loading branch information
LukeMathWalker committed Apr 28, 2023
1 parent f2e772a commit 33056e8
Show file tree
Hide file tree
Showing 26 changed files with 914 additions and 188 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/test-target
/ui_test_envs
/target
/libs/ui_test_envs
/libs/target
/examples/**/target
/vendor
.DS_Store
*.snap
12 changes: 11 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ The generated code or the graph diagnostics may not match our expectations.
The test runner will save the unexpected output in a file named like the expectation file with an additional `.snap` suffix. You can then choose to update the saved snapshot via our utility CLI:

```bash
# It must be run from the root folder of the workspace
# It must be run from the root folder of the libs workspace
cargo r --bin snaps
```

It will cycle through all `.snap` files and print the changeset with respect to our previous expectations.
You will then be prompted to decide if you want to update the saved snapshot to match the new value or if you prefer to keep it as it.

# Checking examples

Each example project under the `examples` folder is its own workspace.
The easiest way to check that everything compiles and works as expected is to rely on the `./ci.sh` script at root of the repository.
It runs whatever `cargo` command you specify against all workspaces in this project (i.e. `libs` + all examples).

E.g. `./ci.sh check` will run `cargo check` in each workspace.

It will also forward any flag to `cargo`—e.g. `./ci.sh check --all-features` will run `cargo check --all-features` in all workspaces.
2 changes: 0 additions & 2 deletions Cargo.toml

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ We publish project updates every 4-6 weeks:

You can see `pavex` at work in the [`/examples` folder](./examples):

- In [`examples/app_blueprint/src/lib.rs`](./examples/app_blueprint/src/lib.rs) we specify the app's behavior in
- In [`examples/skeleton/app_blueprint/src/lib.rs`](./examples/skeleton/app_blueprint/src/lib.rs) we specify the app's behavior in
a `Blueprint`
the endpoints it exposes and their request handlers, as well as the required constructors for the application state;
- In [`examples/app_blueprint/src/bin.rs`](./examples/app_blueprint/src/bin.rs) we serialize the `Blueprint` and
- In [`examples/skeleton/app_blueprint/src/bin.rs`](./examples/skeleton/app_blueprint/src/bin.rs) we serialize the `Blueprint` and
invoke `pavex`'s CLI to generate the server code that will execute at runtime, which you can find in
[`examples/generated_app/src/lib.rs`](./examples/generated_app/src/lib.rs).
[`examples/skeleton/generated_app/src/lib.rs`](./examples/skeleeton/generated_app/src/lib.rs).

In [`examples/app_blueprint/blueprint.ron`](./examples/app_blueprint/blueprint.ron) you can have a peek at what
In [`examples/app_blueprint/blueprint.ron`](./examples/skeleton/app_blueprint/blueprint.ron) you can have a peek at what
the `Blueprint` looks like when serialized.

## Architectural Overview
Expand Down
30 changes: 30 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Check that the first argument is not empty
if [ -z "$1" ]; then
echo "Usage: ./ci.sh <cargo command> [<cargo options>]"
echo "Runs a 'cargo' command on all Rust workspaces in the current directory and its subdirectories."
exit 1
fi

# Get the cargo command and options from the arguments
CARGO_CMD=$1
shift
CARGO_OPTS=${*:-""}

# Find all directories that contain a Cargo.toml file and have a [workspace] section in the file
WORKSPACES=$(find . -type f -name Cargo.toml -exec grep -q "\[workspace\]" {} \; -print | xargs -n1 dirname | sort | uniq)

# Exclude test directory
TOP_WORKSPACES=()
for workspace in $WORKSPACES; do
if [[ ! "$workspace" =~ "/ui_test_envs/" ]]; then
TOP_WORKSPACES+=("$workspace")
fi
done

# Iterate over each workspace and run `cargo check`
for workspace in "${TOP_WORKSPACES[@]}"; do
echo "Running 'cargo $CARGO_CMD $CARGO_OPTS' in workspace: $workspace"
(cd "$workspace" && cargo $CARGO_CMD $CARGO_OPTS)
done
80 changes: 0 additions & 80 deletions examples/app_blueprint/blueprint.ron

This file was deleted.

19 changes: 0 additions & 19 deletions examples/app_blueprint/src/bin.rs

This file was deleted.

7 changes: 7 additions & 0 deletions examples/realworld/Cargo.lock

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

2 changes: 2 additions & 0 deletions examples/realworld/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["api_bp"]
8 changes: 8 additions & 0 deletions examples/realworld/api_bp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "api_bp"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Empty file.
Loading

0 comments on commit 33056e8

Please sign in to comment.