Skip to content

Commit

Permalink
Merge pull request #687 from tweag/erin/nix-cleanup
Browse files Browse the repository at this point in the history
chore: add our scripts to our flake.nix
  • Loading branch information
Erin van der Veen authored Apr 4, 2024
2 parents f21ce70 + 18fd74a commit 7595ac7
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: nix build .#client-app

- name: Verify that usage in README.md matches CLI output
run: ./verify-documented-usage.sh
run: nix run .#verify-documented-usage

- name: Build web playground Wasm app
if: success() && matrix.os == 'ubuntu-latest'
Expand Down
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ grcov --branch \

:warning: `grcov` relies on the `llvm-tools-preview` component for
`rustup`. For Nix users, `rustup` can interfere with the Rust toolchain
that is provided by Nix, if you have both installed. For convenience,
the `generate-coverage.sh` script can be run from the root of this
repository to avoid contaminating your environment, but note it will
download a full toolchain on each run.
that is provided by Nix, if you have both installed.

## Web site and web playground

Expand Down
56 changes: 56 additions & 0 deletions bin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{ pkgs, writeShellApplication }:
{
# FIXME: Broken
# TODO: Don't use rustup to install these components but just use Nix
# generate-coverage = writeShellApplication {
# name = "generate-coverage";

# runtimeInputs = with pkgs; [
# cacert
# grcov
# rustup
# ];

# text = builtins.readFile ./generate-coverage.sh;
# };

playground = writeShellApplication {
name = "playground";

runtimeInputs = with pkgs; [
inotify-tools
];

text = builtins.readFile ./playground.sh;
};

update-wasm-app = writeShellApplication {
name = "update-wasm-app";

text = builtins.readFile ./update-wasm-app.sh;
};

update-wasm-grammars = writeShellApplication {
name = "update-wasm-grammars";

runtimeInputs = with pkgs; [
emscripten
git
toml2json
tree-sitter
];

text = builtins.readFile ./update-wasm-grammars.sh;
};

verify-documented-usage = writeShellApplication {
name = "verify-documented-usage";

runtimeInputs = with pkgs; [
diffutils
gnused
];

text = builtins.readFile ./verify-documented-usage.sh;
};
}
18 changes: 12 additions & 6 deletions generate-coverage.sh → bin/generate-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash --pure --packages cacert grcov rustup
#!/usr/bin/env bash
#shellcheck shell=bash

set -eu

# Create temporary working directory
readonly WORKING_DIR="$(mktemp --directory)"
WORKING_DIR="$(mktemp --directory)"
readonly WORKING_DIR

trap 'rm -rf "${WORKING_DIR}"' EXIT

# Setup subdirectories for rustup and the profile data
export RUSTUP_HOME="${WORKING_DIR}/rustup"
readonly PROFRAW_DIR="${WORKING_DIR}/profraw"
RUSTUP_HOME="${WORKING_DIR}/rustup"
export RUSTUP_HOME

PROFRAW_DIR="${WORKING_DIR}/profraw"
readonly PROFRAW_DIR

mkdir --parents "${RUSTUP_HOME}" "${PROFRAW_DIR}"

# Install Rust toolchain and necessary components
Expand All @@ -24,7 +29,8 @@ LLVM_PROFILE_FILE="${PROFRAW_DIR}/cargo-test-%p-%m.profraw" \
cargo test

# Render HTML coverage report
readonly REPORT_DIR="target/coverage/html"
REPORT_DIR="target/coverage/html"
readonly REPORT_DIR
mkdir --parents "${REPORT_DIR}"
grcov --branch \
--output-type html \
Expand Down
6 changes: 3 additions & 3 deletions playground.sh → bin/playground.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash --packages inotify-tools
#!/usr/bin/env bash
#shellcheck shell=bash

# "Quick-and-Dirty" Topiary Playground

set -euo pipefail

readonly PROGNAME="$(basename "$0")"
PROGNAME="$(basename "$0")"
readonly PROGNAME

fail() {
local error="$*"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 21 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,29 @@

craneLib = crane.mkLib pkgs;

code = pkgs.callPackage ./default.nix { inherit advisory-db crane rust-overlay nix-filter craneLib; };
topiaryPkgs = pkgs.callPackage ./default.nix { inherit advisory-db crane rust-overlay nix-filter craneLib; };
binPkgs = pkgs.callPackage ./bin/default.nix { };
in
{
packages = with code; {
inherit topiary-playground topiary-queries client-app;
default = topiary-cli;
packages = {
inherit (topiaryPkgs)
topiary-playground
topiary-queries
client-app;

inherit (binPkgs)
# FIXME: Broken
# generate-coverage
playground
update-wasm-app
update-wasm-grammars
verify-documented-usage;

default = topiaryPkgs.topiary-cli;
};

checks = {
inherit (code) clippy clippy-wasm fmt topiary-core topiary-cli topiary-playground audit benchmark;
inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-cli topiary-playground audit benchmark;

## Check that the `lib.pre-commit-hook` output builds/evaluates
## correctly. `deepSeq e1 e2` evaluates `e1` strictly in depth before
Expand All @@ -60,16 +73,16 @@
};

devShells = {
default = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; inherit craneLib; };
wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = code.passtru.craneLibWasm; };
default = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; inherit craneLib; inherit binPkgs; };
wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = topiaryPkgs.passtru.craneLibWasm; inherit binPkgs; };
};

## For easy use in https://github.com/cachix/pre-commit-hooks.nix
lib.pre-commit-hook = {
enable = true;
name = "topiary";
description = "A general code formatter based on tree-sitter.";
entry = "${code.topiary-cli}/bin/topiary fmt";
entry = "${topiaryPkgs.topiary-cli}/bin/topiary fmt";
types = [ "text" ];
};
}
Expand Down
28 changes: 11 additions & 17 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
# Allows `nix-shell` without having to go trough the trouble of pinning the same
# version as is done by the flake.
{ pkgs ? import <nixpkgs> { }
{ pkgs
, checks ? { }
, craneLib
, binPkgs
}:
let
update-wasm-grammars = pkgs.writeShellApplication {
name = "update-wasm-grammars";

runtimeInputs = with pkgs; [
emscripten
git
toml2json
tree-sitter
];

text = builtins.readFile ./update-wasm-grammars.sh;
};
in
craneLib.devShell {
inherit checks;

packages = with pkgs; [
update-wasm-grammars
packages = with pkgs; with binPkgs; [
cargo-flamegraph
rust-analyzer

# Our own scripts
# FIXME: Broken
# generate-coverage
playground
update-wasm-app
update-wasm-grammars
verify-documented-usage
];
}

0 comments on commit 7595ac7

Please sign in to comment.