-
Notifications
You must be signed in to change notification settings - Fork 96
Add minimal examples of toolchains in WORKSPACEs #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
50746eb
Add minimal examples of toolchains in WORKSPACEs
itsadrake be40e54
Add Nix and Bazel config to examples
itsadrake 0cad291
Add hopefully helpful readmes to examples
itsadrake 602d621
Fix non-Nix build in examples
itsadrake e7cf471
Pin nixpkgs in example shells
itsadrake 5ef86f2
Clarify non-Nix toolchains in example READMEs
itsadrake 5ff4995
Add toolchain examples to CI workflow
itsadrake 9dc1e76
Update macOS test runner to work with more recent nixpkgs
itsadrake d9b3da9
Add Python workspace example
itsadrake 5b58d0c
Update CI actions in an attempt to fix macOS
itsadrake 8a01b02
Refactor examples to a different CI job for improved granularity
itsadrake be28bad
Add missing rc
itsadrake 5bd0b5d
Add example of C++ toolchain with dependencies
itsadrake 930bd61
Revert macOS CI version, remove macOS for examples
itsadrake 9ba43f3
Run non-Nix tests, fix CC toolchain name clash
itsadrake c813fa2
Improve example documentation
itsadrake 7aba483
Format with buildifier
itsadrake 0057471
Fix example CI script
itsadrake 1b55ed1
Add stub_shebang to python toolchain py_runtime
JasperDeSutter 20576aa
Ignore examples in global tests
itsadrake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| examples |
This file contains hidden or 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 hidden or 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 @@ | ||
| bazel-* |
This file contains hidden or 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 @@ | ||
| build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host |
This file contains hidden or 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 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
|
|
||
| cc_binary( | ||
| name = "hello", | ||
| srcs = ["hello.cc"], | ||
| ) |
This file contains hidden or 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,19 @@ | ||
| C++ Toolchain Example | ||
| ===================== | ||
|
|
||
| This is an example C++ project that uses `rules_cc`. | ||
|
|
||
| If the Nix package manager is present in the build environment, this example will use Nix to provide the C++ toolchain. Otherwise, it will use the toolchain provided by `rules_cc` and not rely on Nix at all. | ||
|
|
||
| # 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. |
This file contains hidden or 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,43 @@ | ||
| # Replace with http_archive: https://github.com/tweag/rules_nixpkgs/#setup | ||
| local_repository( | ||
| name = "io_tweag_rules_nixpkgs", | ||
| path = "../../../", | ||
| ) | ||
|
|
||
| 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", | ||
| ], | ||
| ) | ||
|
|
||
| load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") | ||
|
|
||
| rules_nixpkgs_dependencies() | ||
|
|
||
| load( | ||
| "@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", | ||
| "nixpkgs_cc_configure", | ||
| "nixpkgs_git_repository", | ||
| ) | ||
|
|
||
| nixpkgs_git_repository( | ||
| name = "nixpkgs", | ||
| revision = "21.11", | ||
| sha256 = "c77bb41cf5dd82f4718fa789d49363f512bb6fa6bc25f8d60902fe2d698ed7cc", | ||
| ) | ||
|
|
||
| nixpkgs_cc_configure( | ||
| name = "nixpkgs_config_cc", | ||
| fail_not_supported = False, | ||
| repository = "@nixpkgs", | ||
| ) | ||
|
|
||
| load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains") | ||
|
|
||
| rules_cc_dependencies() | ||
|
|
||
| rules_cc_toolchains() | ||
This file contains hidden or 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 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() | ||
| { | ||
| std::cout << "Hello world!\n"; | ||
|
itsadrake marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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 @@ | ||
| { pkgs ? import (builtins.fetchTarball { | ||
| url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz"; | ||
| sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02"; | ||
| }) { } }: | ||
|
|
||
| pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 ]; } |
This file contains hidden or 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 @@ | ||
| build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host |
This file contains hidden or 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 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
|
|
||
| cc_binary( | ||
| name = "hello", | ||
| srcs = ["hello.cc"], | ||
| deps = [ | ||
| "@boost.dev//:boost", | ||
| "@zlib.dev//:zlib", | ||
| ], | ||
| ) |
This file contains hidden or 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,13 @@ | ||
| C++ With Dependencies Toolchain Example | ||
| ======================================= | ||
|
|
||
| This is an example C++ project with dependencies that uses `rules_cc`. | ||
|
|
||
| This example uses the Nix package manager to provide C++ dependencies, and as such only works with Nix installed. Demonstrating other methods of providing C++ dependencies is out of scope of this example. | ||
|
|
||
| # Usage | ||
|
|
||
| To run the example with Nix, issue the following command: | ||
| ``` | ||
| nix-shell --command 'bazel run --config=nix :hello' | ||
| ``` |
This file contains hidden or 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,81 @@ | ||
| # Replace with http_archive: https://github.com/tweag/rules_nixpkgs/#setup | ||
| 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_cc_configure", | ||
| "nixpkgs_git_repository", | ||
| ) | ||
|
|
||
| nixpkgs_git_repository( | ||
| name = "nixpkgs", | ||
| revision = "21.11", | ||
| sha256 = "c77bb41cf5dd82f4718fa789d49363f512bb6fa6bc25f8d60902fe2d698ed7cc", | ||
| ) | ||
|
|
||
| nixpkgs_cc_configure( | ||
| name = "nixpkgs_config_cc", | ||
| fail_not_supported = False, | ||
| repository = "@nixpkgs", | ||
| ) | ||
|
|
||
| load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package") | ||
|
|
||
| nixpkgs_package( | ||
| name = "boost", | ||
| attribute_path = "boost175", | ||
| repository = "@nixpkgs", | ||
| ) | ||
|
|
||
| nixpkgs_package( | ||
| name = "boost.dev", | ||
| attribute_path = "boost175.dev", | ||
| build_file_content = """\ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
| filegroup( | ||
| name = "include", | ||
| srcs = glob(["include/**/*.h", "include/**/*.hpp"]), | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
| cc_library( | ||
| name = "boost", | ||
| srcs = ["@boost//:lib"], | ||
| hdrs = [":include"], | ||
| strip_include_prefix = "include", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
| """, | ||
| repository = "@nixpkgs", | ||
| ) | ||
|
|
||
| nixpkgs_package( | ||
| name = "zlib", | ||
| repository = "@nixpkgs", | ||
| ) | ||
|
|
||
| nixpkgs_package( | ||
| name = "zlib.dev", | ||
| build_file_content = """\ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
| filegroup( | ||
| name = "include", | ||
| srcs = glob(["include/**/*.h"]), | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
| cc_library( | ||
| name = "zlib", | ||
| srcs = ["@zlib//:lib"], | ||
| hdrs = [":include"], | ||
| strip_include_prefix = "include", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
| """, | ||
| repository = "@nixpkgs", | ||
| ) |
This file contains hidden or 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,8 @@ | ||
| #include <iostream> | ||
| #include <boost/filesystem/operations.hpp> | ||
| #include <zlib.h> | ||
|
|
||
| int main() | ||
| { | ||
| std::cout << "Hello world!\n"; | ||
| } |
This file contains hidden or 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 @@ | ||
| { pkgs ? import (builtins.fetchTarball { | ||
| url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz"; | ||
| sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02"; | ||
| }) { } }: | ||
|
|
||
| pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 ]; } |
This file contains hidden or 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 @@ | ||
| build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host |
This file contains hidden or 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 @@ | ||
| load("@io_bazel_rules_go//go:def.bzl", "go_binary") | ||
|
|
||
| go_binary( | ||
| name = "hello", | ||
| srcs = ["hello.go"], | ||
| ) |
This file contains hidden or 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 @@ | ||
| Go Toolchain Example | ||
| ==================== | ||
|
|
||
| This is an example Go project that uses `rules_go`. | ||
|
|
||
| If the Nix package manager is present in the build environment, this example will use Nix to provide the Go toolchain. Otherwise, it will use the toolchain provided by `rules_go` and not rely on Nix at all. | ||
|
|
||
| # 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 | ||
|
itsadrake marked this conversation as resolved.
|
||
| ``` | ||
This file contains hidden or 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,46 @@ | ||
| # Replace with http_archive: https://github.com/tweag/rules_nixpkgs/#setup | ||
| local_repository( | ||
| name = "io_tweag_rules_nixpkgs", | ||
| path = "../../../", | ||
| ) | ||
|
|
||
| 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() | ||
|
|
||
| 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( | ||
| fail_not_supported = False, | ||
| repository = "@nixpkgs", | ||
| sdk_name = "nix_go", | ||
| ) | ||
|
|
||
| load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
|
|
||
| go_rules_dependencies() | ||
|
|
||
| go_register_toolchains(version = "1.17.1") |
This file contains hidden or 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,7 @@ | ||
| package main | ||
|
|
||
| import "fmt" | ||
|
|
||
| func main() { | ||
| fmt.Println("Hello world!") | ||
| } |
This file contains hidden or 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 @@ | ||
| { pkgs ? import (builtins.fetchTarball { | ||
| url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz"; | ||
| sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02"; | ||
| }) { } }: | ||
|
|
||
| pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 ]; } |
This file contains hidden or 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 @@ | ||
| build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host |
This file contains hidden or 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,5 @@ | ||
| py_binary( | ||
| name = "hello", | ||
| srcs = ["hello.py"], | ||
| main = "hello.py", | ||
| ) |
This file contains hidden or 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,15 @@ | ||
| Python Toolchain Example | ||
| ======================== | ||
|
|
||
| This is an example Python project with modules that uses `rules_python`. | ||
|
|
||
| This example uses the Nix package manager to provide Python packages, and as such only works with Nix installed. Demonstrating other methods of providing Python packages is out of scope of this example. | ||
|
|
||
| # 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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.