Skip to content

Commit

Permalink
feat: add cargo-generate integration
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Jul 29, 2024
1 parent 7100e9e commit 75c491c
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ jobs:
- name: Setup | Checkout
uses: actions/checkout@v2

- name: Setup | Generate
uses: cargo-generate/[email protected]
with:
name: vexide-template

- name: Setup | Toolchain
uses: dtolnay/rust-toolchain@master
with:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
Expand Down Expand Up @@ -94,4 +94,4 @@ $RECYCLE.BIN/
*.vsix

# Direnv
.direnv/
.direnv/
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ edition = "2021"

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

{% if crate_type == "bin" %}
# These fields configure default behavior for uploads with `cargo v5`.
[package.metadata.v5]
slot = 1
icon = "cool-x"
{% if slot != "none" %}
slot = {{ slot }}
{% endif %}
icon = "{{ icon }}"
compress = true
{% endif %}

[dependencies]
vexide = "0.3.0"
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# vexide Template

<!--{% if false %}-->
[![Build status](https://github.com/vexide/vexide-template/actions/workflows/build.yml/badge.svg)](https://github.com/vexide/vexide-template/actions/workflows/build.yml)
<!--{% endif %}-->

> Ready-to-use template for developing VEX V5 robots in Rust.
Expand All @@ -21,28 +23,28 @@ Seasoned vexide user? Delete README.md and update Cargo.toml as needed.
- [Compiling and uploading to a VEX V5 robot](#compiling-and-uploading-to-a-vex-v5-robot)
- [Viewing program output](#viewing-program-output)

<!--{% if false %}-->
## Using This Template

To start a project using this template, click the "Use this template" button in the upper right corner of the GitHub repository. Choose an appropriate name and clone the new repository using Git. Finally, update the package name in `Cargo.toml`:
This template uses `cargo-generate`, which can be installed with the following command:

```toml
[package]
name = "my-vex-robot"
version = "0.1.0"
edition = "2021"
```sh
cargo install cargo-generate
```

You can also configure your program slot and upload behavior in `Cargo.toml`:
Create a new vexide project by then running the following command:

```toml
[package.metadata.v5]
slot = 1
icon = "cool-x"
compress = true
```sh
cargo generate vexide/vexide-template
```

> See our [Building & Uploading tutorial](https://vexide.dev/docs/building-uploading/) for more information.
Or, make a library instead:

```sh
cargo generate vexide/vexide-template --lib
```

<!--{% endif %}-->
## Getting Started (Windows)

Follow the instructions [here](https://www.rust-lang.org/tools/install) to install `rustup`.
Expand Down
50 changes: 50 additions & 0 deletions cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[template]
cargo_generate_version = ">=0.9.0"
ignore = ["target", ".DS_Store"] # ideally this would include all of .gitignore

[conditional.'crate_type == "lib"']
ignore = ["src/main.rs"]

[conditional.'crate_type == "bin"']
ignore = ["src/lib.rs"]

[placeholders]
use_ci = { prompt = "Use recommended GitHub CI configuration?", default = true, type = "bool" }

[conditional.'crate_type == "bin"'.placeholders]
slot = { prompt = "Choose a default program slot (1-8/none):", default = "1", type = "string", regex = "^([1-8]|none)$" }

[conditional.'crate_type == "bin"'.placeholders.icon]
prompt = "Choose an icon for the program:"
default = "cool-x"
type = "string"
choices = [
"cool-x",
"vex-coding-studio",
"question-mark",
"pizza",
"clawbot",
"robot",
"power-button",
"planets",
"alien",
"alien-in-ufo",
"cup-in-field",
"cup-and-ball",
"matlab",
"pros",
"robot-mesh",
"robot-mesh-cpp",
"robot-mesh-blockly",
"robot-mesh-flowol",
"robot-mesh-js",
"robot-mesh-py",
"code-file",
"vexcode-brackets",
"vexcode-blocks",
"vexcode-python",
"vexcode-cpp",
]

[hooks]
post = ["scripts/ci.rhai"]
30 changes: 30 additions & 0 deletions scripts/ci.rhai
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if variable::get("use_ci") {
debug("Generating GitHub CI configuration...");
file::write(".github/workflows/build.yml", `
name: Build

on: [push, pull_request]

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/checkout@v2

- name: Setup | Toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-02-07
components: rust-src

- name: Check
uses: actions-rs/cargo@v1
with:
command: check
`);
} else {
debug("Skipping GitHub CI configuration...");
file::delete(".github");
}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_std]

use vexide::prelude::*;

pub fn revolve(left: Position, right: Position) -> Position {
left + right
}

0 comments on commit 75c491c

Please sign in to comment.