From b463e7f0aeaaa00f3101df6796f477695337bc13 Mon Sep 17 00:00:00 2001 From: Kuba Kaflik Date: Wed, 30 Aug 2023 14:05:00 +0200 Subject: [PATCH 1/4] GNU ar for MacOS --- microros_utils/library_builder.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/microros_utils/library_builder.py b/microros_utils/library_builder.py index 3fed134..27702d6 100644 --- a/microros_utils/library_builder.py +++ b/microros_utils/library_builder.py @@ -4,7 +4,6 @@ from .utils import run_cmd from .repositories import Repository, Sources - class CMakeToolchain: def __init__(self, path, cc, cxx, ar, cflags, cxxflags): cmake_toolchain = """include(CMakeForceCompiler) @@ -55,7 +54,7 @@ def __init__(self, library_folder, packages_folder, distro, python_env): self.env = {} def run(self, meta, toolchain, user_meta = ""): - if os.path.exists(self.library_path): + if os.path.exists(self.library): print("micro-ROS already built") return @@ -183,6 +182,7 @@ def build_mcu_environment(self, meta_file, toolchain_file, user_meta = ""): sys.exit(1) def package_mcu_library(self): + ar_path = self.resolve_ar_path() aux_folder = self.build_folder + "/aux" shutil.rmtree(aux_folder, ignore_errors=True) @@ -194,12 +194,12 @@ def package_mcu_library(self): if f.endswith('.a'): os.makedirs(aux_folder + "/naming", exist_ok=True) os.chdir(aux_folder + "/naming") - os.system("ar x {}".format(root + "/" + f)) + os.system("{} x {}".format(ar_path, root + "/" + f)) for obj in [x for x in os.listdir() if x.endswith('obj')]: os.rename(obj, '../' + f.split('.')[0] + "__" + obj) os.chdir(aux_folder) - command = "ar rc libmicroros.a $(ls *.o *.obj 2> /dev/null); rm *.o *.obj 2> /dev/null; ranlib libmicroros.a" + command = "%s rc libmicroros.a $(ls *.o *.obj 2> /dev/null); rm *.o *.obj 2> /dev/null; ranlib libmicroros.a" % ar_path result = run_cmd(command) if 0 != result.returncode: @@ -221,3 +221,16 @@ def package_mcu_library(self): if os.path.exists(repeated_path): shutil.copytree(repeated_path, folder_path, copy_function=shutil.move, dirs_exist_ok=True) shutil.rmtree(repeated_path) + + def resolve_ar_path(self): + homebrew_binutils_ar_path = "/opt/homebrew/opt/binutils/bin/ar" + + if sys.platform == "darwin": + if os.path.exists(homebrew_binutils_ar_path): + return homebrew_binutils_ar_path + + print("ERROR: GNU ar not found. ({}) Please install binutils with homebrew: brew install binutils" + .format(homebrew_binutils_ar_path)) + sys.exit(1) + + return "ar" From 733fcfe5389f68bce31b6e013e79763cb0855237 Mon Sep 17 00:00:00 2001 From: Kuba Kaflik Date: Wed, 30 Aug 2023 15:14:03 +0200 Subject: [PATCH 2/4] Fix ranlib for library packaging --- microros_utils/library_builder.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/microros_utils/library_builder.py b/microros_utils/library_builder.py index 27702d6..e4a6895 100644 --- a/microros_utils/library_builder.py +++ b/microros_utils/library_builder.py @@ -182,7 +182,7 @@ def build_mcu_environment(self, meta_file, toolchain_file, user_meta = ""): sys.exit(1) def package_mcu_library(self): - ar_path = self.resolve_ar_path() + binutils_path = self.resolve_binutils_path() aux_folder = self.build_folder + "/aux" shutil.rmtree(aux_folder, ignore_errors=True) @@ -194,12 +194,12 @@ def package_mcu_library(self): if f.endswith('.a'): os.makedirs(aux_folder + "/naming", exist_ok=True) os.chdir(aux_folder + "/naming") - os.system("{} x {}".format(ar_path, root + "/" + f)) + os.system("{}ar x {}".format(binutils_path, root + "/" + f)) for obj in [x for x in os.listdir() if x.endswith('obj')]: os.rename(obj, '../' + f.split('.')[0] + "__" + obj) os.chdir(aux_folder) - command = "%s rc libmicroros.a $(ls *.o *.obj 2> /dev/null); rm *.o *.obj 2> /dev/null; ranlib libmicroros.a" % ar_path + command = "{binutils}ar rc libmicroros.a $(ls *.o *.obj 2> /dev/null); rm *.o *.obj 2> /dev/null; {binutils}ranlib libmicroros.a".format(binutils=binutils_path) result = run_cmd(command) if 0 != result.returncode: @@ -222,15 +222,14 @@ def package_mcu_library(self): shutil.copytree(repeated_path, folder_path, copy_function=shutil.move, dirs_exist_ok=True) shutil.rmtree(repeated_path) - def resolve_ar_path(self): - homebrew_binutils_ar_path = "/opt/homebrew/opt/binutils/bin/ar" - + def resolve_binutils_path(self): if sys.platform == "darwin": - if os.path.exists(homebrew_binutils_ar_path): - return homebrew_binutils_ar_path + homebrew_binutils_path = "/opt/homebrew/opt/binutils/bin/" + if os.path.exists(homebrew_binutils_path): + return homebrew_binutils_path - print("ERROR: GNU ar not found. ({}) Please install binutils with homebrew: brew install binutils" - .format(homebrew_binutils_ar_path)) + print("ERROR: GNU binutils not found. ({}) Please install binutils with homebrew: brew install binutils" + .format(homebrew_binutils_path)) sys.exit(1) - return "ar" + return "" From 47b96434ce1ad7128b8106e6e44fcabf48bcb90f Mon Sep 17 00:00:00 2001 From: Kuba Kaflik Date: Wed, 30 Aug 2023 15:21:18 +0200 Subject: [PATCH 3/4] add README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 1c45809..fd2842e 100755 --- a/README.md +++ b/README.md @@ -52,6 +52,17 @@ The community is encouraged to open pull request with custom use cases. ```bash apt install -y git cmake python3-pip ``` + +### Platform specific requirements + +#### MacOS + +XCode command line tools are distributed with toolchain that is not fully compatible with micro-ROS build process. +To fix this, install GNU [binutils](https://www.gnu.org/software/binutils/) using [Homebrew](https://brew.sh/): + +```bash +brew install binutils +``` ## How to add to your project From e162872bcc52181dd331529a8ff2164e74f0a4fa Mon Sep 17 00:00:00 2001 From: Kuba Kaflik Date: Mon, 4 Sep 2023 14:20:06 +0200 Subject: [PATCH 4/4] Update library_builder.py --- microros_utils/library_builder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/microros_utils/library_builder.py b/microros_utils/library_builder.py index e4a6895..766d8d3 100644 --- a/microros_utils/library_builder.py +++ b/microros_utils/library_builder.py @@ -4,6 +4,7 @@ from .utils import run_cmd from .repositories import Repository, Sources + class CMakeToolchain: def __init__(self, path, cc, cxx, ar, cflags, cxxflags): cmake_toolchain = """include(CMakeForceCompiler)