Skip to content

Commit

Permalink
Use find_cpp_toolchain instead of ctx.fragments.cpp
Browse files Browse the repository at this point in the history
ctx.fragments.cpp is deprecated.

This doesn't fully get us away from deprecated APIs. We should use
cc_common for flags and C/C++ compilation command lines.

Related bazel-contrib#1744
  • Loading branch information
Jay Conrod committed Oct 2, 2018
1 parent 6078760 commit c1f4e2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
7 changes: 3 additions & 4 deletions go/platform/apple.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ PLATFORMS = {
def _apple_version_min(platform, version):
return "-m" + platform.name_in_plist.lower() + "-version-min=" + version

def apple_ensure_options(ctx, env, tags, compiler_options, linker_options):
def apple_ensure_options(ctx, env, tags, compiler_options, linker_options, target_gnu_system_name):
"""apple_ensure_options ensures that, when building an Apple target, the
proper environment, compiler flags and Go tags are correctly set."""
system_name = ctx.fragments.cpp.target_gnu_system_name
platform = PLATFORMS.get(system_name)
platform = PLATFORMS.get(target_gnu_system_name)
if platform == None:
return
if system_name.endswith("-ios"):
if target_gnu_system_name.endswith("-ios"):
tags.append("ios") # needed for stdlib building
if platform in [apple_common.platform.ios_device, apple_common.platform.ios_simulator]:
min_version = _apple_version_min(platform, "7.0")
Expand Down
20 changes: 12 additions & 8 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load(
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
"find_cpp_toolchain",
)
load(
"@io_bazel_rules_go//go/private:providers.bzl",
"EXPLICIT_PATH",
Expand Down Expand Up @@ -326,26 +330,26 @@ def go_context(ctx, attr = None):
)

def _go_context_data(ctx):
cpp = ctx.fragments.cpp
cpp = find_cpp_toolchain(ctx)
features = ctx.features
compiler_options = _filter_options(
cpp.compiler_options(features) + cpp.unfiltered_compiler_options(features),
cpp.compiler_options() + cpp.unfiltered_compiler_options(features),
_COMPILER_OPTIONS_BLACKLIST,
)
linker_options = _filter_options(
cpp.link_options + cpp.mostly_static_link_options(features, False),
cpp.mostly_static_link_options(False),
_LINKER_OPTIONS_BLACKLIST,
)

env = {}
tags = []
if "gotags" in ctx.var:
tags = ctx.var["gotags"].split(",")
apple_ensure_options(ctx, env, tags, compiler_options, linker_options)
apple_ensure_options(ctx, env, tags, compiler_options, linker_options, cpp.target_gnu_system_name)
compiler_path, _ = cpp.ld_executable.rsplit("/", 1)
return struct(
strip = ctx.attr.strip,
crosstool = ctx.files._crosstool,
crosstool = ctx.files._cc_toolchain,
tags = tags,
env = env,
cgo_tools = struct(
Expand All @@ -355,18 +359,18 @@ def _go_context_data(ctx):
compiler_options = compiler_options,
linker_options = linker_options,
options = compiler_options + linker_options,
c_options = cpp.c_options,
c_options = cpp.c_options(),
),
)

go_context_data = rule(
_go_context_data,
attrs = {
"strip": attr.string(mandatory = True),
"_crosstool": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
"_xcode_config": attr.label(
default = "@bazel_tools//tools/osx:current_xcode_config",
),
},
fragments = ["cpp", "apple"],
fragments = ["apple"],
)
5 changes: 1 addition & 4 deletions tests/bazel_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ _bazel_test_script = go_rule(
"check": attr.string(),
"config": attr.string(default = "isolate"),
"extra_files": attr.label_list(allow_files = True),
"data": attr.label_list(
allow_files = True,
cfg = "data",
),
"data": attr.label_list(allow_files = True),
"clean_build": attr.bool(default = False),
"bazelrc": attr.label(
allow_single_file = True,
Expand Down

0 comments on commit c1f4e2d

Please sign in to comment.