Skip to content

Commit

Permalink
Use find_cpp_toolchain instead of ctx.fragments.cpp (#1747)
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 #1744
  • Loading branch information
jayconrod authored and Jay Conrod committed Oct 3, 2018
1 parent 2dd4add commit 8372098
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 @@ -295,26 +299,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,
package_list = ctx.file._package_list,
sdk_root = ctx.file._sdk_root,
sdk_files = ctx.files._sdk_files,
Expand All @@ -328,7 +332,7 @@ 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(),
),
)

Expand All @@ -337,7 +341,7 @@ go_context_data = rule(
attrs = {
"strip": attr.string(mandatory = True),
# Hidden internal attributes
"_crosstool": attr.label(default = Label("//tools/defaults:crosstool")),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
"_package_list": attr.label(
allow_files = True,
single_file = True,
Expand All @@ -360,5 +364,5 @@ go_context_data = rule(
default = Label("@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 @@ -218,10 +218,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_files = True,
Expand Down

0 comments on commit 8372098

Please sign in to comment.