Skip to content

Support local OSX SDK #10

@sluongng

Description

@sluongng

Toolchain setup

http_archive(
    name = "bazel-zig-cc",
    sha256 = "e9f82bfb74b3df5ca0e67f4d4989e7f1f7ce3386c295fd7fda881ab91f83e509",
    strip_prefix = "bazel-zig-cc-v1.0.1",
    urls = ["https://github.com/uber/bazel-zig-cc/archive/v1.0.1.tar.gz"],
)

load("@bazel-zig-cc//toolchain:defs.bzl", zig_toolchains = "toolchains")

zig_toolchains()

register_toolchains(
    "@zig_sdk//toolchain:linux_amd64_gnu.2.34",
    "@zig_sdk//toolchain:linux_arm64_gnu.2.34",
    "@zig_sdk//toolchain:darwin_amd64",
    "@zig_sdk//toolchain:darwin_arm64",
)

Error outputs

> bazel build @com_github_mattn_go_ieproxy//...
ERROR: /private/var/tmp/_bazel_sluongng/06e573a93bc2d6a9cad4ad41f00b4310/external/com_github_mattn_go_ieproxy/BUILD.bazel:57:8: GoCompilePkg external/com_github_mattn_go_ieproxy/go-ieproxy_test.internal.a failed: (Exit 1): builder failed: error executing command (from target @com_github_mattn_go_ieproxy//:go-ieproxy_test) bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/go_sdk_darwin_arm64/builder_reset/builder compilepkg -sdk external/go_sdk_darwin_arm64 -installsuffix darwin_arm64 -src ... (remaining 73 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
buildbuddy/external/com_github_mattn_go_ieproxy/ieproxy_darwin.go:7:10: fatal error: 'CFNetwork/CFProxySupport.h' file not found
#include <CFNetwork/CFProxySupport.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
compilepkg: error running subcommand external/go_sdk_darwin_arm64/pkg/tool/darwin_arm64/cgo: exit status 2

Gazelle generated build files

> cat /private/var/tmp/_bazel_sluongng/06e573a93bc2d6a9cad4ad41f00b4310/external/com_github_mattn_go_ieproxy/BUILD.bazel
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "go-ieproxy",
    srcs = [
        "ieproxy.go",
        "ieproxy_darwin.go",
        "ieproxy_unix.go",
        "ieproxy_windows.go",
        "kernel32_data_windows.go",
        "pac_darwin.go",
        "pac_unix.go",
        "pac_windows.go",
        "proxy_middleman.go",
        "proxy_middleman_darwin.go",
        "proxy_middleman_unix.go",
        "proxy_middleman_windows.go",
        "utils.go",
        "winhttp_data_windows.go",
    ],
    cgo = True,
    clinkopts = select({
        "@io_bazel_rules_go//go/platform:darwin": [
            "-framework CFNetwork",
            "-framework CoreFoundation",
        ],
        "@io_bazel_rules_go//go/platform:ios": [
            "-framework CFNetwork",
            "-framework CoreFoundation",
        ],
        "//conditions:default": [],
    }),
    importpath = "github.com/mattn/go-ieproxy",
    visibility = ["//visibility:public"],
    deps = select({
        "@io_bazel_rules_go//go/platform:darwin": [
            "@org_golang_x_net//http/httpproxy",
        ],
        "@io_bazel_rules_go//go/platform:ios": [
            "@org_golang_x_net//http/httpproxy",
        ],
        "@io_bazel_rules_go//go/platform:windows": [
            "@org_golang_x_net//http/httpproxy",
            "@org_golang_x_sys//windows",
            "@org_golang_x_sys//windows/registry",
        ],
        "//conditions:default": [],
    }),
)

alias(
    name = "go_default_library",
    actual = ":go-ieproxy",
    visibility = ["//visibility:public"],
)

go_test(
    name = "go-ieproxy_test",
    srcs = [
        "darwin_test.go",
        "example_test.go",
        "utils_test.go",
        "windows_test.go",
    ],
    embed = [":go-ieproxy"],
)

Bazel version is 6.0.0 on M1 Mac.

Using Grail's toolchain, the sysroot is set to OSX SDK dynamically with https://github.com/grailbio/bazel-toolchain/blob/069ee4e20ec605a6c76c1798658e17175b2eb35e/toolchain/internal/sysroot.bzl#L24-L39

Ultimately this should affect cxx_builtin_include_directories and builtin_sysroot attribute when call cc_common. create_cc_toolchain_config_info()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions