Skip to content

Commit

Permalink
chore: migrate to cargo-make
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAegis committed May 5, 2024
1 parent d925c24 commit 1bff5e5
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Project specific environment variables, if you wish to override them or add
# more variables, create a `.env.local` file next to this one
CARGO_REQUIRE_WEB_SUPPORT = "false"
CARGO_REQUIRE_GIT_LFS = "true"
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: install cargo-make
run: cargo install cargo-make
- name: cache
uses: Swatinem/rust-cache@v2
- name: install alsa and udev (linux)
if: runner.os == 'linux'
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: test
run: cargo test --workspace --all-features
run: cargo make test
lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -51,14 +53,14 @@ jobs:
with:
toolchain: stable
components: rustfmt, clippy
- name: install cargo-make
run: cargo install cargo-make
- name: cache
uses: Swatinem/rust-cache@v2
- name: install alsa and udev (linux)
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
- name: format
run: cargo fmt --all -- --check
- name: check format and clippy
run: cargo make lint
mdbook:
runs-on: ubuntu-latest
needs: [test, lint]
Expand All @@ -75,7 +77,7 @@ jobs:
with:
mdbook-version: "latest"
- name: build mdbook
run: mdbook build
run: cargo make book-build
- name: setup pages
uses: actions/configure-pages@v4
if: |
Expand Down Expand Up @@ -121,6 +123,8 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: install cargo-make
run: cargo install cargo-make
- name: cache
uses: Swatinem/rust-cache@v2
- name: install alsa and udev (linux)
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

Expand Down
202 changes: 202 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Documentation: https://github.com/sagiegurari/cargo-make
env_files = [".env"]

## Project dependencies

[tasks.install-rls]
description = "Install rustup component rls"
workspace = false
private = true
install_crate = { rustup_component_name = "rls" }

[tasks.install-clippy]
description = "Install rustup component clippy"
workspace = false
private = true
install_crate = { rustup_component_name = "clippy" }

[tasks.install-rustfmt]
description = "Install rustup component rustfmt"
workspace = false
private = true
install_crate = { rustup_component_name = "rustfmt" }

[tasks.install-mdbook]
description = "Install crate mdbook for building the documentation"
workspace = false
private = true
install_crate = "mdbook"

[tasks.install-trunk]
condition = { env = { "CARGO_REQUIRE_WEB_SUPPORT" = "true" } }
description = "Install crate trunk for WASM support"
workspace = false
private = true
install_crate = "trunk"

[tasks.install-cargo-expand]
description = "Install crate cargo-expand for expanding and inspecting proc macros"
workspace = false
private = true
install_crate = "cargo-expand"

[tasks.install-target-wasm]
condition = { env = { "CARGO_REQUIRE_WEB_SUPPORT" = "true" } }
description = "Adds the wasm32 target"
workspace = false
private = true
command = "rustup"
args = ["target", "add", "wasm32-unknown-unknown"]

[tasks.install-web-support]
condition = { env = { "CARGO_REQUIRE_WEB_SUPPORT" = "true" } }
description = "Installs everything to be able to build for the web"
workspace = false
dependencies = ["install-target-wasm", "install-trunk"]

[tasks.enable-git-hooks]
description = "Enable git hooks by setting the hooksPath to scripts/hooks"
workspace = false
command = "git"
args = ["config", "core.hooksPath", "scripts/hooks"]

[tasks.install-git-lfs]
condition = { env = { "CARGO_REQUIRE_GIT_LFS" = "true" } }
description = "Makes sure the git lfs hooks are enabled in the repository"
private = false
workspace = false
command = "git"
dependencies = ["enable-git-hooks"]
args = ["lfs", "install", "--force"]

## Tasks

[tasks.book-build]
description = "Builds the book for the workspace"
workspace = false
dependencies = ["install-mdbook"]
command = "mdbook"
args = ["build"]

[tasks.book-serve]
description = "Serves the book for editing"
workspace = false
dependencies = ["install-mdbook"]
command = "mdbook"
args = ["serve"]

[tasks.lint-clippy]
description = "Lints the entire workspace"
workspace = false
dependencies = ["install-clippy"]
command = "cargo"
args = [
"clippy",
"--workspace",
"--all-targets",
"--all-features",
"--",
"-D",
"warnings",
]

[tasks.lint-format]
description = "Format checks the entire workspace"
workspace = false
dependencies = ["install-rustfmt"]
command = "cargo"
args = ["fmt", "--all", "--", "--check"]

