initial framework

This commit is contained in:
Thorn Avery 2023-11-30 09:20:44 +11:00
parent fffd510441
commit 7113dce66f
10 changed files with 286 additions and 0 deletions

4
.gitignore vendored Executable file
View file

@ -0,0 +1,4 @@
target
result
.direnv
.envrc

7
Cargo.lock generated Executable file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "taoc2023"
version = "0.0.1"

6
Cargo.toml Executable file
View file

@ -0,0 +1,6 @@
[package]
name = "taoc2023"
version = "0.0.1"
edition = "2021"
[dependencies]

123
flake.lock Normal file
View file

@ -0,0 +1,123 @@
{
"nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1701193254,
"narHash": "sha256-Hr7efA3GjwqBkGYKmd3XmGckdPQikbcCmOrq7fmTp3A=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "43af5fef0591531a72ebb86c5f1c623ee95c62fe",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1701025348,
"narHash": "sha256-42GHmYH+GF7VjwGSt+fVT1CQuNpGanJbNgVHTAZppUM=",
"owner": "ipetkov",
"repo": "crane",
"rev": "42afaeb1a0325194a7cdb526332d2cb92fddd07b",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1701053011,
"narHash": "sha256-8QQ7rFbKFqgKgLoaXVJRh7Ik5LtI3pyBBCfOnNOGkF0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5b528f99f73c4fad127118a8c1126b5e003b01a9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1701137803,
"narHash": "sha256-0LcPAdql5IhQSUXJx3Zna0dYTgdIoYO7zUrsKgiBd04=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "9dd940c967502f844eacea52a61e9596268d4f70",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

119
flake.nix Executable file
View file

@ -0,0 +1,119 @@
{
description = "Thorn Avery's 2023 Advent of Code";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs = { self, nixpkgs, crane, flake-utils, advisory-db, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
# ====================
# == Customise Here ==
# ====================
version = "0.0.1";
pname = "tAoC2023";
# ====================
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
];
};
inherit (pkgs) lib;
myRustTarget = pkgs.rust-bin.stable.latest.default;
craneLib = (crane.mkLib pkgs).overrideToolchain myRustTarget;
src = craneLib.cleanCargoSource (craneLib.path ./.);
commonArgs = {
inherit version pname;
buildInputs = with pkgs; [
pkg-config
openssl
cargo-mommy
cargo-audit
cargo-tarpaulin
cargo-nextest
];
};
cargoArtifacts = craneLib.buildDepsOnly
(commonArgs // { inherit src; });
my-crate = craneLib.buildPackage
(commonArgs // {
inherit src cargoArtifacts;
});
in
{
checks = {
inherit my-crate;
my-crate-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts src;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
my-crate-doc = craneLib.cargoDoc (commonArgs // {
inherit cargoArtifacts src;
});
my-crate-fmt = craneLib.cargoFmt (commonArgs // {
inherit src;
});
my-crate-audit = craneLib.cargoAudit (commonArgs // {
inherit src advisory-db;
});
my-crate-nextest = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts src;
partitions = 1;
partitionType = "count";
});
} // lib.optionalAttrs (system == "x86_64-linux") {
# cargo-tarpaulin only supports x86_64 systems
my-crate-coverage = craneLib.cargoTarpaulin (commonArgs // {
inherit cargoArtifacts src;
});
};
packages.default = my-crate;
apps.default = flake-utils.lib.mkApp {
drv = my-crate;
};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
nativeBuildInputs = with pkgs; [
(pkgs.writeShellScriptBin "cargo" "${myRustTarget}/bin/cargo mommy $@")
myRustTarget
] ++ commonArgs.buildInputs;
};
});
}

3
src/lib.rs Executable file
View file

@ -0,0 +1,3 @@
pub mod utils;
pub mod problems;

10
src/main.rs Executable file
View file

@ -0,0 +1,10 @@
use taoc2023::problems::*;
use taoc2023::utils::timeit;
fn main() {
println!("== day 01 ==");
timeit(|| {
let res = day01::solution();
println!("solution: {res}");
});
}

View file

@ -0,0 +1,3 @@
pub fn solution() -> String {
"<todo>".to_string()
}

1
src/problems/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod day01;

10
src/utils/mod.rs Normal file
View file

@ -0,0 +1,10 @@
use std::time::SystemTime;
pub fn timeit<F: Fn() -> T, T>(f: F) -> T {
let start = SystemTime::now();
let result = f();
let end = SystemTime::now();
let duration = end.duration_since(start).unwrap();
println!("duration: {} milliseconds", duration.as_millis());
result
}