-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
builds with cgo appear to miss .S assembly files #3411
Comments
Looks like an incarnation of #2006. |
I've also tried axing the asm build by passing in
This also works correctly with the native golang toolchain. |
* update * gzl * Using zstd workaround from @tals, per github.com/bazel-contrib/rules_go/issues/3411 * gaz * hacky patch --------- Co-authored-by: rkapka <[email protected]> Co-authored-by: james-prysm <[email protected]> Co-authored-by: Preston Van Loon <[email protected]> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
I hit this when trying to build go-ethereum - this PR fixes this by patching the build files but would be good if this just worked! https://github.com/aspect-build/rules_sol/pull/8/files#diff-1f2c31b701f066691b4a4024644f86e092ab731eb81cc5d6282017fe485082ae |
Having debugged this a bit: It seems to me like there are two problems:
I added a small demo program here which reproduces this error in a simpler context: https://github.com/evanj/rulesgotest/tree/main/cgoexample_asm
|
@evanj Thanks for the detailed investigation! Would you be interested in working on a fix for one or both of the issues you identified? I could support you along the way. |
I'm going to investigate a bit in some spare time. Meanwhile: the patch approach is a viable workaround. I have an updated version of the patch from #3411 (comment) that works with the latest bazel/rules_go/zstd: https://gist.github.com/evanj/5f9619ace7a18a5acb8a1be9b9d4df23 |
* compilepkg: cgo assembly uses the C compiler This changes compilepkg to use the C compiler for .S and .s files to use the C compiler, like go build does. Previously it would use the Go assembler, which is used for pure Go packages. This should help fix issue: #3411 I have added a cgo test for this issue that is intended to work with both arm64 and amd64 machines. I have only tested it on Linux amd64 and Darwin arm64. Without this change it fails to build with the following output. This fails to parse the assembly file because it uses the Go assembler. ERROR: rules_go/tests/core/cgo/asm/BUILD.bazel:3:11: GoCompilePkg tests/core/cgo/asm/asm.a failed: (Exit 1): builder failed: error executing command (from target //tests/core/cgo/asm:asm) bazel-out/k8-opt-exec-2B5CBBC6/bin/external/go_sdk/builder_reset/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src tests/core/cgo/asm/cgoasm.go -src tests/core/cgo/asm/asm_amd64.S ... tests/core/cgo/asm/asm_amd64.S:4: expected identifier, found "." asm: assembly of tests/core/cgo/asm/asm_amd64.S failed compilepkg: error running subcommand external/go_sdk/pkg/tool/linux_amd64/asm: exit status 1 * add build constraint: unix && (amd64 || arm64) * run buildifier; make asm conditional * assembly fixes for Mac OS X and Linux * Change build constraint to (amd64 || arm64): Should work on Windows The tests were failing on Windows because rules_go incorrectly believed this was a "native" Go package. I think this should work on Windows. --------- Co-authored-by: Fabian Meumertzheim <[email protected]>
* cgo packages with assembly: Support CGO_ENABLED=0 Go supports building cgo packages both with and without Cgo. It uses build constraints to exclude the appropriate files. When building a Cgo package with assembly files, we must exclude them. Previous to this change, rules_go would run the Go assembler on them. This meant that packages which had "conditional" imports of cgo libraries with assembly would fail when compiled with cgo disabled. Add tests for these two cases: * asm_conditional_cgo: A Go package that compiles both with and without Cgo. * asm_dep_conditional_cgo: A Go package that conditionally imports a package with Cgo. Fixes: #3411 * code review improvements: remove unused main; clarify comment
I just confirmed with my independent reproduction that imports |
Great work and thanks for the very instructive example! |
Awesome work @evanj !! |
* downgrade level db * fix current issues * update geth * Fix zstd build. The patch is now longer needed now that bazel-contrib/rules_go#3411 is fixed. * Revert "update geth" This reverts commit 2a7c51a. * change to hex --------- Co-authored-by: Preston Van Loon <[email protected]>
* downgrade level db * fix current issues * update geth * Fix zstd build. The patch is now longer needed now that bazel-contrib/rules_go#3411 is fixed. * Revert "update geth" This reverts commit 2a7c51a. * change to hex --------- Co-authored-by: Preston Van Loon <[email protected]>
* downgrade level db * fix current issues * update geth * Fix zstd build. The patch is now longer needed now that bazel-contrib/rules_go#3411 is fixed. * Revert "update geth" This reverts commit 2a7c51a. * change to hex --------- Co-authored-by: Preston Van Loon <[email protected]>
What version of rules_go are you using?
0.35.0
What version of gazelle are you using?
0.27.0
What version of Bazel are you using?
Build label: 5.4.0
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
Any other potentially useful information about your toolchain?
What did you do?
I am attempting to build Go program using the popular zstd package from DataDog
This library vendors zstd, which includes accelerated operations in the .S file.
This works well with the vanilla go toolchain, however building this via rules_go fails to pick up an .S file for amd64, causing it to fail during link time
The Gazelle-generated project does include the .S file, however:
What did you expect to see?
Hello, World!
What did you see instead?
The text was updated successfully, but these errors were encountered: