Skip to content

Commit

Permalink
Update nixpkgs_cc_configure to work without nix_file or `nix_cont…
Browse files Browse the repository at this point in the history
…ent`
  • Loading branch information
z8v committed Feb 18, 2023
1 parent 691582f commit f5b838b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/toolchains/cc/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ nixpkgs_git_repository(
nixpkgs_cc_configure(
name = "nixpkgs_config_cc",
repository = "@nixpkgs",
attribute_path = "clang_13",
)

load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")
Expand Down
9 changes: 8 additions & 1 deletion toolchains/cc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ nixpkgs_cc_configure(
)
```
```
# alternate usage without specifying `nix_file` or `nix_file_content`
nixpkgs_cc_configure(
repository = "@nixpkgs",
attribute_path = "gcc11",
)
```
```
# use the `stdenv.cc` compiler (the default of the given @nixpkgs repository)
nixpkgs_cc_configure(
repository = "@nixpkgs",
Expand Down Expand Up @@ -110,7 +117,7 @@ default is <code>""</code>

<p>

optional, string, Obtain the toolchain from the Nix expression under this attribute path. Requires `nix_file` or `nix_file_content`.
optional, string, Obtain the toolchain from the Nix expression under this attribute path. Uses default repository if no `nix_file` or `nix_file_content` is provided.

</p>
</td>
Expand Down
18 changes: 16 additions & 2 deletions toolchains/cc/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ def nixpkgs_cc_configure(
)
```
```
# alternate usage without specifying `nix_file` or `nix_file_content`
nixpkgs_cc_configure(
repository = "@nixpkgs",
attribute_path = "gcc11",
)
```
```
# use the `stdenv.cc` compiler (the default of the given @nixpkgs repository)
nixpkgs_cc_configure(
repository = "@nixpkgs",
Expand All @@ -355,7 +362,7 @@ def nixpkgs_cc_configure(
this toolchain.
Args:
attribute_path: optional, string, Obtain the toolchain from the Nix expression under this attribute path. Requires `nix_file` or `nix_file_content`.
attribute_path: optional, string, Obtain the toolchain from the Nix expression under this attribute path. Uses default repository if no `nix_file` or `nix_file_content` is provided.
nix_file: optional, Label, Obtain the toolchain from the Nix expression defined in this file. Specify only one of `nix_file` or `nix_file_content`.
nix_file_content: optional, string, Obtain the toolchain from the given Nix expression. Specify only one of `nix_file` or `nix_file_content`.
nix_file_deps: optional, list of Label, Additional files that the Nix expression depends on.
Expand Down Expand Up @@ -383,7 +390,14 @@ def nixpkgs_cc_configure(
nix_expr = nix_file_content

if attribute_path and nix_expr == None:
fail("'attribute_path' requires one of 'nix_file' or 'nix_file_content'", "attribute_path")
nixopts.extend([
"--argstr",
"ccType",
"ccTypeExpression",
"--arg",
"ccExpr",
"(import <nixpkgs> {{}}).{0}".format(attribute_path),
])
elif attribute_path:
nixopts.extend([
"--argstr",
Expand Down

0 comments on commit f5b838b

Please sign in to comment.