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

Add platform contraints for GOAMD64 #3251

Merged
merged 1 commit into from
Jul 26, 2022
Merged

Conversation

fmeum
Copy link
Member

@fmeum fmeum commented Jul 26, 2022

What type of PR is this?

Feature

What does this PR do? Why is it needed?

The new constraints //go/constraints/amd64:v1 to v4 can be used to
mark a platform as supporting the corresponding level of GOAMD64.

To use the new feature, users would supply their own platform:

platform(
    name = "amd64_with_avx",
    contraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
        "@io_bazel_rules_go//go/constraints/amd64:v3",
    ],
)

and then specify the platform with --platforms.

Which issues(s) does this PR fix?

Fixes #3248

Other notes for review

The new constraints `//go/constraints/amd64:v1` to `v4` can be used to
mark a platform as supporting the corresponding level of `GOAMD64`.

To use the new feature, users would supply their own platform:

```starlark
platform(
    name = "amd64_with_avx",
    contraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
        "@io_bazel_rules_go//go/constraints/amd64:v3",
    ],
)
```

and then specify the platform with `--platforms`.
@rabbbit
Copy link
Contributor

rabbbit commented Jul 26, 2022

Thanks for the quick reaction!

Looks very promising (and almost definitely is what I need), I left a note on #3248.

@fmeum fmeum requested a review from linzhp July 26, 2022 16:20
@fmeum fmeum marked this pull request as ready for review July 26, 2022 16:20
Copy link
Member

@achew22 achew22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see @linzhp run this on the big repo, but LGTM

@fmeum
Copy link
Member Author

fmeum commented Jul 26, 2022

@achew22 Do you know a good place in the docs where I could explain this new feature?

@linzhp
Copy link
Contributor

linzhp commented Jul 26, 2022

The changes look good to me. @rabbbit Did you test it in Uber?

@rabbbit
Copy link
Contributor

rabbbit commented Jul 26, 2022

I patched it and can confirm the env contains the variable I need/want.

SUBCOMMAND: # @io_bazel_rules_go//:stdlib [action 'GoStdlib external/io_bazel_rules_go/stdlib_/pkg', configuration: be3be823bbdbc6e9db2eea6ed500a467975e027a0c143a8f63ba4d6e234e927a, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_pawel/592aedee41e8f957ae1ee499da1dedeb/execroot/__main__ && \
  exec env - \
    CGO_ENABLED=0 \
    GOAMD64=v3 \
    GOARCH=amd64 \
    GOOS=linux \
    GOPATH='' \
    GOROOT=external/go_sdk \
    GOROOT_FINAL=GOROOT \

I have not tested whether the actual variable has an effect (yet), but this change looks good - thanks for the help @fmeum! :)

@fmeum fmeum merged commit eb03b81 into bazel-contrib:master Jul 26, 2022
@sluongng
Copy link
Contributor

It would be nice if instead of having to use bazel build --platforms=//my/custom/platform:with_avx, user can just specify this under an attribute of go_binary instead (similar to goos and goarch).

@fmeum fmeum deleted the goamd64 branch July 27, 2022 07:24
@fmeum
Copy link
Member Author

fmeum commented Jul 27, 2022

It would be nice if instead of having to use bazel build --platforms=//my/custom/platform:with_avx, user can just specify this under an attribute of go_binary instead (similar to goos and goarch).

We generally want to move away from that approach, but introduce a wrapper rule that transitions to a different user-provided platform. That gives you clear semantics with select and less rebuilds since you are not switching between synthetic platforms.

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 this pull request may close these issues.

action_env not passed in to GoCompilePkg actions
5 participants