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

Bazel instructions result in missing rules_xcodeproj #4737

Closed
2 tasks done
mattrobmattrob opened this issue Jan 31, 2023 · 1 comment · Fixed by #5112
Closed
2 tasks done

Bazel instructions result in missing rules_xcodeproj #4737

mattrobmattrob opened this issue Jan 31, 2023 · 1 comment · Fixed by #5112

Comments

@mattrobmattrob
Copy link

New Issue Checklist

Describe the bug

Lack of rules_xcodeproj definition when following the WORKSPACE + bazel run -c opt @SwiftLint//:swiftlint README.md definition in a workspace that doesn't already define rules_xcodeproj.

Complete output when running SwiftLint, including the stack trace and command used
$ bazel run -c opt @SwiftLint//:swiftlint
INFO: Invocation ID: 56dcdaec-eba1-4d83-badf-90936d230d2d
ERROR: Skipping '@SwiftLint//:swiftlint': error loading package '@SwiftLint//': Unable to find package for @com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:xcodeproj.bzl: The repository '@com_github_buildbuddy_io_rules_xcodeproj' could not be resolved: Repository '@com_github_buildbuddy_io_rules_xcodeproj' is not defined.
WARNING: Target pattern parsing failed.
ERROR: error loading package '@SwiftLint//': Unable to find package for @com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:xcodeproj.bzl: The repository '@com_github_buildbuddy_io_rules_xcodeproj' could not be resolved: Repository '@com_github_buildbuddy_io_rules_xcodeproj' is not defined.
INFO: Elapsed time: 5.806s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
    currently loading: @SwiftLint//
ERROR: Build failed. Not running target

Environment

WORKSPACE to use bazel run -c opt @SwiftLint//:swiftlint:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# iOS/macOS

http_archive(
    name = "build_bazel_rules_apple",
    sha256 = "43737f28a578d8d8d7ab7df2fb80225a6b23b9af9655fcdc66ae38eb2abcf2ed",
    url = "https://github.com/bazelbuild/rules_apple/releases/download/2.0.0/rules_apple.2.0.0.tar.gz",
)

load(
    "@build_bazel_rules_apple//apple:repositories.bzl",
    "apple_rules_dependencies",
)

apple_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

load(
    "@build_bazel_apple_support//lib:repositories.bzl",
    "apple_support_dependencies",
)

apple_support_dependencies()

# Buildifier

http_archive(
    name = "buildifier_prebuilt",
    sha256 = "f7093a960a8c3471552764892ce12cb62d9b72600fa4c8b08b2090c45db05ce8",
    strip_prefix = "buildifier-prebuilt-6.0.0.1",
    urls = [
        "http://github.com/keith/buildifier-prebuilt/archive/6.0.0.1.tar.gz",
    ],
)

load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()

# Swiftlint

http_archive(
    name = "SwiftLint",
    sha256 = "b8c4d765bcd8b533fcc2e15f32482a1a17572f143b65af388f7d5ac99994a99a",
    url = "https://github.com/realm/SwiftLint/releases/download/0.50.3/bazel.tar.gz",
)

load("@SwiftLint//bazel:repos.bzl", "swiftlint_repos")

swiftlint_repos()

load("@SwiftLint//bazel:deps.bzl", "swiftlint_deps")

swiftlint_deps()

And then when a manual rules_xcodeproj is added to the WORKSPACE, the result is:

$ bazel run -c opt @SwiftLint//:swiftlint
INFO: Invocation ID: eeacd70a-15dd-475b-a735-db522030d3d7
ERROR: Traceback (most recent call last):
	File "/private/var/tmp/_bazel_mattrobinson/59b651be9fad7ee938075f15ae116bb3/external/com_github_apple_swift_syntax/BUILD.bazel", line 6, column 16, in <toplevel>
		srcs = glob(["Sources/_CSwiftSyntax/src/*.c"]),
Error in glob: glob pattern 'Sources/_CSwiftSyntax/src/*.c' didn't match anything, but allow_empty is set to False (the default value of allow_empty can be set with --incompatible_disallow_empty_glob).
ERROR: /private/var/tmp/_bazel_mattrobinson/59b651be9fad7ee938075f15ae116bb3/external/SwiftLint/BUILD:15:14: no such target '@com_github_apple_swift_syntax//:optlibs': target 'optlibs' not declared in package '' defined by /private/var/tmp/_bazel_mattrobinson/59b651be9fad7ee938075f15ae116bb3/external/com_github_apple_swift_syntax/BUILD.bazel (Tip: use `query "@com_github_apple_swift_syntax//:*"` to see all the targets in that package) and referenced by '@SwiftLint//:SwiftLintFramework'
ERROR: Analysis of target '@SwiftLint//:swiftlint' failed; build aborted: 
INFO: Elapsed time: 0.372s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
ERROR: Build failed. Not running target
@thii
Copy link
Contributor

thii commented Feb 11, 2023

I've just bumped into the same issue.

It looks like SwiftLint currently require rules_apple and rules_xcodeproj just because the top-level BUILD file where the @SwiftLint//:swiftlint target is defined is loading apple_universal_binary and xcodeproj. @jpsim Can we move those rules_apple and rules_xcodeproj targets elsewhere since I think not all SwiftLint users use rules_apple and rules_xcodeproj?

@mattrobmattrob I think the second issue is because the Bazel version you're using has --incompatible_disallow_empty_glob flipped to true. You can explicitly set it to false (or fix the empty globs in com_github_apple_swift_syntax).

thii added a commit to thii/SwiftLint that referenced this issue Feb 17, 2023
This was needed because the `xcodeproj` target was declared in the same
BUILD file with the `@SwiftLint//:swiftlint` target, so when users run
`bazel run @SwiftLint//:swiftlint`, bazel would try to load
`rules_xcodeproj`.

This only fixes for non-bzlmod case now.

Fixes realm#4737
thii added a commit to thii/SwiftLint that referenced this issue Feb 17, 2023
This was needed because the `xcodeproj` target was declared in the same
BUILD file with the `@SwiftLint//:swiftlint` target, so when users run
`bazel run @SwiftLint//:swiftlint`, bazel would try to load
`rules_xcodeproj`. `rules_xcodeproj` 1.0 allows us to specify the
location of the generated Xcode project, so we don't need this target in
the top-level BUILD file anymore.

This only fixes for non-bzlmod case now.

Fixes realm#4737
@jpsim jpsim linked a pull request Jul 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants