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

Building a Go program using Bazel fails on macOS #1099

Closed
kyleconroy opened this issue Apr 5, 2024 · 7 comments
Closed

Building a Go program using Bazel fails on macOS #1099

kyleconroy opened this issue Apr 5, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@kyleconroy
Copy link

kyleconroy commented Apr 5, 2024

Describe the bug

I can no longer build my Go project using Bazel after upgrading to devenv 1.3.1

While I've pushed a repository with a full reproduction, I realize there are still many moving pieces. This could be an issue with Devenv, Nix, Bazel, or rules_go. I'm having a difficult time figuring out where the issue lies, so I thought I'd start here.

To reproduce

git clone https://github.com/kyleconroy/devenv-bazel-go-broken
cd devenv-bazel-go-broken
devenv shell
bazelisk build //hello

Outside the devenv shell, this runs successfully

%  bazelisk build //hello
INFO: Analyzed target //:gazelle (3 packages loaded, 81 targets configured).
INFO: From GoLink external/gazelle~/cmd/gazelle/gazelle_/gazelle [for tool]:
ld: warning: ignoring duplicate libraries: '-lm'
INFO: Found 1 target...
Target //:gazelle up-to-date:
  bazel-bin/gazelle-runner.bash
  bazel-bin/gazelle
INFO: Elapsed time: 8.646s, Critical Path: 7.64s
INFO: 40 processes: 5 internal, 35 darwin-sandbox.
INFO: Build completed successfully, 40 total actions
INFO: Running command line: bazel-bin/gazelle

Once I've activated the shell, it fails.

$ bazelisk build //hello
INFO: Analyzed target //hello:hello (104 packages loaded, 5659 targets configured).
ERROR: /private/var/tmp/_bazel_kyle/c3d7894f4cdf3c1bcc4683dd549d8b70/external/rules_go~/BUILD.bazel:42:7: GoStdlib external/rules_go~/stdlib_/pkg failed: (Exit 1): builder failed: error executing GoStdlib command (from target @@rules_go~//:stdlib) bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_go~~go_sdk~devenv-bazel-go-broken__download_0/builder_reset/builder stdlib -sdk ... (remaining 13 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
# net/internal/cgotest
bazel-out/darwin_arm64-fastbuild/bin/external/rules_go~/stdlib_/src/net/internal/cgotest/resstate.go:10:10: fatal error: 'resolv.h' file not found
#include <resolv.h>
         ^~~~~~~~~~
1 error generated.
stdlib: error running subcommand external/rules_go~~go_sdk~devenv-bazel-go-broken__download_0/bin/go: exit status 1
Target //hello:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 27.889s, Critical Path: 12.49s
INFO: 8 processes: 7 internal, 1 darwin-sandbox.
ERROR: Build did NOT complete successfully

Version

I'm running macOS 14.7.1 and devenv 1.3.1.

$ devenv version
devenv 1.3.1 (aarch64-darwin)
@kyleconroy kyleconroy added the bug Something isn't working label Apr 5, 2024
@kyleconroy
Copy link
Author

I've tried directly adding CoreFoundation (via #508), but it didn't fix anything.

  # https://devenv.sh/packages/
  packages = [ 
    pkgs.bazelisk
    pkgs.git
  ]
  ++ # array concatenation operator
  lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk; [
    frameworks.CoreFoundation
    frameworks.Security
    frameworks.SystemConfiguration
  ]);

@domenkozar
Copy link
Member

I'm not familiar with Bazel, could we somehow reproduce the issue without bazel? That would narrow it down and allow me to help.

@kyleconroy
Copy link
Author

It appears the issue is with Bazel itself. Downgrading to Bazel 6.5.0 fixes the issue. Upgrading back to Bazel 7.0.1 causes the issue to reappear.

@kyleconroy
Copy link
Author

After reading through the Bazel release notes, I've found bazel-contrib/rules_go#3793 which seems like the issue. I'll reopen this if it turns out devenv needs to change something.

@kyleconroy kyleconroy reopened this Dec 19, 2024
@kyleconroy
Copy link
Author

kyleconroy commented Dec 19, 2024

I'm reopening this issue as I've run into another issue with the interaction with nix / devenv / bazel. Sadly, I've been unable to find a fix and am considering migrating off devenv.

I've tried installing the following nixpkgs without any luck.

Install a combination of the following nixpkgs

clang
gcc
darwin.libresolv
darwin.libresolvHeaders
apple-sdk_15

I've also tried to enable C++ support in devenv

languages.cpluscplus.enabled = true;

I've also tried the macOS example from the docs.

I noticed a similar issue (#1641) where installing apple-sdk_15 isn't picked up when entering devenv?

@kyleconroy
Copy link
Author

Also good be related to this work which landed this year https://discourse.nixos.org/t/the-darwin-sdks-have-been-updated/55295/7

@kyleconroy
Copy link
Author

I've confirmed that this is a Bazel issue, as the correct headers are referenced in NIX_CFLAGS_COMPILE

$ echo $NIX_CFLAGS_COMPILE
-isystem /nix/store/67pf95zqmfvllb0bxiqnkdphscn5zxjq-libresolv-83-dev/include 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants