Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44e3072
commit d7c5399
Showing
27 changed files
with
1,172 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
set -x | ||
IFS=$'\n\t' | ||
|
||
cd "$(git rev-parse --show-toplevel)" | ||
|
||
for project in *.hsfiles; do | ||
nix-shell --pure --packages stack --run "stack new inst \"${project}\"" | ||
|
||
cd inst | ||
|
||
if [[ -f "shell.nix" ]]; then | ||
# Build and test with nix. Note that nix-build already runs the tests, | ||
# but we'd also like to be able to run them using just cabal in a shell. | ||
nix-build | ||
cabal="cabal --write-ghc-environment-files=always" | ||
nix-shell --pure --run "$cabal run clash -- Example.Project --vhdl" | ||
nix-shell --pure --run "$cabal run doctests" | ||
nix-shell --pure --run "$cabal run test-library" | ||
fi | ||
|
||
# Clean up | ||
cd .. | ||
rm -rf inst | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
set -x | ||
IFS=$'\n\t' | ||
|
||
cd "$(git rev-parse --show-toplevel)" | ||
|
||
for project in *.hsfiles; do | ||
stack new inst "${project}" | ||
|
||
cd inst | ||
|
||
# Build and test with Stack | ||
stack build | ||
stack test | ||
stack run clash -- Example.Project --vhdl | ||
|
||
# Clean up | ||
cd .. | ||
rm -rf inst | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,59 @@ | ||
tests: | ||
image: docker.pkg.github.com/clash-lang/stack-templates/focal-ghc-cabal-stack:2020-11-25 | ||
stages: | ||
- check | ||
- test | ||
- publish | ||
|
||
.common: | ||
image: docker.pkg.github.com/clash-lang/stack-templates/focal-ghc-cabal-stack:2020-11-28 | ||
timeout: 2 hours | ||
stage: test | ||
retry: | ||
max: 2 | ||
when: | ||
- runner_system_failure | ||
- stuck_or_timeout_failure | ||
tags: | ||
- local | ||
before_script: | ||
- tar -xf cache.tar.zstd -C / || true | ||
after_script: | ||
- bash -c "tar -cf - $(ls -d /root/.cabal /root/.stack /nix) | zstd -T0 -7 > cache.tar.zstd" || true | ||
cache: | ||
key: cabal-stack-$CI_JOB_NAME | ||
when: always | ||
key: $CI_JOB_NAME | ||
paths: | ||
- cache.tar.xz | ||
script: | ||
# Extract cache | ||
- tar -xf cache.tar.xz -C / || true | ||
- cache.tar.zstd | ||
|
||
# Tests | ||
# Use ./render and check for changes | ||
render: | ||
extends: .common | ||
stage: check | ||
script: | ||
- .ci/render_and_check.sh | ||
- .ci/test_projects.sh | ||
- .ci/publish.sh ${CI_COMMIT_REF_NAME} | ||
|
||
# Save cache | ||
- XZ_OPT="-T 0 -1" tar -Ixz -cf cache.tar.xz /root/.cabal /root/.stack | ||
tags: | ||
- local | ||
# Build and test with Cabal | ||
cabal: | ||
extends: .common | ||
script: | ||
- .ci/test_projects_cabal.sh | ||
|
||
# Build and test with Stack | ||
stack: | ||
extends: .common | ||
script: | ||
- .ci/test_projects_stack.sh | ||
|
||
# Build and test with Nix | ||
nix: | ||
extends: .common | ||
image: docker.pkg.github.com/clash-lang/stack-templates/nixos-xz-git:2020-11-28 | ||
script: | ||
- bash .ci/test_projects_nix.sh | ||
|
||
# If all tests pass, publish to 'clash-lang/clash-starters'. | ||
publish: | ||
stage: publish | ||
script: | ||
- .ci/publish.sh | ||
only: | ||
refs: | ||
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM nixos/nix | ||
|
||
# Compression utils | ||
RUN nix-channel --add https://channels.nixos.org/nixos-20.09 nixos \ | ||
&& nix-channel --update \ | ||
&& nix-env -iA nixos.git \ | ||
&& nix-env -iA nixos.gnutar \ | ||
&& nix-env -iA nixos.lzma \ | ||
&& nix-env -iA nixos.zstd \ | ||
&& nix-env -iA nixos.bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -xeo pipefail | ||
|
||
REPO="docker.pkg.github.com/clash-lang/stack-templates" | ||
NAME="nixos-xz-git" | ||
DIR=$(dirname "$0") | ||
now=$(date +%F) | ||
|
||
docker build -t "${REPO}/${NAME}:$now" "$DIR" | ||
docker tag "${REPO}/${NAME}:$now" "${REPO}/${NAME}:latest" | ||
|
||
read -p "Push to GitHub? (y/N) " push | ||
|
||
if [[ $push =~ ^[Yy]$ ]]; then | ||
docker push "${REPO}/${NAME}:$now" | ||
docker push "${REPO}/${NAME}:latest" | ||
else | ||
echo "Skipping push to container registry" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../simple/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!-- omit in toc --> | ||
# Simple Nix Starter Project | ||
This starter project contains the scaffolding needed to integrate Clash with the Nix Stack build system. Read [Simple Starter Project](https://github.com/clash-lang/clash-starters/blob/main/simple/README.md) for more information on the various files. | ||
|
||
<!-- omit in toc --> | ||
# Table of Contents | ||
- [Getting this project](#getting-this-project) | ||
- [Building and testing this project](#building-and-testing-this-project) | ||
- [REPL](#repl) | ||
- [Adding custom dependencies / updating nix](#adding-custom-dependencies--updating-nix) | ||
|
||
# Getting this project | ||
Run `nix-shell --packages stack --run "stack new my-clash-project clash-lang/simple-nix"`. | ||
|
||
# Building and testing this project | ||
Build the project with: | ||
|
||
```bash | ||
nix-build | ||
``` | ||
|
||
To test and generate HDL, first open a Nix shell by invoking: | ||
|
||
``` | ||
nix-shell | ||
``` | ||
|
||
Then, to run the tests defined in `tests/`: | ||
|
||
```bash | ||
cabal run test-library | ||
cabal run doctests | ||
``` | ||
|
||
To compile the project to VHDL run: | ||
|
||
```bash | ||
cabal run clash --write-ghc-environment-files=always -- Example.Project --vhdl | ||
``` | ||
|
||
You can find the HDL files in `vhdl/`. The source can be found in `src/Example/Project.hs`. | ||
|
||
# REPL | ||
Clash offers a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) as a quick way to try things, similar to Python's `python` or Ruby's `irb`. Open the REPL by invoking: | ||
|
||
``` | ||
cabal run --write-ghc-environment-files=always clashi | ||
``` | ||
|
||
# Adding custom dependencies / updating nix | ||
`niv` is available after opening `nix-shell`. See [niv on Hackage](https://hackage.haskell.org/package/niv) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../simple/Setup.hs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../simple/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ nixpkgs ? import ./nix/nixpkgs.nix {} }: | ||
|
||
with nixpkgs.pkgs; | ||
with gitignore; | ||
|
||
haskellPackages.callCabal2nix "{{name}}" (gitignoreSource ./.) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ sources ? import ./sources.nix }: | ||
|
||
let | ||
overlay = _: pkgs: { | ||
|
||
# Nix tooling | ||
niv = (import sources.niv {}).niv; | ||
gitignore = import sources.gitignore { inherit (pkgs) lib; }; | ||
|
||
# Haskell overrides | ||
haskellPackages = pkgs.haskellPackages.override { | ||
overrides = self: super: { | ||
# Add overrides here | ||
}; | ||
}; | ||
}; | ||
|
||
in import sources.nixpkgs { overlays = [ overlay ]; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"gitignore": { | ||
"branch": "master", | ||
"description": "Nix function for filtering local git sources", | ||
"homepage": "", | ||
"owner": "hercules-ci", | ||
"repo": "gitignore", | ||
"rev": "c4662e662462e7bf3c2a968483478a665d00e717", | ||
"sha256": "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx", | ||
"type": "tarball", | ||
"url": "https://github.com/hercules-ci/gitignore/archive/c4662e662462e7bf3c2a968483478a665d00e717.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
}, | ||
"niv": { | ||
"branch": "master", | ||
"description": "Easy dependency management for Nix projects", | ||
"homepage": "https://github.com/nmattia/niv", | ||
"owner": "nmattia", | ||
"repo": "niv", | ||
"rev": "ba57d5a29b4e0f2085917010380ef3ddc3cf380f", | ||
"sha256": "1kpsvc53x821cmjg1khvp1nz7906gczq8mp83664cr15h94sh8i4", | ||
"type": "tarball", | ||
"url": "https://github.com/nmattia/niv/archive/ba57d5a29b4e0f2085917010380ef3ddc3cf380f.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
}, | ||
"nixpkgs": { | ||
"branch": "nixos-20.09", | ||
"description": "Nix Packages collection", | ||
"homepage": "", | ||
"owner": "NixOS", | ||
"repo": "nixpkgs", | ||
"rev": "ffb3aab257e8851b558cdc6079241a7eb0c7239e", | ||
"sha256": "147d4nsq0334skyr9rghcfnizasvba1pr2rq72axwdldlma0qli1", | ||
"type": "tarball", | ||
"url": "https://github.com/NixOS/nixpkgs/archive/ffb3aab257e8851b558cdc6079241a7eb0c7239e.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
} | ||
} |
Oops, something went wrong.