Skip to content

Commit

Permalink
Fix building for iOS (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith authored Aug 21, 2021
1 parent 4ee863c commit da8952e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 5 deletions.
34 changes: 34 additions & 0 deletions examples/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,37 @@ load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
# Use this as is if you are using the rbe_ubuntu16_04 container,
# otherwise refer to RBE docs.
rbe_autoconfig(name = "buildkite_config")

http_archive(
name = "build_bazel_rules_apple",
sha256 = "0052d452af7742c8f3a4e0929763388a66403de363775db7e90adecb2ba4944b",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.31.3/rules_apple.0.31.3.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",
)

swift_rules_dependencies()

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

swift_rules_extra_dependencies()

load(
"@build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies",
)

apple_support_dependencies()
1 change: 1 addition & 0 deletions examples/third_party/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ test_suite(
"//apr:apr_build_test",
"//apr_util:apr_util_build_test",
"//cares:test_c_ares",
"//cares:test_c_ares_ios",
"//curl:curl_test_suite",
"//gn:gn_launch_test",
"//gperftools:test",
Expand Down
36 changes: 36 additions & 0 deletions examples/third_party/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,39 @@ local_repository(
load("//:repositories.bzl", "repositories")

repositories()

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

http_archive(
name = "build_bazel_rules_apple",
sha256 = "0052d452af7742c8f3a4e0929763388a66403de363775db7e90adecb2ba4944b",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.31.3/rules_apple.0.31.3.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",
)

swift_rules_dependencies()

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

swift_rules_extra_dependencies()

load(
"@build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies",
)

apple_support_dependencies()
18 changes: 17 additions & 1 deletion examples/third_party/cares/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_build_test")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

cc_test(
name = "test_c_ares",
srcs = ["c-ares-test.cpp"],
visibility = ["//:__pkg__"],
deps = ["@cares"],
)

cc_library(
name = "ios_lib",
srcs = ["c-ares-test.cpp"],
tags = ["manual"],
deps = ["@cares"],
)

ios_build_test(
name = "test_c_ares_ios",
minimum_os_version = "12.0",
tags = ["manual"],
targets = ["ios_lib"],
visibility = ["//:__pkg__"],
)
15 changes: 11 additions & 4 deletions foreign_cc/private/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ load(
"script_extension",
"shebang",
)
load("//foreign_cc/private/framework:platform.bzl", "os_name")
load(
":cc_toolchain_util.bzl",
"LibrariesToLinkInfo",
Expand Down Expand Up @@ -280,15 +279,23 @@ def get_env_prelude(ctx, lib_name, data_dependencies, target_root):
"export EXT_BUILD_DEPS=$$INSTALLDIR$$.ext_build_deps",
]

if os_name(ctx) == "macos":
env_snippet.extend(["export DEVELOPER_DIR=\"$(xcode-select --print-path)\"", "export SDKROOT=\"$(xcrun --sdk macosx --show-sdk-path)\""])

env = dict()

# Add all environment variables from the cc_toolchain
cc_env = _correct_path_variable(get_env_vars(ctx))
env.update(cc_env)

# This logic mirrors XcodeLocalEnvProvider#querySdkRoot in bazel itself
if "APPLE_SDK_PLATFORM" in cc_env:
platform = cc_env["APPLE_SDK_PLATFORM"]
version = cc_env["APPLE_SDK_VERSION_OVERRIDE"]
sdk = "{}{}".format(platform.lower(), version)
env_snippet.extend([
# TODO: This path needs to take cc_env["XCODE_VERSION_OVERRIDE"] into account
"export DEVELOPER_DIR=\"$(xcode-select --print-path)\"",
"export SDKROOT=\"$(xcrun --sdk {} --show-sdk-path)\"".format(sdk),
])

cc_toolchain = find_cpp_toolchain(ctx)
if cc_toolchain.compiler == "msvc-cl":
# Prepend PATH environment variable with the path to the toolchain linker, which prevents MSYS using its linker (/usr/bin/link.exe) rather than the MSVC linker (both are named "link.exe")
Expand Down

0 comments on commit da8952e

Please sign in to comment.