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

Make C++ toolchain optional #3390

Merged
merged 5 commits into from
Dec 30, 2023

Conversation

illicitonion
Copy link
Contributor

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

Currently, if you transition a go_binary, you must have a C++ toolchain
for it even if it's building in pure mode without cgo.

By making this toolchain optional, we push the error from a
toolchain-resolution-time error to an analysis-time error only if a
toolchain is both needed and not found.

This showed up in testing bazel-contrib/bazel-lib#289

@achew22
Copy link
Member

achew22 commented Dec 8, 2022

Can you also include a test to confirm we don't regress on this? Thanks!

@fmeum
Copy link
Member

fmeum commented Dec 8, 2022

@illicitonion Is it possible that you based your commit on a rather old version of master? Rebasing should fix the CI failure.

@illicitonion illicitonion force-pushed the optional-cpp-toolchain branch 2 times, most recently from 5da15de to 264ad0c Compare December 8, 2022 17:33
WORKSPACE Outdated Show resolved Hide resolved
@fmeum
Copy link
Member

fmeum commented Jan 30, 2023

@illicitonion This should be unblocked as soon as Bazel 6.1 is the minimum supported version of rules_go: bazelbuild/bazel@ac47e10

@illicitonion
Copy link
Contributor Author

Amazing, thanks!

@LeandroLovisolo
Copy link

LeandroLovisolo commented Dec 21, 2023

@illicitonion This should be unblocked as soon as Bazel 6.1 is the minimum supported version of rules_go: bazelbuild/bazel@ac47e10

Bazel 6.1 has been released. Any chance this PR could be merged?

@fmeum
Copy link
Member

fmeum commented Dec 21, 2023

We still support Bazel 5.4.0 though.

@illicitonion Would you be interested in picking this up again and using bazel_features for feature detection?

@illicitonion
Copy link
Contributor Author

Sure, happy to pick this up again!

It looks like bazel_features requires a two-step init (http_archiveing it in, then calling a function from it), but rules_go only has a one-step init (loading go_rules_dependencies and calling it) - is there an existing pattern in rules_go for two-step init? (The problem being: You can't load the function you need to call at the top of the file because the http_archive you're loading it from doesn't exist yet, and you can't load it after the http_archive has been called because you can't load inside a function)

@fmeum
Copy link
Member

fmeum commented Dec 22, 2023

@illicitonion There isn't and adding a second step would be a breaking change. How about adding this feature for Bzlmod only? Then we can look into whether we can support WORKSPACE as a follow-up.

@illicitonion illicitonion force-pushed the optional-cpp-toolchain branch 5 times, most recently from 0232f96 to 09c9158 Compare December 22, 2023 16:50
@illicitonion
Copy link
Contributor Author

@fmeum I think we're good to go on this, PTAL!

(Sorry for the horrors of the fake bazel_features :))

Copy link
Member

@fmeum fmeum left a comment

Choose a reason for hiding this comment

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

Looks great, only a few stylistic comments

go/private/context.bzl Outdated Show resolved Hide resolved
go/private/context.bzl Outdated Show resolved Hide resolved
go/private/fake_bazel_features.bzl Outdated Show resolved Hide resolved
tests/core/cross/BUILD.bazel Outdated Show resolved Hide resolved
@illicitonion illicitonion force-pushed the optional-cpp-toolchain branch 5 times, most recently from 59e4347 to f36882b Compare December 27, 2023 16:01
tests/core/starlark/cgo/cgo_test.bzl Show resolved Hide resolved
@fmeum
Copy link
Member

fmeum commented Dec 27, 2023

@linzhp Could you test this?

Copy link
Contributor

@tyler-french tyler-french left a comment

Choose a reason for hiding this comment

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

Tested these changes at Uber and everything passes

Currently, if you transition a go_binary, you must have a C++ toolchain
for it even if it's building in pure mode without cgo.

