1

add macos support

+ buildifier
This commit is contained in:
Motiejus Jakštys 2021-06-16 12:44:16 +03:00 committed by Motiejus Jakštys
parent 58a04fbfec
commit 39535dadc5
3 changed files with 67 additions and 48 deletions

View File

@ -34,7 +34,15 @@ tasks:
--platforms @zig_sdk//:aarch64-linux-musl //test:gomusl --platforms @zig_sdk//:aarch64-linux-musl //test:gomusl
file $(./getpath @zig_sdk//:aarch64-linux-musl //test:gomusl) | \ file $(./getpath @zig_sdk//:aarch64-linux-musl //test:gomusl) | \
tee /dev/stderr | grep -q "statically linked" tee /dev/stderr | grep -q "statically linked"
#- test_macos-gnu: | - test_x86_64-macos-gnu: |
# cd bazel-zig-cc; ../bazel build --toolchain_resolution_debug=true \ cd bazel-zig-cc; ../bazel build --toolchain_resolution_debug=true \
# --platforms @zig_sdk//:x86_64-macos-gnu \ --platforms @zig_sdk//:x86_64-macos-gnu \
# //test:gognu //test:gomacos
file $(./getpath @zig_sdk//:x86_64-macos-gnu //test:gomacos) | \
tee /dev/stderr | grep -q "Mach-O 64-bit arm64 executable"
- test_aarch64-macos-gnu: |
cd bazel-zig-cc; ../bazel build --toolchain_resolution_debug=true \
--platforms @zig_sdk//:aarch64-macos-gnu \
//test:gomacos
file $(./getpath @zig_sdk//:aarch64-macos-gnu //test:gomacos) | \
tee /dev/stderr | grep -q "Mach-O 64-bit x86_64 executable"

View File

@ -11,6 +11,19 @@ go_library(
go_binary( go_binary(
name = "gognu", name = "gognu",
embed = [":go_lib"], embed = [":go_lib"],
target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
)
go_binary(
name = "gomacos",
embed = [":go_lib"],
gc_linkopts = [
"-s",
"-w",
"-buildmode=pie",
],
target_compatible_with = ["@platforms//os:macos"],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )

View File

@ -4,7 +4,6 @@ load(":zig_toolchain.bzl", "zig_cc_toolchain_config")
DEFAULT_TOOL_PATHS = { DEFAULT_TOOL_PATHS = {
"ar": "ar", "ar": "ar",
"gcc": "c++", # https://github.com/bazelbuild/bazel/issues/4644 "gcc": "c++", # https://github.com/bazelbuild/bazel/issues/4644
"cpp": "/usr/bin/false", "cpp": "/usr/bin/false",
"gcov": "/usr/bin/false", "gcov": "/usr/bin/false",
"nm": "/usr/bin/false", "nm": "/usr/bin/false",
@ -94,11 +93,10 @@ def toolchain_repositories():
"linux-x86_64": "3e5b4fa3b346e2eae6829dd7ef90e9a0f6e6297cee62017e3d0f0f7c9edfa21e", "linux-x86_64": "3e5b4fa3b346e2eae6829dd7ef90e9a0f6e6297cee62017e3d0f0f7c9edfa21e",
"macos-x86_64": "9b5e3fefa6ae0b1ab26821323df0641f818e72bffc343e194dc60829005d3055", "macos-x86_64": "9b5e3fefa6ae0b1ab26821323df0641f818e72bffc343e194dc60829005d3055",
}, },
host_platform_include_root = { host_platform_include_root = {
"macos-x86_64": "lib/zig/", "macos-x86_64": "lib/zig/",
"linux-x86_64": "lib/", "linux-x86_64": "lib/",
} },
) )
def register_all_toolchains(): def register_all_toolchains():
@ -242,7 +240,7 @@ def zig_build_macro(absolute_path, zig_include_root):
zig_cc_toolchain_config( zig_cc_toolchain_config(
name = target + "_cc_toolchain_config", name = target + "_cc_toolchain_config",
target = target, target = target,
target_suffix = getattr(target_config, 'target_suffix', ''), target_suffix = getattr(target_config, "target_suffix", ""),
tool_paths = absolute_tool_paths, tool_paths = absolute_tool_paths,
cxx_builtin_include_directories = cxx_builtin_include_directories, cxx_builtin_include_directories = cxx_builtin_include_directories,
copts = target_config.copts, copts = target_config.copts,
@ -274,7 +272,7 @@ def zig_build_macro(absolute_path, zig_include_root):
toolchains = { toolchains = {
target_config.bazel_target_cpu: ":%s_cc_toolchain" % target, target_config.bazel_target_cpu: ":%s_cc_toolchain" % target,
}, },
tags = ["manual"] tags = ["manual"],
) )
native.toolchain( native.toolchain(