[tasks.format]
description = "Formats the entire workspace"
workspace = false
dependencies = ["install-rustfmt"]
command = "cargo"
args = ["fmt", "--all", "--", "--emit=files"]

[tasks.each-format]
description = "Formats each project"
dependencies = ["install-rustfmt"]
command = "cargo"
args = ["fmt", "--", "--emit=files"]

[tasks.clean]
description = "Cleans the workspace"
workspace = false
command = "cargo"
args = ["clean"]

[tasks.build]
description = "Builds the entire workspace"
workspace = false
category = "Build"
command = "cargo"
args = ["build", "--workspace", "--all-targets", "--all-features"]

[tasks.each-build]
description = "Build individual projects"
category = "Build"
command = "cargo"
args = ["build", "--all-targets", "--all-features"]

[tasks.test]
description = "Tests the entire workspace"
workspace = false
command = "cargo"
args = ["test", "--workspace", "--all-features"]

[tasks.each-test]
description = "Tests individual projects"
command = "cargo"
args = ["test", "--all-features"]

## Miscellaneous

[tasks.print-env]
description = "Print the environment"
workspace = false
command = "env"

## Scripts

[tasks.script-link-assets]
description = "Run script link_assets.sh"
workspace = false
script = { file = "scripts/link_assets.sh" }

## Flows

[tasks.setup]
description = "Prepares the workspace for development"
workspace = false
dependencies = [
"install-rls",
"install-git-lfs",
"install-clippy",
"install-rustfmt",
"install-mdbook",
"install-cargo-expand",
"install-web-support",
"script-link-assets",
]

[tasks.lint]
description = "Run clippy and format checking in parallel"
workspace = false
run_task = { name = ["lint-format", "lint-clippy"], parallel = true }

[tasks.all]
description = "Run every task"
workspace = false
dependencies = ["setup", "format", "build", "lint", "book-build", "test"]

## Git hooks

[tasks.pre-commit]
description = "Definition of the pre-commit git hook."
workspace = false
dependencies = ["lint-format", "lint"]

[tasks.pre-push]
workspace = false
dependencies = ["test"]
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ as those entities (and their ancestors) are named.
This is especially useful for scenes spawned from GLTF models since you'd need
complex queries to retrieve deep entities from the scene hierarchy.

## Requirements

- [Git LFS](https://git-lfs.github.com/)
- [Latest Rust Stable](https://rustup.rs/)

## Development

This repository is using `cargo-make`, it will take care of installing all
required cargo extensions and rustup components used in this repository.

1. Run `scripts/setup.sh` (Or run `cargo install cargo-make`)
2. (Optional) Install the rest of the tooling/cargo extensions using
`cargo make setup`

### `cargo-make` tasks

- `cargo make all` to run everything that could make ci fail (Everything below)
- `cargo make build` to build all crates
- `cargo make test` to test all crates
- `cargo make format` to format all crates
- `cargo make lint` to lint all crates using `clippy` and `rustfmt`
- `cargo make book-build` to build the documentation book

## Example

Running the example:
Expand Down
3 changes: 0 additions & 3 deletions scripts/enable_git_hooks.sh

This file was deleted.

3 changes: 3 additions & 0 deletions scripts/hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs post-checkout "$@"
3 changes: 3 additions & 0 deletions scripts/hooks/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs post-commit "$@"
3 changes: 3 additions & 0 deletions scripts/hooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs post-merge "$@"
3 changes: 1 addition & 2 deletions scripts/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh

cargo fmt --all -- --check
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo make pre-commit
4 changes: 2 additions & 2 deletions scripts/hooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

cargo test --workspace --all-features
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs pre-push "$@"
28 changes: 28 additions & 0 deletions scripts/link_assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

repo_root=$(git rev-parse --show-toplevel 2> /dev/null)

if [ -z "$repo_root" ]; then
echo "No git repository found."
exit 1
fi

create_symlinks() {
target_dir=$1
if [ -d "$repo_root/$target_dir" ]; then
for dir in "$repo_root/$target_dir"/*/; do
if [ -d "${dir}assets" ]; then
echo "An assets directory already exists at ${dir}. Skipping..."
else
relative_path=$(realpath --relative-to="$dir" "$repo_root/assets")
ln -s "$relative_path" "${dir}assets"
echo "Created symlink for ${dir}assets"
fi
done
else
echo "Directory $target_dir not found."
fi
}

create_symlinks "examples"
create_symlinks "apps"
3 changes: 3 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

cargo install cargo-make

0 comments on commit 1bff5e5

Please sign in to comment.