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

[internal] Error when using cgo files #13172

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/python/pants/backend/go/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ class GoModPackageSourcesField(StringSequenceField, AsyncFieldMixin):
default = ("**/*.go", "**/*.s")
help = (
"What sources to generate `go_first_party_package` targets for.\n\n"
"Pants will generate one target per matching directory."
"Pants will generate one target per matching directory.\n\n"
"Pants does not yet support some file types like `.c` and `.h` files, along with cgo "
"files. If you need to use these files, please open a feature request at "
"https://github.com/pantsbuild/pants/issues/new/choose so that we know to "
"prioritize adding support."
)

def _prefix_glob_with_address(self, glob: str) -> str:
Expand Down
9 changes: 9 additions & 0 deletions src/python/pants/backend/go/util_rules/first_party_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ async def compute_first_party_package_info(
),
)
metadata = json.loads(result.stdout)

if "CgoFiles" in metadata:
raise NotImplementedError(
f"The first-party package {request.address} includes `CgoFiles`, which Pants does "
"not yet support. Please open a feature request at "
"https://github.com/pantsbuild/pants/issues/new/choose so that we know to "
"prioritize adding support."
)

return FirstPartyPkgInfo(
digest=pkg_sources.snapshot.digest,
imports=tuple(metadata.get("Imports", [])),
Expand Down
40 changes: 38 additions & 2 deletions src/python/pants/backend/go/util_rules/first_party_pkg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pants.engine.addresses import Address
from pants.engine.fs import PathGlobs, Snapshot
from pants.engine.rules import QueryRule
from pants.testutil.rule_runner import RuleRunner
from pants.testutil.rule_runner import RuleRunner, engine_error


@pytest.fixture
Expand All @@ -34,7 +34,7 @@ def rule_runner() -> RuleRunner:
return rule_runner


def test_resolve_go_package(rule_runner: RuleRunner) -> None:
def test_package_info(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
"foo/BUILD": "go_mod()\n",
Expand Down Expand Up @@ -118,3 +118,39 @@ def assert_info(
test_files=["bar_test.go"],
xtest_files=[],
)


def test_cgo_not_supported(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
"BUILD": "go_mod(name='mod')\n",
"go.mod": dedent(
"""\
module go.example.com/foo
go 1.17
"""
),
"hello.go": dedent(
"""\
package main

// int fortytwo()
// {
// return 42;
// }
import "C"
import "fmt"

func main() {
f := C.intFunc(C.fortytwo)
fmt.Println(C.intFunc(C.fortytwo))
}
"""
),
}
)
with engine_error(NotImplementedError):
rule_runner.request(
FirstPartyPkgInfo,
[FirstPartyPkgInfoRequest(Address("", target_name="mod", generated_name="./"))],
)