Skip to content

Commit

Permalink
Merge pull request #556 from tweag/guide-bzlmod
Browse files Browse the repository at this point in the history
guide: bzlmod version of example
  • Loading branch information
mergify[bot] authored Jun 25, 2024
2 parents e50218c + ed31108 commit 7e1d203
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,14 @@ jobs:
pushd examples/cc-template
echo
echo "::group::Running $(head -n1 README.md) with Nix"
nix develop --command bazel run //src:hello-world
echo "::group::Running $(head -n1 README.md) with Nix, WORKSPACE"
nix develop --command bazel run --noenable_bzlmod //src:hello-world
popd
pushd examples/cc-template
echo
echo "::group::Running $(head -n1 README.md) with Nix, bzlmod"
nix develop --command bazel run --enable_bzlmod //src:hello-world
popd
pushd examples/toolchains
Expand Down
3 changes: 1 addition & 2 deletions examples/cc-template/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import %workspace%/../../.bazelrc.remote-cache

build --noenable_bzlmod
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
build --host_platform=@rules_nixpkgs_core//platforms:host
build --crosstool_top=@nixpkgs_config_cc//:toolchain

1 change: 1 addition & 0 deletions examples/cc-template/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.direnv/
bazel-*/
MODULE.bazel.lock
36 changes: 36 additions & 0 deletions examples/cc-template/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module(name = "rules_nixpkgs_guide")

bazel_dep(name = "rules_nixpkgs_core")
# Remove to use rules_nixpkgs_core from the BCR
local_path_override(
module_name = "rules_nixpkgs_core",
path = "../../core",
)

nix_repo = use_extension("@rules_nixpkgs_core//extensions:repository.bzl", "nix_repo")
nix_repo.file(
name = "nixpkgs",
file = "//:nixpkgs.nix",
file_deps = ["//:flake.lock"],
)
use_repo(nix_repo, "nixpkgs")

bazel_dep(name = "rules_nixpkgs_cc")
# Replace by archive_override to download a rules_nixpkgs_cc revision.
# (rules_nixpkgs_cc is not available on the BCR, yet.)
#
# archive_override(
# module_name = "rules_nixpkgs_cc",
# urls = ["https://github.com/tweag/rules_nixpkgs/releases/download/v0.11.1/rules_nixpkgs-0.11.1.tar.gz"],
# integrity = "sha256-KlVTSNf4WT/KK/P8bOU8XWKSnegbbCkuI/FsVXwK5Fo=",
# strip_prefix = "rules_nixpkgs-0.11.1/toolchains/cc",
# )
local_path_override(
module_name = "rules_nixpkgs_cc",
path = "../../toolchains/cc",
)

# TODO remove transitive rules_nixpkgs_cc dependencies.
# Once there is a module extension for the cc toolchain.
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_cc", version = "0.0.4")
7 changes: 7 additions & 0 deletions examples/cc-template/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@rules_nixpkgs_cc//:cc.bzl", "nixpkgs_cc_configure")

# TODO Use module extension once available.
nixpkgs_cc_configure(
name = "nixpkgs_config_cc",
repository = "@nixpkgs",
)

0 comments on commit 7e1d203

Please sign in to comment.