Skip to content

Commit 32f899c

Browse files
committed
feat(2023): init
1 parent 488328a commit 32f899c

File tree

12 files changed

+121
-84
lines changed

12 files changed

+121
-84
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Xcode
33
#
44
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
5+
.direnv/
56

67
## User settings
78
xcuserdata/

2023/01/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "aoc-2023-01"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
aoc-2023-common = { path = "../common/" }

2023/01/input/1.txt

Whitespace-only changes.

2023/01/input/example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello 2023!

2023/01/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use aoc_2023_common::challenge_input;
2+
3+
fn main() {
4+
let input = challenge_input();
5+
println!("{input}");
6+
}

2023/Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2023/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
version = "0.1.0"
3+
4+
members = [
5+
"common",
6+
"01",
7+
]

2023/common/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "aoc-2023-common"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

2023/common/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std::env;
2+
use std::fs;
3+
4+
#[must_use]
5+
pub fn challenge_input() -> String {
6+
let args: Vec<String> = env::args().collect();
7+
let file_path = &args
8+
.get(1)
9+
.expect("⚠️Please pass a path to an input file! ⚠️");
10+
11+
fs::read_to_string(file_path).expect("⚠️Unable to read input file! ⚠️")
12+
}

flake.lock

Lines changed: 31 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
stable = lib.overrideToolchain self'.packages.rust-stable;
2525
};
2626
days = map (pkgs.lib.fixedWidthNumber 2) (pkgs.lib.range 1 15);
27+
days2023 = map (pkgs.lib.fixedWidthNumber 2) (pkgs.lib.range 1 1);
2728
in {
2829
packages = {
2930
rust-stable = inputs'.rust-overlay.packages.rust.override {
3031
extensions = [ "rust-src" "rust-analyzer" "clippy" ];
3132
};
33+
# TODO: generate for each year
3234
} // (builtins.listToAttrs (map (day: {
3335
name = "2022-${day}";
3436
value = let
@@ -43,34 +45,51 @@
4345
'';
4446
};
4547

46-
}) days));
48+
}) days))
49+
// (builtins.listToAttrs (map (day: {
50+
name = "2023-${day}";
51+
value = let
52+
build = let pname = "aoc-2023-${day}"; in crane.stable.buildPackage {
53+
src = ./2023;
54+
cargoBuildCommand = "cargo build --release -p ${pname}";
55+
version = "0.1.0";
56+
inherit pname;
57+
};
58+
in pkgs.writeShellApplication {
59+
name = "aoc-2023-${day}";
60+
text = ''
61+
${build}/bin/aoc-2023-${day} "$@"
62+
'';
63+
};
64+
65+
}) days2023));
4766
apps = {
4867
new-day = {
4968
type = "app";
5069
program = pkgs.writeShellApplication {
5170
name = "new-day";
5271
runtimeInputs = [ self'.packages.rust-stable ];
5372
text = ''
54-
cd 2022
55-
cargo new "$1" --name="aoc-2022-$1"
73+
cd "$1"
74+
cargo new "$2" --name="aoc-$1-$2"
5675
57-
echo "aoc-2022-common = { path = \"../common/\" }" >> ./"$1"/Cargo.toml
76+
echo "aoc-$1-common = { path = \"../common/\" }" >> ./"$2"/Cargo.toml
5877
59-
mkdir "$1"/input
78+
mkdir "$2"/input
6079
61-
touch "$1"/input/example.txt
62-
touch "$1"/input/1.txt
80+
touch "$2"/input/example.txt
81+
touch "$2"/input/1.txt
6382
64-
echo 'use aoc_2022_common::challenge_input;
83+
echo "use aoc_$1_common::challenge_input;
6584
6685
fn main() {
6786
let input = challenge_input();
68-
println!("{input}");
69-
}' > ./"$1"/src/main.rs
87+
println!(\"{input}\");
88+
}" > ./"$2"/src/main.rs
7089
7190
echo "Cargo project created!";
72-
echo "You should add $1 to ./2022/Cargo.toml";
73-
echo "and also add $1 to days in ./flake.nix";
91+
echo "You should add $2 to ./$1/Cargo.toml";
92+
echo "and also add $2 to days in ./flake.nix";
7493
'';
7594
};
7695

0 commit comments

Comments
 (0)