merged nix builder into repo
This commit is contained in:
		
							parent
							
								
									87f53eb424
								
							
						
					
					
						commit
						784cdd6268
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1 +1,2 @@
 | 
			
		|||
/target
 | 
			
		||||
target
 | 
			
		||||
result
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -207,7 +207,7 @@ dependencies = [
 | 
			
		|||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "tAoC2022"
 | 
			
		||||
name = "taoc2022"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "clap",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
[package]
 | 
			
		||||
name = "tAoC2022"
 | 
			
		||||
name = "taoc2022"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
edition = "2021"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										140
									
								
								flake.lock
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								flake.lock
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,140 @@
 | 
			
		|||
{
 | 
			
		||||
  "nodes": {
 | 
			
		||||
    "advisory-db": {
 | 
			
		||||
      "flake": false,
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1669846878,
 | 
			
		||||
        "narHash": "sha256-2ks8+eP/MuH07KGUR7zO/cSRPyoYJIPQHDsj+hveN/U=",
 | 
			
		||||
        "owner": "rustsec",
 | 
			
		||||
        "repo": "advisory-db",
 | 
			
		||||
        "rev": "b80f8edaa7e5ce5a6babcd61f14dddee77875c2c",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "rustsec",
 | 
			
		||||
        "repo": "advisory-db",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "crane": {
 | 
			
		||||
      "inputs": {
 | 
			
		||||
        "flake-compat": "flake-compat",
 | 
			
		||||
        "flake-utils": "flake-utils",
 | 
			
		||||
        "nixpkgs": [
 | 
			
		||||
          "nixpkgs"
 | 
			
		||||
        ],
 | 
			
		||||
        "rust-overlay": "rust-overlay"
 | 
			
		||||
      },
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1669605882,
 | 
			
		||||
        "narHash": "sha256-TiQtL5sUI5rp28S63v+VX25qNjcrc8Xeu+shf3g7Tj4=",
 | 
			
		||||
        "owner": "ipetkov",
 | 
			
		||||
        "repo": "crane",
 | 
			
		||||
        "rev": "24591d5f8cc979f7b243b88a2d39da09976970ad",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "ipetkov",
 | 
			
		||||
        "repo": "crane",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "flake-compat": {
 | 
			
		||||
      "flake": false,
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1650374568,
 | 
			
		||||
        "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
 | 
			
		||||
        "owner": "edolstra",
 | 
			
		||||
        "repo": "flake-compat",
 | 
			
		||||
        "rev": "b4a34015c698c7793d592d66adbab377907a2be8",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "edolstra",
 | 
			
		||||
        "repo": "flake-compat",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "flake-utils": {
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1667395993,
 | 
			
		||||
        "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
 | 
			
		||||
        "owner": "numtide",
 | 
			
		||||
        "repo": "flake-utils",
 | 
			
		||||
        "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "numtide",
 | 
			
		||||
        "repo": "flake-utils",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "flake-utils_2": {
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1667395993,
 | 
			
		||||
        "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
 | 
			
		||||
        "owner": "numtide",
 | 
			
		||||
        "repo": "flake-utils",
 | 
			
		||||
        "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "numtide",
 | 
			
		||||
        "repo": "flake-utils",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "nixpkgs": {
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1669900182,
 | 
			
		||||
        "narHash": "sha256-EKxjHxRJnP1w+2nnm8pq4Uqkqa5McnfPXcO8cG8Mxzc=",
 | 
			
		||||
        "owner": "NixOS",
 | 
			
		||||
        "repo": "nixpkgs",
 | 
			
		||||
        "rev": "bcb6dbbe30ce7631e5a0865dff1ab9b63d92977d",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "NixOS",
 | 
			
		||||
        "ref": "nixpkgs-unstable",
 | 
			
		||||
        "repo": "nixpkgs",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "root": {
 | 
			
		||||
      "inputs": {
 | 
			
		||||
        "advisory-db": "advisory-db",
 | 
			
		||||
        "crane": "crane",
 | 
			
		||||
        "flake-utils": "flake-utils_2",
 | 
			
		||||
        "nixpkgs": "nixpkgs"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "rust-overlay": {
 | 
			
		||||
      "inputs": {
 | 
			
		||||
        "flake-utils": [
 | 
			
		||||
          "crane",
 | 
			
		||||
          "flake-utils"
 | 
			
		||||
        ],
 | 
			
		||||
        "nixpkgs": [
 | 
			
		||||
          "crane",
 | 
			
		||||
          "nixpkgs"
 | 
			
		||||
        ]
 | 
			
		||||
      },
 | 
			
		||||
      "locked": {
 | 
			
		||||
        "lastModified": 1667487142,
 | 
			
		||||
        "narHash": "sha256-bVuzLs1ZVggJAbJmEDVO9G6p8BH3HRaolK70KXvnWnU=",
 | 
			
		||||
        "owner": "oxalica",
 | 
			
		||||
        "repo": "rust-overlay",
 | 
			
		||||
        "rev": "cf668f737ac986c0a89e83b6b2e3c5ddbd8cf33b",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      },
 | 
			
		||||
      "original": {
 | 
			
		||||
        "owner": "oxalica",
 | 
			
		||||
        "repo": "rust-overlay",
 | 
			
		||||
        "type": "github"
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "root": "root",
 | 
			
		||||
  "version": 7
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										98
									
								
								flake.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								flake.nix
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,98 @@
 | 
			
		|||
{
 | 
			
		||||
  description = "tAoC2022 - Nix Builder";
 | 
			
		||||
 | 
			
		||||
  inputs = {
 | 
			
		||||
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
 | 
			
		||||
    crane = {
 | 
			
		||||
      url = "github:ipetkov/crane";
 | 
			
		||||
      inputs.nixpkgs.follows = "nixpkgs";
 | 
			
		||||
    };
 | 
			
		||||
    flake-utils.url = "github:numtide/flake-utils";
 | 
			
		||||
    advisory-db = {
 | 
			
		||||
      url = "github:rustsec/advisory-db";
 | 
			
		||||
      flake = false;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    # my rust project
 | 
			
		||||
    # taoc2022 = {
 | 
			
		||||
    #   url = "git+ssh://gitea@git.p7.co.nz/thornAvery/tAoC2022";
 | 
			
		||||
    #   flake = false;
 | 
			
		||||
    # };
 | 
			
		||||
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }:
 | 
			
		||||
    flake-utils.lib.eachDefaultSystem (system:
 | 
			
		||||
      let
 | 
			
		||||
        pkgs = import nixpkgs {
 | 
			
		||||
          inherit system;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        inherit (pkgs) lib;
 | 
			
		||||
 | 
			
		||||
        craneLib = crane.lib.${system};
 | 
			
		||||
        src = ./.;
 | 
			
		||||
 | 
			
		||||
        buildInputs = [
 | 
			
		||||
        ] ++ lib.optionals pkgs.stdenv.isDarwin [
 | 
			
		||||
          pkgs.libiconv
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        cargoArtifacts = craneLib.buildDepsOnly {
 | 
			
		||||
          inherit src buildInputs;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        my-crate = craneLib.buildPackage {
 | 
			
		||||
          inherit cargoArtifacts src buildInputs;
 | 
			
		||||
        };
 | 
			
		||||
      in
 | 
			
		||||
      {
 | 
			
		||||
        checks = {
 | 
			
		||||
          inherit my-crate;
 | 
			
		||||
 | 
			
		||||
          my-crate-clippy = craneLib.cargoClippy {
 | 
			
		||||
            inherit cargoArtifacts src buildInputs;
 | 
			
		||||
            cargoClippyExtraArgs = "--all-targets -- --deny warnings";
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          my-crate-doc = craneLib.cargoDoc {
 | 
			
		||||
            inherit cargoArtifacts src;
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          my-crate-fmt = craneLib.cargoFmt {
 | 
			
		||||
            inherit src;
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          my-crate-audit = craneLib.cargoAudit {
 | 
			
		||||
            inherit src advisory-db;
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          my-crate-nextest = craneLib.cargoNextest {
 | 
			
		||||
            inherit cargoArtifacts src buildInputs;
 | 
			
		||||
            partitions = 1;
 | 
			
		||||
            partitionType = "count";
 | 
			
		||||
          };
 | 
			
		||||
        } // lib.optionalAttrs (system == "x86_64-linux") {
 | 
			
		||||
          # cargo-tarpaulin only supports x86_64 systems
 | 
			
		||||
          my-crate-coverage = craneLib.cargoTarpaulin {
 | 
			
		||||
            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; [
 | 
			
		||||
            cargo
 | 
			
		||||
            rustc
 | 
			
		||||
            rust-analyzer
 | 
			
		||||
          ];
 | 
			
		||||
        };
 | 
			
		||||
      });
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,3 +1,2 @@
 | 
			
		|||
#![allow(non_snake_case)]
 | 
			
		||||
pub mod problem01;
 | 
			
		||||
pub mod problem02;
 | 
			
		||||
pub mod problem_01;
 | 
			
		||||
pub mod problem_02;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/main.rs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1,11 +1,11 @@
 | 
			
		|||
use tAoC2022::problem01;
 | 
			
		||||
use tAoC2022::problem02;
 | 
			
		||||
use taoc2022::problem_01;
 | 
			
		||||
use taoc2022::problem_02;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    println!("== Problem 01 ==");
 | 
			
		||||
    println!("= a: {}", problem01::solutionA());
 | 
			
		||||
    println!("= b: {}", problem01::solutionB());
 | 
			
		||||
    println!("= a: {}", problem_01::solution_a());
 | 
			
		||||
    println!("= b: {}", problem_01::solution_b());
 | 
			
		||||
    println!("== Problem 02 ==");
 | 
			
		||||
    println!("= a: {}", problem02::solutionA());
 | 
			
		||||
    println!("= b: {}", problem02::solutionB());
 | 
			
		||||
    println!("= a: {}", problem_02::solution_a());
 | 
			
		||||
    println!("= b: {}", problem_02::solution_b());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +0,0 @@
 | 
			
		|||
static INPUT: &'static str = include_str!("input.txt");
 | 
			
		||||
 | 
			
		||||
pub fn solutionA() -> i32 {
 | 
			
		||||
    0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn solutionB() -> i32 {
 | 
			
		||||
    0
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,10 +1,10 @@
 | 
			
		|||
static INPUT: &'static str = include_str!("input.txt");
 | 
			
		||||
static INPUT: &str = include_str!("input.txt");
 | 
			
		||||
 | 
			
		||||
fn solution(x: i32) -> i32 {
 | 
			
		||||
    let mut totals = vec![Default::default(); x.try_into().unwrap()];
 | 
			
		||||
    let mut total = 0;
 | 
			
		||||
    for line in INPUT.lines() {
 | 
			
		||||
        if line == "" {
 | 
			
		||||
        if line.is_empty() {
 | 
			
		||||
            add_to_total(&mut totals, total);
 | 
			
		||||
            total = 0;
 | 
			
		||||
        } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -15,21 +15,19 @@ fn solution(x: i32) -> i32 {
 | 
			
		|||
    return totals.iter().sum();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn add_to_total(totals: &mut Vec<i32>, total: i32) {
 | 
			
		||||
fn add_to_total(totals: &mut [i32], total: i32) {
 | 
			
		||||
    let mut i = total;
 | 
			
		||||
    for n in totals.iter_mut() {
 | 
			
		||||
        if i > *n {
 | 
			
		||||
            let tmp = *n;
 | 
			
		||||
            *n = i;
 | 
			
		||||
            i = tmp;
 | 
			
		||||
            std::mem::swap(&mut (*n), &mut i);
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn solutionA() -> i32 {
 | 
			
		||||
    return solution(1);
 | 
			
		||||
pub fn solution_a() -> i32 {
 | 
			
		||||
    solution(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn solutionB() -> i32 {
 | 
			
		||||
    return solution(3);
 | 
			
		||||
pub fn solution_b() -> i32 {
 | 
			
		||||
    solution(3)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								src/problem_02/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/problem_02/mod.rs
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
// static INPUT: &'static str = include_str!("input.txt");
 | 
			
		||||
 | 
			
		||||
pub fn solution_a() -> i32 {
 | 
			
		||||
    0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn solution_b() -> i32 {
 | 
			
		||||
    0
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in a new issue