Skip to content

Commit 9f9757f

Browse files
committed
working osx toolchain
1 parent fd1cbd3 commit 9f9757f

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

.bazelrc

+4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ run --define kafka_enabled=false
3333

3434
# use multi-arch toolchain
3535
build:cross --crosstool_top=//tools/cross-toolchain:multiarch_toolchain
36+
build:cross --host_platform=@io_bazel_rules_go//go/toolchain:linux_amd64
37+
build:cross --host_crosstool_top=//tools/cross-toolchain:hostonly_toolchain
38+
#build:cross --distinct_host_configuration=true
3639

3740
# toolchain build debug config
3841
build:debug --sandbox_debug
3942
build:debug --toolchain_resolution_debug
4043
build:debug --verbose_failures
44+
build:debug -s
4145

4246
# Docker Sandbox Mode - Note all docker sandbox configs must run from a linux x86_64 host
4347
build:docker-sandbox --experimental_docker_image=suburbandad/cross-clang-10:latest

tools/cross-toolchain/BUILD

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load(":cc_toolchain_config_linux_arm64.bzl", "arm64_cc_toolchain_config")
43
load(":cc_toolchain_config_osx.bzl", "osx_cc_toolchain_config")
4+
load(":cc_toolchain_config_linux_arm64.bzl", "arm64_cc_toolchain_config")
55

66
cc_toolchain_suite(
77
name = "multiarch_toolchain",
@@ -14,6 +14,13 @@ cc_toolchain_suite(
1414
},
1515
)
1616

