Skip to content

fix: remove duplicate srcs when evaluating clang files #1452

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/example_infos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ _macos_single_bazel_version_test_examples = [
"xcmetrics_example",
"tca_example",
"symlink_example",
"yoga_example",
]

_linux_single_bazel_version_test_examples = []
Expand Down
33 changes: 33 additions & 0 deletions examples/yoga_example/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_example/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_example/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/yoga_example/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_example/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_example/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_example/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_example/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_example/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_example/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 //...
2 changes: 1 addition & 1 deletion swiftpkg/internal/clang_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _collect_files(

modulemap = None
modulemap_orig_path = None
for orig_path in all_srcs:
for orig_path in depset(all_srcs).to_list():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate how we are getting duplicate sources in the first place?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Package.swift we have publicHeadersPath: ".", which then extends the lookup into . and into ./yoga both of which generate a duplicated module.modulemap src

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be merged first and then I'll update this PR

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you even need this PR, once the other PR merges?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the other PR fixes something different related to picking up public headers unrelated to the compiled target

path = _relativize(orig_path, relative_to)
_root, ext = paths.split_extension(path)
if lists.contains(_HEADER_EXTS, ext):
Expand Down