By making this toolchain optional, we push the error from a
toolchain-resolution-time error to an analysis-time error only if a
toolchain is both _needed_ and not found.
Also switch from @bazel_tools//tools/cpp:current_cc_toolchain to
@bazel_tools//tools/cpp:optional_current_cc_toolchain because otherwise
we still get a hard error if the toolchain can't be found.
@fmeum fmeum enabled auto-merge (squash) December 30, 2023 07:32
@fmeum fmeum merged commit b5d0db5 into bazel-contrib:master Dec 30, 2023
2 checks passed
@illicitonion illicitonion deleted the optional-cpp-toolchain branch January 2, 2024 10:38
cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/bazel-starlib Jan 3, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [io_bazel_rules_go](https://togithub.com/bazelbuild/rules_go) |
http_archive | patch | `v0.44.1` -> `v0.44.2` |

---

### Release Notes

<details>
<summary>bazelbuild/rules_go (io_bazel_rules_go)</summary>

###
[`v0.44.2`](https://togithub.com/bazelbuild/rules_go/releases/tag/v0.44.2)

[Compare
Source](https://togithub.com/bazelbuild/rules_go/compare/v0.44.1...v0.44.2)

#### `WORKSPACE` code

load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive")

    http_archive(
        name = "io_bazel_rules_go",
sha256 =
"7c76d6236b28ff695aa28cf35f95de317a9472fd1fb14ac797c9bf684f09b37c",
        urls = [

"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",

"https://github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",
        ],
    )

load("@&#8203;io_bazel_rules_go//go:deps.bzl", "go_register_toolchains",
"go_rules_dependencies")

    go_rules_dependencies()

    go_register_toolchains(version = "1.21.5")

#### What's Changed

- Make C++ toolchain optional by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[https://github.com/bazelbuild/rules_go/pull/3390](https://togithub.com/bazelbuild/rules_go/pull/3390)
- Fix a race detected only if a test times out by
[@&#8203;patrickmscott](https://togithub.com/patrickmscott) in
[https://github.com/bazelbuild/rules_go/pull/3808](https://togithub.com/bazelbuild/rules_go/pull/3808)
- registering timeout handler synchronously by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/rules_go/pull/3810](https://togithub.com/bazelbuild/rules_go/pull/3810)
- patch release 0.44.2 by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/rules_go/pull/3811](https://togithub.com/bazelbuild/rules_go/pull/3811)

**Full Changelog**:
bazel-contrib/rules_go@v0.44.1...v0.44.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
trunk-io bot referenced this pull request in ride-app/driver-service Jan 3, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [io_bazel_rules_go](https://togithub.com/bazelbuild/rules_go) | http_archive | patch | `v0.44.1` -> `v0.44.2` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency Dashboard for more information.

---

### Release Notes

<details>
<summary>bazelbuild/rules_go (io_bazel_rules_go)</summary>

### [`v0.44.2`](https://togithub.com/bazelbuild/rules_go/releases/tag/v0.44.2)

[Compare Source](https://togithub.com/bazelbuild/rules_go/compare/v0.44.1...v0.44.2)

#### `WORKSPACE` code

    load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

    http_archive(
        name = "io_bazel_rules_go",
        sha256 = "7c76d6236b28ff695aa28cf35f95de317a9472fd1fb14ac797c9bf684f09b37c",
        urls = [
            "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",
            "https://github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",
        ],
    )

    load("@&#8203;io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

    go_rules_dependencies()

    go_register_toolchains(version = "1.21.5")

#### What's Changed

-   Make C++ toolchain optional by [@&#8203;illicitonion](https://togithub.com/illicitonion) in [https://github.com/bazelbuild/rules_go/pull/3390](https://togithub.com/bazelbuild/rules_go/pull/3390)
-   Fix a race detected only if a test times out by [@&#8203;patrickmscott](https://togithub.com/patrickmscott) in [https://github.com/bazelbuild/rules_go/pull/3808](https://togithub.com/bazelbuild/rules_go/pull/3808)
-   registering timeout handler synchronously by [@&#8203;linzhp](https://togithub.com/linzhp) in [https://github.com/bazelbuild/rules_go/pull/3810](https://togithub.com/bazelbuild/rules_go/pull/3810)
-   patch release 0.44.2 by [@&#8203;tyler-french](https://togithub.com/tyler-french) in [https://github.com/bazelbuild/rules_go/pull/3811](https://togithub.com/bazelbuild/rules_go/pull/3811)

**Full Changelog**: bazel-contrib/rules_go@v0.44.1...v0.44.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/ride-app/driver-service).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMDMuMSIsInVwZGF0ZWRJblZlciI6IjM3LjEwMy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
renovate bot referenced this pull request in kreempuff/rules_unreal_engine Jan 3, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [io_bazel_rules_go](https://togithub.com/bazelbuild/rules_go) |
http_archive | patch | `v0.44.1` -> `v0.44.2` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>bazelbuild/rules_go (io_bazel_rules_go)</summary>

###
[`v0.44.2`](https://togithub.com/bazelbuild/rules_go/releases/tag/v0.44.2)

[Compare
Source](https://togithub.com/bazelbuild/rules_go/compare/v0.44.1...v0.44.2)

#### `WORKSPACE` code

load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive")

    http_archive(
        name = "io_bazel_rules_go",
sha256 =
"7c76d6236b28ff695aa28cf35f95de317a9472fd1fb14ac797c9bf684f09b37c",
        urls = [

"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",

"https://github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",
        ],
    )

load("@&#8203;io_bazel_rules_go//go:deps.bzl", "go_register_toolchains",
"go_rules_dependencies")

    go_rules_dependencies()

    go_register_toolchains(version = "1.21.5")

#### What's Changed

- Make C++ toolchain optional by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[https://github.com/bazelbuild/rules_go/pull/3390](https://togithub.com/bazelbuild/rules_go/pull/3390)
- Fix a race detected only if a test times out by
[@&#8203;patrickmscott](https://togithub.com/patrickmscott) in
[https://github.com/bazelbuild/rules_go/pull/3808](https://togithub.com/bazelbuild/rules_go/pull/3808)
- registering timeout handler synchronously by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/rules_go/pull/3810](https://togithub.com/bazelbuild/rules_go/pull/3810)
- patch release 0.44.2 by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/rules_go/pull/3811](https://togithub.com/bazelbuild/rules_go/pull/3811)

**Full Changelog**:
bazel-contrib/rules_go@v0.44.1...v0.44.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/kreempuff/rules_unreal_engine).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMDMuMSIsInVwZGF0ZWRJblZlciI6IjM3LjEwMy4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/rules_swift_package_manager Jan 7, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [io_bazel_rules_go](https://togithub.com/bazelbuild/rules_go) |
http_archive | patch | `v0.44.1` -> `v0.44.2` |

---

### Release Notes

<details>
<summary>bazelbuild/rules_go (io_bazel_rules_go)</summary>

###
[`v0.44.2`](https://togithub.com/bazelbuild/rules_go/releases/tag/v0.44.2)

[Compare
Source](https://togithub.com/bazelbuild/rules_go/compare/v0.44.1...v0.44.2)

#### `WORKSPACE` code

load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive")

    http_archive(
        name = "io_bazel_rules_go",
sha256 =
"7c76d6236b28ff695aa28cf35f95de317a9472fd1fb14ac797c9bf684f09b37c",
        urls = [

"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",

"https://github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip",
        ],
    )

load("@&#8203;io_bazel_rules_go//go:deps.bzl", "go_register_toolchains",
"go_rules_dependencies")

    go_rules_dependencies()

    go_register_toolchains(version = "1.21.5")

#### What's Changed

- Make C++ toolchain optional by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[https://github.com/bazelbuild/rules_go/pull/3390](https://togithub.com/bazelbuild/rules_go/pull/3390)
- Fix a race detected only if a test times out by
[@&#8203;patrickmscott](https://togithub.com/patrickmscott) in
[https://github.com/bazelbuild/rules_go/pull/3808](https://togithub.com/bazelbuild/rules_go/pull/3808)
- registering timeout handler synchronously by
[@&#8203;linzhp](https://togithub.com/linzhp) in
[https://github.com/bazelbuild/rules_go/pull/3810](https://togithub.com/bazelbuild/rules_go/pull/3810)
- patch release 0.44.2 by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/rules_go/pull/3811](https://togithub.com/bazelbuild/rules_go/pull/3811)

**Full Changelog**:
bazel-contrib/rules_go@v0.44.1...v0.44.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.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 this pull request may close these issues.

6 participants