17+
cc_toolchain_suite(
18+
name = "hostonly_toolchain",
19+
toolchains = {
20+
"k8": "cc-clang-amd64",
21+
},
22+
)
23+
1724
filegroup(
1825
name = "empty",
1926
srcs = [],

tools/cross-toolchain/cc_toolchain_config_osx.bzl

+6-25
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ load(
2020

2121
def _impl(ctx):
2222
toolchain_identifier = "osxcross"
23-
compiler = "gcc"
23+
compiler = "clang"
2424
abi_version = "darwin_x86_64"
2525
abi_libc_version = "darwin_x86_64"
2626
install = "/usr/x86_64-apple-darwin/"
@@ -31,12 +31,12 @@ def _impl(ctx):
3131
osxcross_binprefix = osxcross + "bin/x86_64-apple-darwin14-"
3232
sdkroot = osxcross + "SDK/MacOSX10.10.sdk/"
3333
cross_system_include_dirs = [
34-
#"/usr/lib/clang/10.0.0/include",
34+
"/usr/lib/clang/10.0.0/include",
3535
osxcross + "include",
3636
sdkroot + "usr/include",
37-
sdkroot + "usr/include/c++/v1/",
3837
]
3938
cross_system_lib_dirs = [
39+
"/usr/x86_64-apple-darwin/lib",
4040
sdkroot + "usr/lib",
4141
osxcross + "/lib",
4242
]
@@ -57,7 +57,7 @@ def _impl(ctx):
5757
flag_groups = [
5858
flag_group(
5959
flags = [
60-
"-isysroot " + sdkroot,
60+
"-stdlib=libc++",
6161
"-no-canonical-prefixes",
6262
"-Wno-builtin-macro-redefined",
6363
"-D__DATE__=\"redacted\"",
@@ -85,6 +85,7 @@ def _impl(ctx):
8585
flag_group(
8686
flags = [
8787
"-mlinker-version=400",
88+
"-B " + osxcross + "bin",
8889
"-nostdinc",
8990
"-U_FORTIFY_SOURCE",
9091
"-fstack-protector",
@@ -134,7 +135,6 @@ def _impl(ctx):
134135
flag_groups = [
135136
flag_group(
136137
flags = [
137-
#"-target x86_64-apple-darwin-macho",
138138
"-v",
139139
"-lm",
140140
"-no-canonical-prefixes",
@@ -180,22 +180,6 @@ def _impl(ctx):
180180
],
181181
)
182182

183-
sysroot_feature = feature(
184-
name = "sysroot",
185-
enabled = True,
186-
flag_sets = [
187-
flag_set(
188-
actions = ALL_COMPILE_ACTIONS + ALL_LINK_ACTIONS,
189-
flag_groups = [
190-
flag_group(
191-
expand_if_available = "sysroot",
192-
flags = ["--sysroot=%{sysroot}"],
193-
),
194-
],
195-
),
196-
],
197-
)
198-
199183
coverage_feature = feature(
200184
name = "coverage",
201185
flag_sets = [
@@ -227,7 +211,6 @@ def _impl(ctx):
227211
default_compile_flags_feature,
228212
objcopy_embed_flags_feature,
229213
user_compile_flags_feature,
230-
#sysroot_feature,
231214
coverage_feature,
232215
]
233216

@@ -237,7 +220,6 @@ def _impl(ctx):
237220
tool_path(name = "dwp", path = "/usr/bin/dwp"),
238221
tool_path(name = "gcov", path = "/usr/bin/gcov"),
239222
tool_path(name = "nm", path = osxcross_binprefix + "nm"),
240-
#tool_path(name = "objcopy", path = "/usr/bin/objcopy"),
241223
tool_path(name = "objdump", path = osxcross_binprefix + "ObjectDump"),
242224
tool_path(name = "strip", path = osxcross_binprefix + "strip"),
243225
tool_path(name = "gcc", path = osxcross + "bin/o64-clang"),
@@ -249,7 +231,6 @@ def _impl(ctx):
249231
features = features,
250232
abi_version = abi_version,
251233
abi_libc_version = abi_libc_version,
252-
#builtin_sysroot = sysroot,
253234
compiler = compiler,
254235
cxx_builtin_include_directories = cross_system_include_dirs,
255236
host_system_name = "x86_64-unknown-linux-gnu",
@@ -267,4 +248,4 @@ osx_cc_toolchain_config = rule(
267248
"stdlib": attr.string(),
268249
},
269250
provides = [CcToolchainConfigInfo],
270-
)
251+
)

tools/cross-toolchain/cc_toolchain_config_windows.bzl

Whitespace-only changes.

tools/cross-toolchain/install_clang_cross10.sh

+24-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
set -eu
44

5+
OSXCROSS_REPO=tpoechtrager/osxcross
6+
OSXCROSS_SHA1=bee9df6
7+
DARWIN_SDK_URL=https://www.dropbox.com/s/yfbesd249w10lpc/MacOSX10.10.sdk.tar.xz
8+
59
curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-${INSTALL_LLVM_VERSION}/clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
610
-o clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz
711
tar xf clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-linux-gnu-ubuntu-18.04.tar.xz --strip-components=1 -C /usr
@@ -23,18 +27,23 @@ mv /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu/lib/clang/10.0.0/lib/li
2327
rm -rf /clang+llvm-${INSTALL_LLVM_VERSION}-aarch64-linux-gnu
2428

2529
# darwin
26-
curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-${INSTALL_LLVM_VERSION}/clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin.tar.xz \
27-
-o clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin.tar.xz
28-
tar xf clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin.tar.xz
29-
rm -f clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin.tar.xz
30-
mkdir -p /usr/x86_64-apple-darwin/lib/clang/10.0.0
31-
mkdir -p /usr/x86_64-apple-darwin/include/c++
32-
mkdir -p /usr/lib/clang/10.0.0/lib/darwin/
33-
mv /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin/include/c++/v1 /usr/x86_64-apple-darwin/include/c++/
34-
mv /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin/lib/clang/10.0.0/include /usr/x86_64-apple-darwin/lib/clang/10.0.0/
35-
mv /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin/lib/libc++.a /usr/x86_64-apple-darwin/lib/
36-
mv /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin/lib/libc++abi.a /usr/x86_64-apple-darwin/lib/
37-
mv /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin/lib/libunwind.a /usr/x86_64-apple-darwin/lib/
38-
mv /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a /usr/lib/clang/10.0.0/lib/darwin/
39-
mv /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin/lib/clang/10.0.0/lib/darwin/libclang_rt.cc_kext.a /usr/lib/clang/10.0.0/lib/darwin/
40-
rm -rf /clang+llvm-${INSTALL_LLVM_VERSION}-x86_64-apple-darwin
30+
mkdir -p /usr/x86_64-apple-darwin/
31+
mkdir -p /tmp/osxcross && cd "/tmp/osxcross"
32+
curl -sLo osxcross.tar.gz "https://codeload.github.com/${OSXCROSS_REPO}/tar.gz/${OSXCROSS_SHA1}"
33+
tar --strip=1 -xzf osxcross.tar.gz
34+
rm -f osxcross.tar.gz
35+
curl -sLo tarballs/MacOSX10.10.sdk.tar.xz "${DARWIN_SDK_URL}"
36+
yes "" | SDK_VERSION=10.10 OSX_VERSION_MIN=10.10 ./build.sh
37+
mv target /usr/x86_64-apple-darwin/osxcross
38+
mv tools /usr/x86_64-apple-darwin/osxcross/
39+
cd /usr/x86_64-apple-darwin/osxcross/include
40+
ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/ CarbonCore
41+
ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers/ CoreFoundation
42+
ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/ Frameworks
43+
ln -s ../SDK/MacOSX10.10.sdk/System/Library/Frameworks/Security.framework/Versions/A/Headers/ Security
44+
rm -rf /tmp/osxcross
45+
rm -rf "/usr/x86_64-apple-darwin/osxcross/SDK/MacOSX10.10.sdk/usr/share/man"
46+
# symlink ld64.lld
47+
ln -s /usr/x86_64-apple-darwin/osxcross/bin/x86_64-apple-darwin14-ld /usr/x86_64-apple-darwin/osxcross/bin/ld64.lld
48+
#final hack due to linker oddity
49+
ln -s /usr/x86_64-apple-darwin/osxcross/lib/libxar.so.1 /usr/lib

0 commit comments

Comments
 (0)