Skip to content

go_cross_binary builds c-shared go lib with error #3480

@farcop

Description

@farcop

What version of rules_go are you using?

v0.38.1

What version of gazelle are you using?

v0.28.0

What version of Bazel are you using?

6.1.0

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

Yes

What operating system and processor architecture are you using?

Macos M1 (arm64)

Any other potentially useful information about your toolchain?

BAZEL_ZIG_CC_VERSION = "v1.0.1"

http_archive(
    name = "bazel-zig-cc",
    sha256 = "e9f82bfb74b3df5ca0e67f4d4989e7f1f7ce3386c295fd7fda881ab91f83e509",
    strip_prefix = "bazel-zig-cc-{}".format(BAZEL_ZIG_CC_VERSION),
    urls = ["https://git.sr.ht/~motiejus/bazel-zig-cc/archive/{}.tar.gz".format(BAZEL_ZIG_CC_VERSION)],
)

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

zig_toolchains()

register_toolchains(
    "@zig_sdk//toolchain:linux_amd64_musl",
    "@zig_sdk//toolchain:linux_arm64_musl",
)

What did you do?

I want to build go shared lib to multiple architectures (linux_amd64 and linux_arm64) with Bazel
Go-code is here https://github.com/kublr/fluent-bit-rabbitmq-output

What did you expect to see?

Build without errors

What did you see instead?

if I used BUILD file below

go_library(
    name = "fluent-bit-rabbitmq-output_lib",
    srcs = [
        "out_rabbitmq.go",
        "record_parser.go",
        "routing_key_creator.go",
        "routing_key_validator.go",
    ],
    cgo = True,
    importpath = "src.kublr.io/kublr/kublr-feature-logging/elk/fluent-bit-rabbitmq-output",
    visibility = ["//visibility:private"],
    deps = [
        "//vendor/github.com/fluent/fluent-bit-go/output",
        "//vendor/github.com/streadway/amqp",
    ],
)

go_binary(
    name = "fluent-bit-rabbitmq-output",
    embed = [":fluent-bit-rabbitmq-output_lib"],
    linkmode = "c-shared",
    visibility = ["//visibility:public"],
    out = "out_rabbitmq.so",
)

[
    go_cross_binary(
        name = "fluent-bit-rabbitmq-output-bin_%s" % architecture, 
        platform = "@zig_sdk//platform:linux_%s" % architecture, 
        target = "fluent-bit-rabbitmq-output",
    ) for architecture in ARCHITECTURES
]

It builds but with error

% bazel build //kublr-feature-logging/elk/fluent-bit-rabbitmq-output:fluent-bit-rabbitmq-output-bin_arm64
INFO: Analyzed target //kublr-feature-logging/elk/fluent-bit-rabbitmq-output:fluent-bit-rabbitmq-output-bin_arm64 (26 packages loaded, 1923 targets configured).
INFO: Found 1 target...
Target //kublr-feature-logging/elk/fluent-bit-rabbitmq-output:fluent-bit-rabbitmq-output-bin_arm64 up-to-date:
  bazel-bin/kublr-feature-logging/elk/fluent-bit-rabbitmq-output/error
  bazel-bin/kublr-feature-logging/elk/fluent-bit-rabbitmq-output/out_rabbitmq.so
INFO: Elapsed time: 29.744s, Critical Path: 29.23s
INFO: 67 processes: 6 internal, 61 darwin-sandbox.
INFO: Build completed successfully, 67 total actions
% cat bazel-bin/kublr-feature-logging/elk/fluent-bit-rabbitmq-output/error

>&2 echo 'cannot run go_cross target "fluent-bit-rabbitmq-output-bin_arm64": underlying target "@//kublr-feature-logging/elk/fluent-bit-rabbitmq-output:fluent-bit-rabbitmq-output" is not executable'
exit 1

Without linkmode = "c-shared" it builds fine.

To eliminate errors in the cross compiler, I can build the project without errors like this

bazel build \
    --platforms @zig_sdk//platform:linux_amd64 \
    --extra_toolchains @zig_sdk//toolchain:linux_amd64_musl \
    //kublr-feature-logging/elk/fluent-bit-rabbitmq-output:fluent-bit-rabbitmq-output

More details here uber/hermetic_cc_toolchain#17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions