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

Header files produced by linkmode = "c-shared" not part of the go rule outputs #3991

Open
GabrielCFigueira opened this issue Jul 24, 2024 · 2 comments

Comments

@GabrielCFigueira
Copy link

What version of rules_go are you using?

0.40.1

What version of gazelle are you using?

0.28.0

What version of Bazel are you using?

7.2.1

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

Yes (with version 0.49.0 of rules_go and version 0.37.0 of gazelle)

What operating system and processor architecture are you using?

Linux, x86_64

Any other potentially useful information about your toolchain?

Also reproduced the error with remote execution.

What did you do?

I have the following bazel targets:

go_library(
    name = "go_default_library",
    srcs = ["file.go"],
    cgo = True,
    importpath = "path/to/target",
)

go_binary(
    name = "target",
    embed = [":go_default_library"],
    linkmode = "c-shared",
)

It is of my understanding that adding linkmode = "c-shared" creates an additional .so and _cgo_install.h file. So then I have a genrule that consumes this .h file:

genrule(
    name = "rename_header_file",
    outs = ["new_name.h"],
    cmd = """
    cp $$(dirname $(location //path/to/target:target))/_cgo_install.h $@
    """,
    srcs = ["//path/to/target:target"],
)

What did you expect to see?

I expected to be able to run the genrule above, and rename the header file

What did you see instead?

When the --spawn_strategy is local, the outputs of //path/to/target:target are correctly produced: a .so and _cgo_install.h. However, when using --spawn_strategy=processwrapper-sandbox or remote execution, only the .so shows up as an output of //path/to/target:target, and header file is missing, causing the genrule to fail with file not found.
Could it be due to the header file not being part of the outputs of the go_binary rule? Not sure how to proceed here

@fmeum
Copy link
Collaborator

fmeum commented Jul 24, 2024

The header file should be part of the CcInfo provider returned by the go_binary target. You can inspect it with bazel cquery --output=starlark --starlark:expr='providers(target)' //:target.

The header file is not a standard "file to build" that you could access via a regular genrule. What do you want to do with the file?

@GabrielCFigueira
Copy link
Author

GabrielCFigueira commented Jul 24, 2024

Hey, thanks for the quick answer. The file is then supposed to be used by a cc_library, like this:

cc_library(
    name ="something",
    hdrs = [":new_name.h"]
    includes = ["."],
    deps = ["//path/to/target:target"],
)

cc_library(
    name = "another",
    srcs = glob(["*.cpp"]),
    hdrs = glob(["*.h"]),
    deps = [
        ":something",
    ],
)

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

No branches or pull requests

2 participants