Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-10.15]
os: [ubuntu-latest, macos-11]
Comment thread
itsadrake marked this conversation as resolved.
Outdated
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v14.1
- uses: actions/checkout@v2.4.0
- uses: cachix/install-nix-action@v16
with:
nix_path: nixpkgs=./nixpkgs.nix
- name: Configure
Expand All @@ -27,3 +27,31 @@ jobs:
set -euo pipefail
bazel test //...
'
test-examples:
name: Build & Test - Examples
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-11]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2.4.0
- uses: cachix/install-nix-action@v16
with:
nix_path: nixpkgs=./nixpkgs.nix
- name: Configure
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat >.bazelrc.local <<EOF
common --config=ci
build --remote_header=x-buildbuddy-api-key="$BUILDBUDDY_API_KEY"
EOF
- name: Build & test
run: |
for dir in $PWD/examples/toolchains/*; do
cd "$dir"
echo
echo Running $(head -n1 README.md)
nix-shell --command 'bazel run --config=nix :hello'
done
Comment thread
itsadrake marked this conversation as resolved.
Outdated
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
1 change: 1 addition & 0 deletions examples/toolchains/cc/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
6 changes: 6 additions & 0 deletions examples/toolchains/cc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")

cc_binary(
name = "hello",
srcs = [ "hello.cc" ]
)
17 changes: 17 additions & 0 deletions examples/toolchains/cc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
C++ Toolchain Example
=====================

This is an example C++ project that uses `rules_cc`. It should build and run both with or without Nix installed.
Comment thread
itsadrake marked this conversation as resolved.
Outdated

# Usage

To run the example with Nix, issue the following command:
```
nix-shell --command 'bazel run --config=nix :hello'
```

To run the example without Nix, make sure you have Bazel installed, and issue the following command:
```
bazel run :hello
```
This non-Nix example will look for the C++ toolchain on the PATH.
38 changes: 38 additions & 0 deletions examples/toolchains/cc/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_cc",
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
urls = [
"https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz",
]
)

local_repository(
Comment thread
itsadrake marked this conversation as resolved.
Outdated
name = "io_tweag_rules_nixpkgs",
path = "../../../"
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
rules_nixpkgs_dependencies()
Comment thread
itsadrake marked this conversation as resolved.

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
"nixpkgs_git_repository",
"nixpkgs_cc_configure"
)
nixpkgs_git_repository(
name = "nixpkgs",
revision = "21.11",
Comment thread
itsadrake marked this conversation as resolved.
sha256 = "c77bb41cf5dd82f4718fa789d49363f512bb6fa6bc25f8d60902fe2d698ed7cc",
)

nixpkgs_cc_configure(
repository = "@nixpkgs",
fail_not_supported = False,
)
Comment thread
itsadrake marked this conversation as resolved.

load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")

rules_cc_dependencies()

rules_cc_toolchains()

6 changes: 6 additions & 0 deletions examples/toolchains/cc/hello.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main()
{
std::cout << "Hello world!\n";
Comment thread
itsadrake marked this conversation as resolved.
}
6 changes: 6 additions & 0 deletions examples/toolchains/cc/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ pkgs ? import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz";
sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02";
}) { } }:

pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 ]; }
1 change: 1 addition & 0 deletions examples/toolchains/go/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
6 changes: 6 additions & 0 deletions examples/toolchains/go/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary")

go_binary(
name = "hello",
srcs = [ "hello.go" ]
)
17 changes: 17 additions & 0 deletions examples/toolchains/go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Go Toolchain Example
====================

This is an example Go project that uses `rules_go`. It should build and run both with or without Nix installed.

# Usage

To run the example with Nix, issue the following command:
```
nix-shell --command 'bazel run --config=nix :hello'
```

To run the example without Nix, make sure you have Bazel installed, and issue the following command:
```
bazel run :hello
Comment thread
itsadrake marked this conversation as resolved.
```
This non-Nix example will download a binary distribution of Go's toolchain from the Internet.
38 changes: 38 additions & 0 deletions examples/toolchains/go/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")

go_rules_dependencies()

local_repository(
name = "io_tweag_rules_nixpkgs",
path = "../../../"
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
rules_nixpkgs_dependencies()

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository")
nixpkgs_git_repository(
name = "nixpkgs",
revision = "21.11",
sha256 = "c77bb41cf5dd82f4718fa789d49363f512bb6fa6bc25f8d60902fe2d698ed7cc",
)

load("@io_tweag_rules_nixpkgs//nixpkgs:toolchains/go.bzl", "nixpkgs_go_configure")
nixpkgs_go_configure(
sdk_name = "nix_go",
repository = "@nixpkgs",
fail_not_supported = False,
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains(version = "1.17.1")
7 changes: 7 additions & 0 deletions examples/toolchains/go/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello world!")
}
6 changes: 6 additions & 0 deletions examples/toolchains/go/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ pkgs ? import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz";
sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02";
}) { } }:

pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 ]; }
1 change: 1 addition & 0 deletions examples/toolchains/python/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
5 changes: 5 additions & 0 deletions examples/toolchains/python/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
py_binary(
name = "hello",
srcs = [ "hello.py"],
main = "hello.py",
)
13 changes: 13 additions & 0 deletions examples/toolchains/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Python Toolchain Example
========================

This is an example Python project with modules that uses `rules_python`. Providing Python modules without Nix is currently not supported.
Comment thread
itsadrake marked this conversation as resolved.
Outdated

# Usage

To run the example with Nix, issue the following command:
```
nix-shell --command 'bazel run --config=nix :hello'
```

To specify Python version or modules, change the `python3_attribute_path` parameter in the `nixpkgs_python_configure` call in the `WORKSPACE` file.
22 changes: 22 additions & 0 deletions examples/toolchains/python/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

local_repository(
name = "io_tweag_rules_nixpkgs",
path = "../../.."
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
rules_nixpkgs_dependencies()

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository")
nixpkgs_git_repository(
name = "nixpkgs",
revision = "21.11",
sha256 = "c77bb41cf5dd82f4718fa789d49363f512bb6fa6bc25f8d60902fe2d698ed7cc",
)

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_python_configure")
nixpkgs_python_configure(
repository = "@nixpkgs",
python3_attribute_path = "python39.withPackages(ps: with ps; [ numpy opencv4 ])"
)
4 changes: 4 additions & 0 deletions examples/toolchains/python/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import cv2
import numpy

print("Hello world!")
6 changes: 6 additions & 0 deletions examples/toolchains/python/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ pkgs ? import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz";
sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02";
}) { } }:

pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 ]; }