mirror of https://github.com/tinygo-org/tinygo.git
Browse Source
This adds a flake.nix file that makes it possible to quickly create a development environment. You can download Nix here, for use on your Linux or macOS system: https://nixos.org/download.html After you have installed Nix, you can enter the development environment as follows: nix develop This drops you into a bash shell, where you can install TinyGo simply using the following command: go install That's all! Assuming you've set up your $PATH correctly, you can now use the tinygo command as usual: tinygo version You can also do many other things from this environment. Building and flashing should work as you're used to: it's not a VM or container so there are no access restrictions.pull/3949/head
Ayke van Laethem
1 year ago
committed by
Ron Evans
5 changed files with 185 additions and 2 deletions
@ -0,0 +1,43 @@ |
|||||
|
name: Nix |
||||
|
|
||||
|
on: |
||||
|
pull_request: |
||||
|
push: |
||||
|
branches: |
||||
|
- dev |
||||
|
- release |
||||
|
|
||||
|
concurrency: |
||||
|
group: ${{ github.workflow }}-${{ github.ref }} |
||||
|
cancel-in-progress: true |
||||
|
|
||||
|
jobs: |
||||
|
nix-test: |
||||
|
runs-on: ubuntu-latest |
||||
|
steps: |
||||
|
- name: Checkout |
||||
|
uses: actions/checkout@v3 |
||||
|
- name: Pull musl |
||||
|
run: | |
||||
|
git submodule update --init lib/musl |
||||
|
- name: Restore LLVM source cache |
||||
|
uses: actions/cache/restore@v3 |
||||
|
id: cache-llvm-source |
||||
|
with: |
||||
|
key: llvm-source-16-linux-nix-v1 |
||||
|
path: | |
||||
|
llvm-project/compiler-rt |
||||
|
- name: Download LLVM source |
||||
|
if: steps.cache-llvm-source.outputs.cache-hit != 'true' |
||||
|
run: make llvm-source |
||||
|
- name: Save LLVM source cache |
||||
|
uses: actions/cache/save@v3 |
||||
|
if: steps.cache-llvm-source.outputs.cache-hit != 'true' |
||||
|
with: |
||||
|
key: ${{ steps.cache-llvm-source.outputs.cache-primary-key }} |
||||
|
path: | |
||||
|
llvm-project/compiler-rt |
||||
|
- uses: cachix/install-nix-action@v22 |
||||
|
- name: Test |
||||
|
run: | |
||||
|
nix develop --ignore-environment --keep HOME --command bash -c "go install && ~/go/bin/tinygo version && ~/go/bin/tinygo build -o test ./testdata/cgo" |
@ -0,0 +1,60 @@ |
|||||
|
{ |
||||
|
"nodes": { |
||||
|
"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": 1696983906, |
||||
|
"narHash": "sha256-L7GyeErguS7Pg4h8nK0wGlcUTbfUMDu+HMf1UcyP72k=", |
||||
|
"owner": "NixOS", |
||||
|
"repo": "nixpkgs", |
||||
|
"rev": "bd1cde45c77891214131cbbea5b1203e485a9d51", |
||||
|
"type": "github" |
||||
|
}, |
||||
|
"original": { |
||||
|
"id": "nixpkgs", |
||||
|
"ref": "nixos-23.05", |
||||
|
"type": "indirect" |
||||
|
} |
||||
|
}, |
||||
|
"root": { |
||||
|
"inputs": { |
||||
|
"flake-utils": "flake-utils", |
||||
|
"nixpkgs": "nixpkgs" |
||||
|
} |
||||
|
}, |
||||
|
"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 |
||||
|
} |
@ -0,0 +1,63 @@ |
|||||
|
# A Nix flake file, mainly intended for developing TinyGo. |
||||
|
# You can download Nix here, for use on your Linux or macOS system: |
||||
|
# https://nixos.org/download.html |
||||
|
# After you have installed Nix, you can enter the development environment as |
||||
|
# follows: |
||||
|
# |
||||
|
# nix develop |
||||
|
# |
||||
|
# This drops you into a bash shell, where you can install TinyGo simply using |
||||
|
# the following command: |
||||
|
# |
||||
|
# go install |
||||
|
# |
||||
|
# That's all! Assuming you've set up your $PATH correctly, you can now use the |
||||
|
# tinygo command as usual: |
||||
|
# |
||||
|
# tinygo version |
||||
|
# |
||||
|
# You can also do many other things from this environment. Building and flashing |
||||
|
# should work as you're used to: it's not a VM or container so there are no |
||||
|
# access restrictions and you're running in the same host environment - just |
||||
|
# with a slightly different set of tools available. |
||||
|
{ |
||||
|
inputs = { |
||||
|
# Use a recent stable release, but fix the version to make it reproducible. |
||||
|
# This version should be updated from time to time. |
||||
|
nixpkgs.url = "nixpkgs/nixos-23.05"; |
||||
|
flake-utils.url = "github:numtide/flake-utils"; |
||||
|
}; |
||||
|
outputs = { self, nixpkgs, flake-utils }: |
||||
|
flake-utils.lib.eachDefaultSystem (system: |
||||
|
let |
||||
|
pkgs = nixpkgs.legacyPackages.${system}; |
||||
|
in |
||||
|
with pkgs; |
||||
|
{ |
||||
|
devShells.default = mkShell { |
||||
|
buildInputs = [ |
||||
|
# These dependencies are required for building tinygo (go install). |
||||
|
go |
||||
|
llvmPackages_16.llvm |
||||
|
llvmPackages_16.libclang |
||||
|
# Additional dependencies needed at runtime, for building and/or |
||||
|
# flashing. |
||||
|
llvmPackages_16.lld |
||||
|
avrdude |
||||
|
binaryen |
||||
|
# Additional dependencies needed for on-chip debugging. |
||||
|
# These tools are rather big (especially GDB) and not frequently |
||||
|
# used, so are commented out. On-chip debugging is still possible if |
||||
|
# these tools are available in the host environment. |
||||
|
#gdb |
||||
|
#openocd |
||||
|
]; |
||||
|
shellHook= '' |
||||
|
# Ugly hack to make the Clang resources directory available. |
||||
|
# Perhaps there is a cleaner way to do it, but this works. |
||||
|
export GOFLAGS="\"-ldflags=-X github.com/tinygo-org/tinygo/goenv.clangResourceDir=${llvmPackages_16.clang.cc.lib}/lib/clang/16"\" |
||||
|
''; |
||||
|
}; |
||||
|
} |
||||
|
); |
||||
|
} |
Loading…
Reference in new issue