diff --git a/.bazelrc b/.bazelrc index e41bccdd2..373a11347 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,6 @@ build --strategy=ObjcLink=standalone build --disk_cache=/tmp/bazel build --swiftcopt=-whole-module-optimization + +try-import clang.bazelrc + diff --git a/BUILD b/BUILD index 32888c2d0..bbf1686f9 100644 --- a/BUILD +++ b/BUILD @@ -3,11 +3,11 @@ licenses(["notice"]) load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") package( - default_visibility = ["//visibility:public"], + default_visibility = ["//visibility:public"], ) exports_files([ - "LICENSE", + "LICENSE", ]) swift_library( diff --git a/bazel/setup_clang.sh b/bazel/setup_clang.sh new file mode 100755 index 000000000..0ed987b9d --- /dev/null +++ b/bazel/setup_clang.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +BAZELRC_FILE="${BAZELRC_FILE:-$(bazel info workspace)/clang.bazelrc}" + +LLVM_PREFIX=$1 + +if [[ ! -e "${LLVM_PREFIX}/bin/llvm-config" ]]; then + echo "Error: cannot find llvm-config in ${LLVM_PREFIX}." + exit 1 +fi + +export PATH="$(${LLVM_PREFIX}/bin/llvm-config --bindir):${PATH}" + +RT_LIBRARY_PATH="$(dirname $(find $(llvm-config --libdir) -name libclang_rt.ubsan_standalone_cxx-x86_64.a | head -1))" + +echo "# Generated file, do not edit. If you want to disable clang, just delete this file. +build:clang --action_env='PATH=${PATH}' +build:clang --action_env=CC=clang +build:clang --action_env=CXX=clang++ +build:clang --action_env='LLVM_CONFIG=${LLVM_PREFIX}/bin/llvm-config' +build:clang --repo_env='LLVM_CONFIG=${LLVM_PREFIX}/bin/llvm-config' +build:clang --linkopt='-L$(llvm-config --libdir)' +build:clang --linkopt='-Wl,-rpath,$(llvm-config --libdir)' + +build:clang-asan --action_env=ENVOY_UBSAN_VPTR=1 +build:clang-asan --copt=-fsanitize=vptr,function +build:clang-asan --linkopt=-fsanitize=vptr,function +build:clang-asan --linkopt='-L${RT_LIBRARY_PATH}' +build:clang-asan --linkopt=-l:libclang_rt.ubsan_standalone-x86_64.a +build:clang-asan --linkopt=-l:libclang_rt.ubsan_standalone_cxx-x86_64.a +" > ${BAZELRC_FILE} + diff --git a/external/swift-atomics.BUILD b/external/swift-atomics.BUILD index 58bb895fe..641b0fe43 100644 --- a/external/swift-atomics.BUILD +++ b/external/swift-atomics.BUILD @@ -4,12 +4,11 @@ package( default_visibility = ["//visibility:public"], ) -objc_library( +cc_library( name = "_AtomicsShims", hdrs = ["Sources/_AtomicsShims/include/_AtomicsShims.h"], srcs = ["Sources/_AtomicsShims/src/_AtomicsShims.c"], - enable_modules = 1, - module_name = "_AtomicsShims", + tags = ["swift_module=_AtomicsShims"], includes = [ "Sources/_AtomicsShims/include/" ] diff --git a/src/BUILD b/src/BUILD index ca299cc5b..dd80adad1 100644 --- a/src/BUILD +++ b/src/BUILD @@ -1,8 +1,7 @@ -objc_library( +cc_library( name = "SQLiteDflatObjC", hdrs = ["sqlite/include/Bridge.h"], - enable_modules = True, - module_name = "SQLiteDflatObjC", + tags = ["swift_module=SQLiteDflatObjC"], visibility = ["//:__pkg__"] ) diff --git a/src/Publisher.swift b/src/Publisher.swift index bda112649..f4503d7cc 100644 --- a/src/Publisher.swift +++ b/src/Publisher.swift @@ -1,3 +1,4 @@ +#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Combine @available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) @@ -61,3 +62,5 @@ open class QueryPublisherBuilder where Element: Equatable { fatalError() } } + +#endif diff --git a/src/Workspace.swift b/src/Workspace.swift index 4d767c9c2..18018c93d 100644 --- a/src/Workspace.swift +++ b/src/Workspace.swift @@ -90,6 +90,7 @@ public protocol Workspace: Queryable { * automatically. */ func subscribe(object: Element, changeHandler: @escaping (_: SubscribedObject) -> Void) -> Subscription where Element: Equatable +#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) // MARK - Combine-compliant /** * Return a publisher for object subscription in Combine. @@ -106,6 +107,7 @@ public protocol Workspace: Queryable { */ @available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) func publisher(for: Element.Type) -> QueryPublisherBuilder where Element: Equatable +#endif } public extension Workspace {