diff --git a/WORKSPACE b/WORKSPACE index 5106f9d..6100b60 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,3 +1,4 @@ register_toolchains( "//toolchain:cc_toolchain_for_linux_arm64", + "//toolchain_osx:cc_osx_toolchain_for_linux_arm64", ) diff --git a/fill/actuators/BUILD b/fill/actuators/BUILD index 5850ebb..3ffb8ba 100644 --- a/fill/actuators/BUILD +++ b/fill/actuators/BUILD @@ -6,6 +6,7 @@ cc_library( visibility = [ "//fill:__subpackages__", ], + linkopts = ["-L/usr/local/lib"], ) cc_library( diff --git a/fill/setup_mock_wiringpi.sh b/fill/setup_mock_wiringpi.sh index 5739dec..5ef3512 100755 --- a/fill/setup_mock_wiringpi.sh +++ b/fill/setup_mock_wiringpi.sh @@ -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 \ No newline at end of file +export LD_LIBRARY_PATH=/usr/lib diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index cd117f1..0f8d58c 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -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( @@ -93,4 +93,4 @@ cc_toolchain_config = rule( implementation = _impl, attrs = {}, provides = [CcToolchainConfigInfo], -) +) \ No newline at end of file diff --git a/toolchain_osx/BUILD b/toolchain_osx/BUILD new file mode 100644 index 0000000..ece37e9 --- /dev/null +++ b/toolchain_osx/BUILD @@ -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", +) \ No newline at end of file diff --git a/toolchain_osx/cc_toolchain_config.bzl b/toolchain_osx/cc_toolchain_config.bzl new file mode 100644 index 0000000..5541f9c --- /dev/null +++ b/toolchain_osx/cc_toolchain_config.bzl @@ -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], +)