Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.dot text eol=lf
*.fixed text eol=lf
*.rs text eol=lf
*.sh text eol=lf
*.stderr text eol=lf
*.toml text eol=lf
33 changes: 26 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,45 @@ on:
- 'README.md'
- 'CONTRIBUTING.md'
- '.vscode/**'
workflow_dispatch:

defaults:
run:
shell: bash

jobs:
build:
name: Cargo Test, Clippy and Format
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
# Unsetting this would make so that any malicious package could get our Github Token
persist-credentials: false
- run: cargo fmt --check
- run: cargo test --all
- run: cargo test --all
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Format check
run: cargo fmt --check
- name: Test rpl with embedded patterns
run: cargo test --all
- name: Test rpl with external patterns (actually the same with embedded ones)
run: cargo test --all
env:
RPL_PATS: docs/patterns-pest
- run: cargo clippy -- -D warnings
- run: cargo install --path .
- run: cargo rpl --workspace --all-targets
- name: Run Clippy
run: cargo clippy -- -D warnings
- name: Install rpl
run: cargo install --path . --verbose
- name: Test installed rpl
run: cargo rpl --workspace --all-targets --verbose
# - uses: actions-rust-lang/audit@v1.2.4
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Then, use `cargo +nightly-2025-02-14 rpl` to run RPL in your own repository to d

> Every three months (or so), the toolchain will be updated to the latest nightly version. You can check the current toolchain by running `rustc -V` in the RPL repository.

# Development Setup

When aiming to update the pattern grammar, you should first set your RUSTUP_HOME environment variable, normally `%USERPROFILE%\.rustup` on Windows, so that the build script of `rpl_parser` crate can find the rustfmt binary in your toolchains.

# Tests

- Use `cargo tests` (short for `cargo test --all`) to run all tests.
Expand Down
88 changes: 45 additions & 43 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ color-print = "0.3.4"
anstream = "0.6.0"

[dev-dependencies]
ui_test = "0.29.2"
ui_test = "0.30.4"
tester = "0.9"
regex = "1.5"
toml.workspace = true
Expand Down
37 changes: 27 additions & 10 deletions crates/rpl_parser/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use std::env::VarError;
use std::fs::{File, read_to_string};
use std::io::Write as _;
use std::path::Path;
use std::process::{Command, Stdio};

use quote::quote;

const TOOLCHAIN_PREFIX: &str = "nightly-2025-02-14";

fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo::rerun-if-changed=src/grammar/RPL.pest");

let Some(rustfmt) = find_rustfmt_path()? else {
println!("cargo::warning=Could not find rustfmt for {TOOLCHAIN_PREFIX}, skipping parser generation.");
return Ok(());
};

let parser = {
use pest_typed_generator::derive_typed_parser;
let input = quote! {
Expand All @@ -18,8 +28,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
derive_typed_parser(input.clone(), false, true)
};

let rustfmt = find_rustfmt_path()?;

let child = Command::new(rustfmt)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
Expand All @@ -41,10 +49,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

fn find_rustfmt_path() -> Result<String, Box<dyn std::error::Error>> {
let rustup_home = std::env::var("RUSTUP_HOME")?;
fn find_rustfmt_path() -> Result<Option<String>, Box<dyn std::error::Error>> {
let rustup_home = match std::env::var("RUSTUP_HOME") {
Ok(val) => val,
Err(VarError::NotPresent) => return Ok(None),
Err(e) => return Err(Box::new(e)),
};

let toolchains_dir = format!("{}/toolchains", rustup_home);
let toolchains_dir = Path::new(&rustup_home).join("toolchains");
let toolchains = std::fs::read_dir(toolchains_dir)?
.filter_map(|entry| entry.ok())
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
Expand All @@ -56,16 +68,21 @@ fn find_rustfmt_path() -> Result<String, Box<dyn std::error::Error>> {
.file_stem()
// Remember to update the date in the condition below if you change the nightly toolchain date.
// FIXME: This is a temporary solution to use a specific nightly toolchain.
.is_some_and(|stem| stem.to_str().is_some_and(|stem| stem.starts_with("nightly-2025-02-14")))
.is_some_and(|stem| stem.to_str().is_some_and(|stem| stem.starts_with(TOOLCHAIN_PREFIX)))
{
continue; // Use only the nightly toolchain from 2025-02-14
}
let rustfmt_candidate = toolchain.join("bin/rustfmt");
let rustfmt_executable = if cfg!(windows) { "rustfmt.exe" } else { "rustfmt" };
let rustfmt_candidate = toolchain.join("bin").join(rustfmt_executable);
if rustfmt_candidate.exists() {
return Ok(rustfmt_candidate.to_str().unwrap().to_string());
return Ok(Some(
rustfmt_candidate
.to_str()
.ok_or_else(|| format!("Invalid UTF-8 in rustfmt path {:?}", rustfmt_candidate))?
.to_string(),
));
}
}

let err = "Could not find rustfmt in any toolchain";
Err(err.into())
Ok(None)
}
Loading