Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim Alweheshy committed Jan 21, 2025
1 parent 46c38b9 commit 80ec224
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/yoga/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@cgrindel_bazel_starlib//bzltidy:defs.bzl", "tidy")

tidy(
name = "tidy",
targets = [
":update_build_files",
],
)

# MARK: - Gazelle

# Ignore the Swift build folder
# gazelle:exclude .build

gazelle_binary(
name = "gazelle_bin",
languages = [
"@bazel_skylib_gazelle_plugin//bzl",
"@rules_swift_package_manager//gazelle",
],
)

gazelle(
name = "update_build_files",
data = [
"@swift_deps_info//:swift_deps_index",
],
extra_args = [
"-swift_dependency_index=$(location @swift_deps_info//:swift_deps_index)",
],
gazelle = ":gazelle_bin",
)
59 changes: 59 additions & 0 deletions examples/yoga/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
bazel_dep(
name = "rules_swift_package_manager",
version = "0.0.0",
)
local_path_override(
module_name = "rules_swift_package_manager",
path = "../..",
)

bazel_dep(name = "cgrindel_bazel_starlib", version = "0.23.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")

# The apple_support bazel_dep must come before the rules_cc.
# https://github.com/bazelbuild/apple_support#incompatible-toolchain-resolution
bazel_dep(name = "apple_support", version = "1.17.1")
bazel_dep(
name = "rules_swift",
version = "2.3.1",
repo_name = "build_bazel_rules_swift",
)
bazel_dep(
name = "rules_apple",
version = "3.16.1",
repo_name = "build_bazel_rules_apple",
)

bazel_dep(
name = "bazel_skylib_gazelle_plugin",
version = "1.7.1",
dev_dependency = True,
)
bazel_dep(
name = "gazelle",
version = "0.41.0",
dev_dependency = True,
repo_name = "bazel_gazelle",
)

apple_cc_configure = use_extension(
"@apple_support//crosstool:setup.bzl",
"apple_cc_configure_extension",
)
use_repo(apple_cc_configure, "local_config_apple_cc")

swift_deps = use_extension(
"@rules_swift_package_manager//:extensions.bzl",
"swift_deps",
)
swift_deps.from_package(
declare_swift_deps_info = True,
resolved = "//:Package.resolved",
swift = "//:Package.swift",
)
use_repo(
swift_deps,
"swift_deps_info",
"swift_package",
"swiftpkg_yoga",
)
14 changes: 14 additions & 0 deletions examples/yoga/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "yoga",
"kind" : "remoteSourceControl",
"location" : "https://github.com/facebook/yoga",
"state" : {
"revision" : "69b8934429702bd3ab06e8d6f709112a761b474b",
"version" : "3.1.0"
}
}
],
"version" : 2
}
10 changes: 10 additions & 0 deletions examples/yoga/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// swift-tools-version: 6.0

import PackageDescription

let package = Package(
name: "YogaKitExample",
dependencies: [
.package(url: "https://github.com/facebook/yoga.git", from: "3.1.0"),
]
)
4 changes: 4 additions & 0 deletions examples/yoga/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Yoga Example

This example demonstrates support for clang, with a root public headers search paths. For example, the file
`external/swiftpkg_yoga/yoga/module.modulemap` will be duplicated when we have both `sources: ["yoga"],` and `publicHeadersPath: ".",` in `Package.swift`. Removing duplicate from the srcs read is useful in this case.
12 changes: 12 additions & 0 deletions examples/yoga/Tests/YogaTests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test")

swift_test(
name = "YogaTests",
srcs = [
"YogaTests.swift",
],
module_name = "YogaTests",
deps = [
"@swiftpkg_yoga//:yoga",
],
)
9 changes: 9 additions & 0 deletions examples/yoga/Tests/YogaTests/YogaTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@testable import Yoga
import XCTest

class YogaTests: XCTestCase {
func testSomething() {
let view = UIView()
view.flex.isEnabled = true
}
}
1 change: 1 addition & 0 deletions examples/yoga/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Intentionally blank: Using bzlmod
2 changes: 2 additions & 0 deletions examples/yoga/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Intentionally blank
# This exists to force Bazel in bzlmod mode to be strict.
15 changes: 15 additions & 0 deletions examples/yoga/do_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)"

# Use the Bazel binary specified by the integration test. Otherise, fall back
# to bazel.
bazel="${BIT_BAZEL_BINARY:-bazel}"

# Generate Swift external deps and update build files
"${bazel}" run //:tidy

# Ensure that it builds and tests pass
"${bazel}" test //...

0 comments on commit 80ec224

Please sign in to comment.