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

Feature: Build pure go_binary targets without cc toolchain #4145

Closed
sallustfire opened this issue Oct 17, 2024 · 1 comment · Fixed by #4146
Closed

Feature: Build pure go_binary targets without cc toolchain #4145

sallustfire opened this issue Oct 17, 2024 · 1 comment · Fixed by #4146

Comments

@sallustfire
Copy link
Contributor

What version of rules_go are you using?

v0.50.1

What version of Bazel are you using?

7.3.2

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

PopOS 22.04

What did you do?

go_binary targets with pure = "on" still participate in cc toolchain selection. This can be seen in one of the examples in the repo:

bazel cquery "somepath(//tests/core/go_binary:static_pure_bin, kind(toolchain, deps(//tests/core/go_binary:static_pure_bin)))"
INFO: Analyzed target //tests/core/go_binary:static_pure_bin (1 packages loaded, 14 targets configured).
INFO: Found 1 target...
//tests/core/go_binary:static_pure_bin (5c86453)
//:go_context_data (55832f6)
//:stdlib (c5fe2ab)
//:cgo_context_data (c5fe2ab)
@bazel_tools//tools/cpp:optional_current_cc_toolchain (c5fe2ab)
INFO: Elapsed time: 0.122s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions

This happens because //:go_context_data has a dependency on //:cgo_context_data. There are two other places where this same cgo dependency enters //:stdlib and //:cgo_context_data_proxy.

What did you expect to see?

Only the go SDK should be selected

bazel cquery "somepath(//tests/core/go_binary:static_pure_bin, kind(toolchain, deps(//tests/core/go_binary:static_pure_bin)))"
INFO: Analyzed target //tests/core/go_binary:static_pure_bin (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
//tests/core/go_binary:static_pure_bin (5c86453)
@go_sdk//:go_linux_amd64-impl (5c86453)
INFO: Elapsed time: 0.126s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
sallustfire pushed a commit to sallustfire/rules_go that referenced this issue Oct 17, 2024
fmeum pushed a commit that referenced this issue Oct 18, 2024
**What type of PR is this?**

> Feature

**What does this PR do? Why is it needed?**

//:cgo_context_data is in the dependency closure of pure go_binary
targets. This PR adds a config_setting to detect when //go/config:pure
is set to True and updates the places where //:cgo_context_data is
selected.

**Which issues(s) does this PR fix?**

Fixes #4145 

**Other notes for review**

No breaking tests have been added, but the functionality can be seen on
the pure targets in the test folder. e.g.
```
bazel cquery "somepath(//tests/core/go_binary:static_pure_bin, //:cgo_context_data)"
INFO: Analyzed 2 targets (0 packages loaded, 0 targets configured).
INFO: Found 2 targets...
INFO: Empty query results
INFO: Elapsed time: 0.097s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
```

---------

Co-authored-by: Connor McEntee <[email protected]>
@aaomidi
Copy link

aaomidi commented Oct 23, 2024

I think based on #4154, this might still be an issue.

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.

2 participants