Workflow
This commit is contained in:
218
.github/workflows/rust.yml
vendored
Normal file
218
.github/workflows/rust.yml
vendored
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
name: Rust
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
{
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cargo test",
|
||||||
|
"run": "nix develop --command cargo test --verbose"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
build-release:
|
||||||
|
{
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cargo test (release)",
|
||||||
|
"run": "nix develop --command cargo test --verbose --release"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# shellcheck:
|
||||||
|
# {
|
||||||
|
# "name": "Shellcheck",
|
||||||
|
# "runs-on": "ubuntu-latest",
|
||||||
|
# "steps": [
|
||||||
|
# {
|
||||||
|
# "uses": "actions/checkout@v3",
|
||||||
|
# "name": "Checkout"
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# "name": "Install Nix",
|
||||||
|
# "uses": "cachix/install-nix-action@v17",
|
||||||
|
# "with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# "name": "Run Shellcheck",
|
||||||
|
# "run": "nix develop --command bash -c \"find . -type f -name '*.sh' | xargs shellcheck\""
|
||||||
|
# }
|
||||||
|
# ]
|
||||||
|
# }
|
||||||
|
|
||||||
|
alejandra:
|
||||||
|
{
|
||||||
|
"name": "Nix formatting",
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Run Alejandra",
|
||||||
|
"run": "nix develop .#ci --command alejandra -- --check ."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
rust-fmt:
|
||||||
|
{
|
||||||
|
"name": "Rust formatting",
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Run ShellCheck",
|
||||||
|
"run": "nix develop --command cargo -- fmt --all -- --check"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
{
|
||||||
|
"name": "Clippy",
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Run Clippy",
|
||||||
|
"run": "nix develop --command cargo -- clippy -- -D warnings"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
nix-build:
|
||||||
|
{
|
||||||
|
"name": "Nix build",
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Build app",
|
||||||
|
"run": "nix build"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
nix-run:
|
||||||
|
{
|
||||||
|
"name": "Run app through Nix",
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Run app",
|
||||||
|
"run": "nix run"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
linkcheck:
|
||||||
|
{
|
||||||
|
"name": "Check links",
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"uses": "actions/checkout@v3",
|
||||||
|
"name": "Checkout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Install Nix",
|
||||||
|
"uses": "cachix/install-nix-action@v17",
|
||||||
|
"with": { "extra-nix-config": "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Run link checker",
|
||||||
|
"run": "nix develop .#ci --command markdown-link-check README.md"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
all-required-checks-complete:
|
||||||
|
{
|
||||||
|
"needs":
|
||||||
|
[
|
||||||
|
'nix-build',
|
||||||
|
'nix-run',
|
||||||
|
'build',
|
||||||
|
'build-release',
|
||||||
|
'alejandra',
|
||||||
|
'clippy',
|
||||||
|
'rust-fmt',
|
||||||
|
'linkcheck',
|
||||||
|
# 'shellcheck'
|
||||||
|
],
|
||||||
|
"runs-on": "ubuntu-latest",
|
||||||
|
"steps": [
|
||||||
|
{ "run": "echo \"All required checks complete.\"" }
|
||||||
|
]
|
||||||
|
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 Patrick Stevens
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# The Little Learner, in Rust
|
||||||
|
|
||||||
|
Me running through [The Little Learner](https://www.thelittlelearner.com/), but in Rust instead of Scheme.
|
128
flake.lock
generated
Normal file
128
flake.lock
generated
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"crate2nix": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1678820090,
|
||||||
|
"narHash": "sha256-4FFeonajXNqiSP0PqUlC1wmTyPC8SX6SthEvgRjMupw=",
|
||||||
|
"owner": "kolloch",
|
||||||
|
"repo": "crate2nix",
|
||||||
|
"rev": "4fd826e37bec90dfe26ca16cb6e632c617cc7c0d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "kolloch",
|
||||||
|
"repo": "crate2nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-compat": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1673956053,
|
||||||
|
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1659877975,
|
||||||
|
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1678898370,
|
||||||
|
"narHash": "sha256-xTICr1j+uat5hk9FyuPOFGxpWHdJRibwZC+ATi0RbtE=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "ac718d02867a84b42522a0ece52d841188208f2c",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1665296151,
|
||||||
|
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"crate2nix": "crate2nix",
|
||||||
|
"flake-compat": "flake-compat",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"rust-overlay": "rust-overlay",
|
||||||
|
"utils": "utils"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-overlay": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1679106165,
|
||||||
|
"narHash": "sha256-03Opt2yu4E/AIFjvlgib0/nhMn6B4B/t/nvwS2bzOGw=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "7313c06ac334d6262ddfe30a38b3abc3da6bd565",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1678901627,
|
||||||
|
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
111
flake.nix
Normal file
111
flake.nix
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
{
|
||||||
|
description = "Implementation of The Little Learner";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
utils.url = "github:numtide/flake-utils";
|
||||||
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||||
|
crate2nix = {
|
||||||
|
url = "github:kolloch/crate2nix";
|
||||||
|
flake = false;
|
||||||
|
};
|
||||||
|
flake-compat = {
|
||||||
|
url = "github:edolstra/flake-compat";
|
||||||
|
flake = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = {
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
utils,
|
||||||
|
rust-overlay,
|
||||||
|
crate2nix,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
name = "little_learner";
|
||||||
|
in
|
||||||
|
utils.lib.eachDefaultSystem
|
||||||
|
(
|
||||||
|
system: let
|
||||||
|
# Imports
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
rust-overlay.overlays.default
|
||||||
|
(self: super: {
|
||||||
|
# Because rust-overlay bundles multiple rust packages into one
|
||||||
|
# derivation, specify that mega-bundle here, so that crate2nix
|
||||||
|
# will use them automatically.
|
||||||
|
rustc = self.rust-bin.stable.latest.default;
|
||||||
|
cargo = self.rust-bin.stable.latest.default;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
inherit
|
||||||
|
(import "${crate2nix}/tools.nix" {inherit pkgs;})
|
||||||
|
generatedCargoNix
|
||||||
|
;
|
||||||
|
|
||||||
|
# Create the cargo2nix project
|
||||||
|
project =
|
||||||
|
pkgs.callPackage
|
||||||
|
(generatedCargoNix {
|
||||||
|
inherit name;
|
||||||
|
src = ./.;
|
||||||
|
})
|
||||||
|
{
|
||||||
|
# Individual crate overrides go here
|
||||||
|
# Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50
|
||||||
|
defaultCrateOverrides =
|
||||||
|
pkgs.defaultCrateOverrides
|
||||||
|
// {
|
||||||
|
# The app crate itself is overriden here. Typically we
|
||||||
|
# configure non-Rust dependencies (see below) here.
|
||||||
|
${name} = oldAttrs:
|
||||||
|
{
|
||||||
|
inherit buildInputs nativeBuildInputs;
|
||||||
|
}
|
||||||
|
// buildEnvVars;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Configuration for the non-Rust dependencies
|
||||||
|
buildInputs = with pkgs; [openssl.dev];
|
||||||
|
nativeBuildInputs = with pkgs; [rustc cargo pkgconfig];
|
||||||
|
buildEnvVars = {
|
||||||
|
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
|
||||||
|
};
|
||||||
|
in rec {
|
||||||
|
packages.${name} = project.rootCrate.build;
|
||||||
|
|
||||||
|
# `nix build`
|
||||||
|
defaultPackage = packages.${name};
|
||||||
|
|
||||||
|
# `nix run`
|
||||||
|
apps.${name} = utils.lib.mkApp {
|
||||||
|
inherit name;
|
||||||
|
drv = packages.${name};
|
||||||
|
};
|
||||||
|
defaultApp = apps.${name};
|
||||||
|
|
||||||
|
# `nix develop`
|
||||||
|
devShells = {
|
||||||
|
ci =
|
||||||
|
pkgs.mkShell {
|
||||||
|
inherit nativeBuildInputs;
|
||||||
|
buildInputs = [pkgs.nodePackages.markdown-link-check pkgs.alejandra] ++ buildInputs;
|
||||||
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
|
}
|
||||||
|
// buildEnvVars;
|
||||||
|
default =
|
||||||
|
pkgs.mkShell
|
||||||
|
{
|
||||||
|
inherit buildInputs nativeBuildInputs;
|
||||||
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
|
}
|
||||||
|
// buildEnvVars;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user