Skip to content

Commit

Permalink
feat: handle day25 special case
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Dec 26, 2024
1 parent 603fe40 commit 0fdffaa
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/trigger-day-scheduling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ jobs:
DAY_NUMBER: ${{ inputs.day }}
RUSTFLAGS: "-C target-cpu=native"
run: |
if ! cargo build --test test_build ; then
if [ "${{ inputs.day }}" -eq 25 ]; then
BUILD_ARGS="--features day_25"
else
BUILD_ARGS=""
fi
if ! cargo build --test test_build $BUILD_ARGS; then
echo "::warning::The day ${{ inputs.day }} module is missing or malformed. Skipping the run."
echo "valid=false" >> $GITHUB_OUTPUT
else
Expand Down
4 changes: 4 additions & 0 deletions rust-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
name = "rust-runner"
version = "0.1.0"
edition = "2021"
build = "build.rs"

[features]
day_25 = []

[dependencies]
paste = "1.0.0"
Expand Down
9 changes: 9 additions & 0 deletions rust-runner/bench_part2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use rust_runner::{check_result, Output};
use std::hint::black_box;

paste::paste! {
#[cfg(not(day_25))]
use solution::[<day env!("DAY_NUMBER")>]::{part2};
}

#[cfg(not(day_25))]
fn bench_part2(c: &mut Criterion) {
let mut g = c.benchmark_group(concat!("day", env!("DAY_NUMBER")));
let input = include_str!("./input.txt");
Expand All @@ -19,5 +21,12 @@ fn bench_part2(c: &mut Criterion) {
check_result(output, expected, 2);
}

#[cfg(day_25)]
fn bench_part2(c: &mut Criterion) {
let mut g = c.benchmark_group(concat!("day", env!("DAY_NUMBER")));
g.bench_function("part2", |b| b.iter(|| {}));
}


criterion_group!(benches, bench_part2);
criterion_main!(benches);
9 changes: 9 additions & 0 deletions rust-runner/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::env;

fn main() {
if let Ok(day_number) = env::var("DAY_NUMBER") {
if day_number == "25" {
println!("cargo:rustc-cfg=day_25");
}
}
}
2 changes: 2 additions & 0 deletions rust-runner/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
5 changes: 5 additions & 0 deletions rust-runner/test_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
use rust_runner::check_result;

paste::paste! {
#[cfg(not(day_25))]
use solution::[<day env!("DAY_NUMBER")>]::{part1, part2};

#[cfg(day_25)]
use solution::[<day env!("DAY_NUMBER")>]::part1;
}

#[test]
Expand All @@ -13,6 +17,7 @@ fn test_build_part_1() {
check_result(output, expected, 1);
}

#[cfg(not(day_25))]
#[test]
fn test_build_part_2() {
let input = "PLACEHOLDER";
Expand Down

0 comments on commit 0fdffaa

Please sign in to comment.