bazel-contrib / bazel-contrib/rules_go

CGO constraint does nothing

Open
#4,356 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

Platform: Windows 11 x64

I cannot get cgo to work, and this is one of the ways I tried that is not being respected.

## Reproduction steps

Add the following to `BUILD.bazel`:

```
platform(
name = "x64_windows-clang-cl",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@bazel_tools//tools/cpp:clang-cl",
"@rules_go//go/toolchain:cgo_on",
],
)
```

Run bazel with `--platforms=//tools:x64_windows-clang-cl --host_platform=//tools:x64_windows-clang-cl` and compile a cgo rule with `-s`.

## Expected behaviour

Either the rule is compiled with `CGO_ENABLED=1`, or an error occurs because the toolchain is not compatible with the `cgo_on` constraint.

## Actual behaviour

The rule is compiled with `CGO_ENABLED=0`

## What should happen

Either the `cgo_on` constraint should only be supported by toolchains that actually support cgo, or it should be removed.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the `BUILD.bazel` platform definition, `--platforms=//tools:x64_windows-clang-cl`, `--host_platform=//tools:x64_windows-clang-cl`, and a cgo rule compiled with `-s`. Trace how the `@rules_go//go/toolchain:cgo_on` constraint is handled by the selected toolchain. Done means cgo is enabled, or the incompatible constraint produces an error, or the constraint is removed as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.