Skip to content
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

[BUG] cannot specify list extra_rustc_flags in rust_register_toolchains #2692

Closed
nmattia opened this issue Jun 13, 2024 · 0 comments · Fixed by #2693
Closed

[BUG] cannot specify list extra_rustc_flags in rust_register_toolchains #2692

nmattia opened this issue Jun 13, 2024 · 0 comments · Fixed by #2693

Comments

@nmattia
Copy link
Contributor

nmattia commented Jun 13, 2024

It's currently impossible to specify a list of extra_rustc_flags in the toolchain:

rust_register_toolchains(
    ...
    extra_rustc_flags = [
        ...
    ],
)

Even though rust_register_toolchains suggests this is possible

extra_rustc_flags (dict, list, optional): Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.

It fails with the following error:

File "/foo/bar/baz/external/rules_rust/rust/repositories.bzl", line 1053, column 50, in rust_repository_set
  extra_rustc_flags = extra_rustc_flags.get(toolchain.target_triple) if extra_rustc_flags != None else None,
Error: 'list' value has no field or method 'get'

The following patch seems to fix it:

@@ -1040,6 +1040,17 @@ def rust_repository_set(
         elif type(extra_target_triples) == "dict":
             target_compatible_with = extra_target_triples.get(toolchain.target_triple)

+
+        # Infer toolchain-specific rustc flags depending on the type (list, dict, optional) of extra_rustc_flags
+        if extra_rustc_flags == None:
+            toolchain_extra_rustc_flags = []
+        elif type(extra_rustc_flags) == "list":
+            toolchain_extra_rustc_flags = extra_rustc_flags
+        elif type(extra_rustc_flags) == "dict":
+            toolchain_extra_rustc_flags = extra_rustc_flags.get(toolchain.target_triple)
+        else:
+            fail("extra_rustc_flags should be a list or a dict")
+
         all_toolchain_names.append(rust_toolchain_repository(
             name = toolchain.name,
             allocator_library = allocator_library,
@@ -1050,7 +1061,7 @@ def rust_repository_set(
             edition = edition,
             exec_triple = exec_triple,
             extra_exec_rustc_flags = extra_exec_rustc_flags,
-            extra_rustc_flags = extra_rustc_flags.get(toolchain.target_triple) if extra_rustc_flags != None else None,
+            extra_rustc_flags = toolchain_extra_rustc_flags,
             opt_level = opt_level.get(toolchain.target_triple) if opt_level != None else None,
             target_settings = target_settings,
             iso_date = toolchain.channel.iso_date,
github-merge-queue bot pushed a commit that referenced this issue Jun 14, 2024
Fixes #2692 

This fixes `rust_register_toolchains` to correctly call
`rust_toolchain_repository` with a list of `extra_rustc_flags`.

Previously, the `extra_rustc_flags` argument of
`rust_register_toolchains` was assumed (when set) to be a dict of
toolchain triple to list. With this change, a `list` parameter is used
for all toolchain triples.

Co-authored-by: UebelAndre <github@uebelandre.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant