Skip to content

Commit

Permalink
fix: ensure all non-header source files are included in textual_hdrs (
Browse files Browse the repository at this point in the history
#259)

- Include all non-header source files in the `textual_hdrs` for clang
rules. This ensures that source files will be present if the code has an
include for a non-header file (e.g. `#include "foo.c"`).
- Add `soto_example` to confirm that a clang module with this situation
builds properly.

Closes #252.
  • Loading branch information
cgrindel authored Mar 3, 2023
1 parent 53cc37f commit 03fb442
Show file tree
Hide file tree
Showing 19 changed files with 7,395 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# To update these lines, execute
# `bazel run @contrib_rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
query --deleted_packages=examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
build --deleted_packages=examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example
query --deleted_packages=examples/firebase_example,examples/firebase_example/abtesting,examples/firebase_example/abtesting/SharedApp,examples/firebase_example/analytics/AnalyticsExample,examples/firebase_example/appdistribution,examples/firebase_example/appdistribution/AppDistributionExample,examples/firebase_example/appdistribution/AppDistributionTests,examples/http_archive_ext_deps,examples/http_archive_ext_deps/Sources/MyDequeModule,examples/http_archive_ext_deps/Sources/PrintStuff,examples/http_archive_ext_deps/Tests/MyDequeModuleTests,examples/http_archive_ext_deps/third_party,examples/interesting_deps,examples/ios_sim,examples/ios_sim/Sources/Foo,examples/ios_sim/Tests/FooTests,examples/objc_code,examples/phone_number_kit,examples/phone_number_kit/Tests/PhoneNumberKitTests,examples/pkg_manifest_minimal,examples/pkg_manifest_minimal/Sources/MyExecutable,examples/pkg_manifest_minimal/Sources/MyLibrary,examples/pkg_manifest_minimal/Tests/MyLibraryTests,examples/pkg_manifest_minimal/third_party,examples/soto_example,examples/soto_example/Tests/SotoTests,examples/tca_example,examples/tca_example/SwiftUICaseStudies,examples/tca_example/SwiftUICaseStudiesTests,examples/vapor_example,examples/vapor_example/Sources/App,examples/vapor_example/Sources/Run,examples/vapor_example/Tests/AppTests,examples/vapor_example/swift,examples/xcmetrics_example

# Import Shared settings
import %workspace%/shared.bazelrc
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
bazel_version: .bazelversion
- example: pkg_manifest_minimal
bazel_version: "5_4_0"
- example: soto_example
bazel_version: .bazelversion
- example: vapor_example
bazel_version: .bazelversion
- example: firebase_example
Expand Down Expand Up @@ -90,6 +92,8 @@ jobs:
bazel_version: .bazelversion
- example: pkg_manifest_minimal
bazel_version: "5_4_0"
- example: soto_example
bazel_version: .bazelversion
- example: vapor_example
bazel_version: .bazelversion
runs-on: ubuntu-22.04
Expand Down
2 changes: 2 additions & 0 deletions examples/example_infos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ _default_timeout = "long"

_timeouts = {
"firebase_example": "eternal",
"soto_example": "eternal",
"vapor_example": "eternal",
"xcmetrics_example": "eternal",
}
Expand All @@ -111,6 +112,7 @@ _all_os_all_bazel_versions_test_examples = [
]

_all_os_single_bazel_version_test_examples = [
"soto_example",
"vapor_example",
]

Expand Down
13 changes: 13 additions & 0 deletions examples/soto_example/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Import Shared settings
import %workspace%/../../shared.bazelrc

# Import CI settings.
import %workspace%/../../ci.bazelrc

# Try to import a local.rc file; typically, written by CI
try-import %workspace%/../../local.bazelrc

# The CNIOBoringSSL uses C++14 features like 'enable_if_t' macro support.
# For more details on how to enable this in Bazel:
# https://stackoverflow.com/questions/40260242/how-to-set-c-standard-version-when-build-with-bazel/43388168#43388168
build --cxxopt='-std=c++14'
42 changes: 42 additions & 0 deletions examples/soto_example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzltidy:defs.bzl", "tidy")
load("@cgrindel_swift_bazel//swiftpkg:defs.bzl", "swift_update_packages")

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

# MARK: - Gazelle

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

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

gazelle(
name = "update_build_files",
gazelle = ":gazelle_bin",
)

swift_update_packages(
name = "swift_update_pkgs",
gazelle = ":gazelle_bin",
)

bzl_library(
name = "swift_deps",
srcs = ["swift_deps.bzl"],
visibility = ["//visibility:public"],
deps = ["@cgrindel_swift_bazel//swiftpkg:defs"],
)
122 changes: 122 additions & 0 deletions examples/soto_example/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"pins" : [
{
"identity" : "async-http-client",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "864c8d9e0ead5de7ba70b61c8982f89126710863",
"version" : "1.15.0"
}
},
{
"identity" : "jmespath.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/adam-fowler/jmespath.swift.git",
"state" : {
"revision" : "4513d319c4aaa6c3b2ac18e1e6566a803515ad91",
"version" : "1.0.2"
}
},
{
"identity" : "soto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/soto-project/soto.git",
"state" : {
"revision" : "26bd91a43a3e569956b99b7f15aa2709a1a6ff23",
"version" : "6.5.0"
}
},
{
"identity" : "soto-core",
"kind" : "remoteSourceControl",
"location" : "https://github.com/soto-project/soto-core.git",
"state" : {
"revision" : "cf1c872126e4874144ed2f91aa2124e72388abe0",
"version" : "6.4.1"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "ff3d2212b6b093db7f177d0855adbc4ef9c5f036",
"version" : "1.0.3"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
"version" : "1.5.2"
}
},
{
"identity" : "swift-metrics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "e8bced74bc6d747745935e469f45d03f048d6cbd",
"version" : "2.3.4"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "45167b8006448c79dda4b7bd604e07a034c15c49",
"version" : "2.48.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "d75ed708d00353acf173ca23018b6bd46f949464",
"version" : "1.17.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "38feec96bcd929028939107684073554bf01abeb",
"version" : "1.25.2"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3",
"version" : "2.23.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c",
"version" : "1.15.0"
}
}
],
"version" : 2
}
10 changes: 10 additions & 0 deletions examples/soto_example/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// swift-tools-version: 5.7

import PackageDescription

let package = Package(
name: "PhoneNumberKitExample",
dependencies: [
.package(url: "https://github.com/soto-project/soto.git", from: "6.0.0"),
]
)
8 changes: 8 additions & 0 deletions examples/soto_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Soto Example

This example demonstrates support for clang, non-header files being included in other clang
source files. For example, the file
`external/swiftpkg_soto_core/Sources/CSotoExpat/xmltok.c` has a `#include "xmltok_impl.c"`. The
file `external/swiftpkg_soto_core/Sources/CSotoExpat/xmltok_impl.c` has a comment stating
`This file is included!`. Instead of including `xmltok_impl.c` in `srcs`, it should included in
`textual_hdrs`.
11 changes: 11 additions & 0 deletions examples/soto_example/Tests/SotoTests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test")

swift_test(
name = "SotoTests",
srcs = [
"SotoTests.swift",
"main.swift",
],
module_name = "SotoTests",
deps = ["@swiftpkg_soto//:Sources_Soto_SotoS3"],
)
14 changes: 14 additions & 0 deletions examples/soto_example/Tests/SotoTests/SotoTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@testable import SotoS3
import XCTest

class SotoTests: XCTestCase {
func testSomething() {
let bucketName = "soto-getting-started-bucket"
let createBucketRequest = S3.CreateBucketRequest(bucket: bucketName)
XCTAssertEqual(createBucketRequest.bucket, bucketName)
}

static var allTests = [
("testSomething", testSomething),
]
}
7 changes: 7 additions & 0 deletions examples/soto_example/Tests/SotoTests/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if os(Linux)
import XCTest

XCTMain([
testCase(SotoTests.allTests),
])
#endif
84 changes: 84 additions & 0 deletions examples/soto_example/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
workspace(name = "soto_example")

local_repository(
name = "cgrindel_swift_bazel",
path = "../..",
)

load("@cgrindel_swift_bazel//:deps.bzl", "swift_bazel_dependencies")

swift_bazel_dependencies()

load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")

bazel_starlib_dependencies()

# MARK: - Gazelle

# gazelle:repo bazel_gazelle

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

http_archive(
name = "bazel_skylib_gazelle_plugin",
sha256 = "04182233284fcb6545d36b94248fe28186b4d9d574c4131d6a511d5aeb278c46",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-gazelle-plugin-1.4.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.0/bazel-skylib-gazelle-plugin-1.4.0.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace")
load("@cgrindel_swift_bazel//:go_deps.bzl", "swift_bazel_go_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

# Declare Go dependencies before calling go_rules_dependencies.
swift_bazel_go_dependencies()

bazel_skylib_gazelle_plugin_workspace()

go_rules_dependencies()

go_register_toolchains(version = "1.19.5")

gazelle_dependencies()

# MARK: - Swift Toolchain

http_archive(
name = "build_bazel_rules_swift",
sha256 = "32f95dbe6a88eb298aaa790f05065434f32a662c65ec0a6aabdaf6881e4f169f",
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.5.0/rules_swift.1.5.0.tar.gz",
)

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",
)
load("//:swift_deps.bzl", "swift_dependencies")

# gazelle:repository_macro swift_deps.bzl%swift_dependencies
swift_dependencies()

swift_rules_dependencies()

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

swift_rules_extra_dependencies()
18 changes: 18 additions & 0 deletions examples/soto_example/do_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

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

assert_match() {
local pattern=${1}
local actual="${2}"
local err_msg="Expected to match. pattern: ${pattern}, actual: ${actual}"
[[ "${actual}" =~ ${pattern} ]] || (echo >&2 "${err_msg}" && exit 1)
}

# Generate Swift external deps and update build files
bazel run //:tidy

# Ensure that it builds and tests pass
bazel test //...
6 changes: 6 additions & 0 deletions examples/soto_example/set_up_clean_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

# NOTE: This is a placeholder. The phone_number_kit example does not support a clean
# test because some of the targets have been marked as 'manual'.
Loading

0 comments on commit 03fb442

Please sign in to comment.