Skip to content

Commit

Permalink
[WIP] Bazel support (#14)
Browse files Browse the repository at this point in the history
* Added .bazelversion and updated gitignore.

* Added bazel files.

* fixup! Added bazel files.

* Generated bazel files. Having trouble with the test fixtures and Bundle.

* Treat helloworld.swift as txt since is just a fixture and reference for
the binary under the tests/.../fixture folder.

* Added tidy macro.

* fixup! Added tidy macro.

* Added some configs to .bazelrc
  • Loading branch information
dirtyhabits97 authored Apr 19, 2024
1 parent 812c541 commit 081c1b9
Show file tree
Hide file tree
Showing 13 changed files with 3,664 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
common --enable_bzlmod

# Verbose Failures
build --verbose_failures

# Test output information
test --test_output=errors --test_summary=detailed

# Strict PATH. Helps prevent build cache invalidation due to PATH differences.
build --incompatible_strict_action_env=true

# Set minimum macOS version
# This prevents the tests from failing
build --macos_minimum_os=13.0
build --host_macos_minimum_os=13.0

# Configure Apple CC toolchain
# https://github.com/bazelbuild/apple_support#toolchain-setup
build --enable_platform_specific_config
build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain
build:macos --crosstool_top=@local_config_apple_cc//:toolchain
build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.2
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
# gitignore template for Bazel build system
# website: https://bazel.build/

# Ignore all bazel-* symlinks. There is no full list since this can change
# based on the name of the directory bazel is cloned into.
/bazel-*
54 changes: 54 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
load("@gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@rules_swift_package_manager//swiftpkg:defs.bzl", "swift_update_packages")
load("@cgrindel_bazel_starlib//bzltidy:defs.bzl", "tidy")

# Ignore the `.build` folder that is created by running Swift package manager
# commands. The Swift Gazelle plugin executes some Swift package manager
# commands to resolve external dependencies. This results in a `.build` file
# being created.
# NOTE: Swift package manager is not used to build any of the external packages.
# The `.build` directory should be ignored. Be sure to configure your source
# control to ignore it (i.e., add it to your `.gitignore`).
# gazelle:exclude .build

# This declaration builds a Gazelle binary that incorporates all of the Gazelle
# plugins for the languages that you use in your workspace. In this example, we
# are only listing the Gazelle plugin for Swift from rules_swift_package_manager.
gazelle_binary(
name = "gazelle_bin",
languages = [
"@rules_swift_package_manager//gazelle",
],
)

# This macro defines two targets: `swift_update_pkgs` and
# `swift_update_pkgs_to_latest`.
#
# The `swift_update_pkgs` target should be run whenever the list of external
# dependencies is updated in the `Package.swift`. Running this target will
# populate the `swift_deps.bzl` with `swift_package` declarations for all of
# the direct and transitive Swift packages that your project uses.
#
# The `swift_update_pkgs_to_latest` target should be run when you want to
# update your Swift dependencies to their latest eligible version.
swift_update_packages(
name = "swift_update_pkgs",
gazelle = ":gazelle_bin",
generate_swift_deps_for_workspace = False,
update_bzlmod_stanzas = True,
)

# This target updates the Bazel build files for your project. Run this target
# whenever you add or remove source files from your project.
gazelle(
name = "update_build_files",
gazelle = ":gazelle_bin",
)

tidy(
name = "tidy",
targets = [
":swift_update_pkgs",
":update_build_files",
],
)
22 changes: 22 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Source: https://www.buildbuddy.io/blog/how-to-migrate-an-ios-app-to-bazel/#swift-packages-swiftpm
bazel_dep(name = "apple_support", version = "1.14.0")
bazel_dep(name = "rules_swift", version = "1.16.0", repo_name = "build_bazel_rules_swift")
# Support swift-package-manager
bazel_dep(name = "rules_swift_package_manager", version = "0.29.2")
bazel_dep(name = "gazelle", version = "0.35.0")
# Allows the use of `tidy`
bazel_dep(name = "cgrindel_bazel_starlib", version = "0.18.1")

# swift_deps START
swift_deps = use_extension(
"@rules_swift_package_manager//:extensions.bzl",
"swift_deps",
)
swift_deps.from_file(
deps_index = "//:swift_deps_index.json",
)
use_repo(
swift_deps,
"swiftpkg_swift_argument_parser",
)
# swift_deps END
Loading

0 comments on commit 081c1b9

Please sign in to comment.