cgrindel / rules_swift_package_manager

Collection of utilities and Bazel rules to aid in the development and maintenance of Swift repositories using Bazel.
Apache License 2.0
74 stars 29 forks source link

Possible incompatibility with Yams? #1198

Open ileitch opened 2 months ago

ileitch commented 2 months ago
$ bazel run //:update_build_files

gazelle: failed to create swift.SwiftFileInfo for /Users/me/code/peripheryapp/periphery/.build/checkouts/Yams/Tests/main.swift. open /Users/me/code/peripheryapp/periphery/.build/checkouts/Yams/Tests/main.swift: no such file or directory
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x10515aa6c]

...

Steps to reproduce:

  1. git clone git@github.com:peripheryapp/periphery.git
  2. cd periphery
  3. git checkout bazel-swiftpm
  4. swift package resolve
  5. bazel run //:update_build_files

It looks like this select in the Yams project isn't being evaluated correctly. Is there somewhere I need to configure rules_swift_package_manager to only build for macos, or is this an incompatibility with Yams? Alternatively, is it possible to exclude the Yams test targets from the analysis?

Environment:

cgrindel commented 2 months ago

I am a little surprised that is being picked up. rules_swift_package_manager deletes existing Bazel build files for Swift packages. The delete logic is here. 🤔

cgrindel commented 2 months ago

I just attempted to reproduce the issue. I am seeing a build error:

ERROR: /private/var/tmp/_bazel_chuck/1d745b1f8c4c04cbd181f13871d2aaa3/external/rules_go~/BUILD.bazel:42:7: GoStdlib external/rules_go~/stdlib_/pkg [for tool] failed: (Exit 1): builder failed: error executing GoStdlib command (from target @@rules_go~//:stdlib)
  (cd /private/var/tmp/_bazel_chuck/1d745b1f8c4c04cbd181f13871d2aaa3/sandbox/darwin-sandbox/2/execroot/_main && \
  exec env - \
    CC=external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh \
    CGO_CFLAGS='-U_FORTIFY_SOURCE -fstack-protector -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -O2 -D_FORTIFY_SOURCE=1 -DNDEBUG -ffunction-sections -fdata-sections -mmacosx-version-min=14.4 -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted"' \
    CGO_ENABLED=1 \
    CGO_LDFLAGS='-mmacosx-version-min=14.4 -no-canonical-prefixes -fobjc-link-runtime -headerpad_max_install_names -Wl,-dead_strip -lm' \
    GOARCH=amd64 \
    GOEXPERIMENT=nocoverageredesign \
    GOOS=darwin \
    GOPATH='' \
    GOROOT=external/rules_go~~go_sdk~go_default_sdk \
    GOROOT_FINAL=GOROOT \
    GOTOOLCHAIN=local \
    PATH=/Applications/Xcode-15.3.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:external/bazel_tools~cc_configure_extension~local_config_cc:/bin:/usr/bin \
    ZERO_AR_DATE=1 \
  bazel-out/darwin_x86_64-opt-exec-ST-d57f47055a04/bin/external/rules_go~~go_sdk~go_default_sdk/builder_reset/builder stdlib -sdk external/rules_go~~go_sdk~go_default_sdk -installsuffix darwin_amd64 -out bazel-out/darwin_x86_64-opt-exec-ST-d57f47055a04/bin/external/rules_go~/stdlib_ -package std -package runtime/cgo -gcflags '')
# Configuration: 472ee93f664283993c12a8846b7e08c17338e9e8797c5cf86698c875fac858f8
# Execution platform: @@platforms//host:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
# runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found
stdlib: error running subcommand external/rules_go~~go_sdk~go_default_sdk/bin/go: exit status 1
Target //:update_build_files failed to build
cgrindel commented 2 months ago

I will install Xcode 15.4 and try again.

jpsim commented 2 months ago

Interesting! Let me know if I can help by making any changes to Yams. What's interesting is that I've been using rspm with Yams for a year without issue.

luispadron commented 1 month ago

Maybe what's happening here is that the .build directory is being recreated outside of this Bazel rule. This can happen for many reasons like resolving the package or having an editor for Swift/SPM which resolves these files.

We have also been using Yams and other repositories via rules_swift_package_manager which also have BUILD files in their repository without issue but that's potentially because we add the .build to our .bazelignore file so that its never part of the build.