Skip to content

Commit

Permalink
Adding OSX toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
bwz5 committed Jan 18, 2025
1 parent d4bb96b commit 34081c8
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 3 deletions.
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
register_toolchains(
"//toolchain:cc_toolchain_for_linux_arm64",
"//toolchain_osx:cc_osx_toolchain_for_linux_arm64",
)
1 change: 1 addition & 0 deletions fill/actuators/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc_library(
visibility = [
"//fill:__subpackages__",
],
linkopts = ["-L/usr/local/lib"],
)

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion fill/setup_mock_wiringpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
BINPATH=$(bazel cquery --output=files //fill/lib/MockWiringPi:mock_wiringpi $1)
sudo rm /usr/lib/libwiringPi.so
sudo cp $BINPATH /usr/lib/libwiringPi.so
export LD_LIBRARY_PATH=/usr/lib
export LD_LIBRARY_PATH=/usr/lib
4 changes: 2 additions & 2 deletions toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Toolchain for cross-compiling from x86 linux (e.g. WSL) to arm linux (e.g. Raspi) """
""" Toolchain for cross-compiling x86 linux (e.g. WSL) to arm linux (e.g. Raspi) """

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load(
Expand Down Expand Up @@ -93,4 +93,4 @@ cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
)
33 changes: 33 additions & 0 deletions toolchain_osx/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load(":cc_toolchain_config.bzl", "cc_toolchain_config")

package(default_visibility = ["//visibility:public"])

cc_toolchain_config(name = "linux_arm64_osx_toolchain_config")
filegroup(name = "empty")

cc_toolchain(
name = "linux_arm64_osx_toolchain",
all_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
toolchain_config = ":linux_arm64_osx_toolchain_config",
toolchain_identifier = "linux_arm64-osx_toolchain",
)

toolchain(
name = "cc_osx_toolchain_for_linux_arm64",
exec_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:osx",
],
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
toolchain = ":linux_arm64_osx_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
98 changes: 98 additions & 0 deletions toolchain_osx/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
""" Toolchain for cross-compiling from aarch64 osx to arm linux (e.g. Raspi) """

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"feature",
"flag_group",
"flag_set",
"tool_path",
)

all_link_actions = [
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.cpp_link_dynamic_library,
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]

def _impl(ctx):
tool_paths = [
tool_path(
name = "gcc",
path = "/opt/homebrew/bin/aarch64-unknown-linux-gnu-gcc-13.3.0",
),
tool_path(
name = "ld",
path = "/bin/false",
),
tool_path(
name = "ar",
path = "/opt/homebrew/bin/aarch64-unknown-linux-gnu-gcc-ar",
),
tool_path(
name = "cpp",
path = "/bin/false",
),
tool_path(
name = "gcov",
path = "/bin/false",
),
tool_path(
name = "nm",
path = "/bin/false",
),
tool_path(
name = "objdump",
path = "/bin/false",
),
tool_path(
name = "strip",
path = "/bin/false",
),
]

features = [
feature(
name = "default_linker_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_link_actions,
flag_groups = ([
flag_group(
flags = [
"-lstdc++",
],
),
]),
),
],
),
]

return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
features = features,
cxx_builtin_include_directories = [
"/opt/homebrew/Cellar/aarch64-unknown-linux-gnu/13.3.0/toolchain/aarch64-unknown-linux-gnu/sysroot/usr/include/",
"/opt/homebrew/Cellar/aarch64-unknown-linux-gnu/13.3.0/toolchain/lib/gcc/aarch64-unknown-linux-gnu/13.3.0/include/",
"/opt/homebrew/Cellar/aarch64-unknown-linux-gnu/13.3.0/toolchain/aarch64-unknown-linux-gnu/include/c++/13.3.0",
"/usr/include",
"/opt/homebrew/include",
],
toolchain_identifier = "local",
host_system_name = "local",
target_system_name = "local",
target_cpu = "aarch64",
target_libc = "unknown",
compiler = "aarch64-unknown-linux-gnu-gcc-13.3.0",
abi_version = "unknown",
abi_libc_version = "unknown",
tool_paths = tool_paths,
)

cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)

0 comments on commit 34081c8

Please sign in to comment.