Skip to content

Commit 841dc13

Browse files
authored
Use GNU binutils on MacOS (#116)
* GNU ar for MacOS * Fix ranlib for library packaging * add README * Update library_builder.py
1 parent fdeb1ea commit 841dc13

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ The community is encouraged to open pull request with custom use cases.
5252
```bash
5353
apt install -y git cmake python3-pip
5454
```
55+
56+
### Platform specific requirements
57+
58+
#### MacOS
59+
60+
XCode command line tools are distributed with toolchain that is not fully compatible with micro-ROS build process.
61+
To fix this, install GNU [binutils](https://www.gnu.org/software/binutils/) using [Homebrew](https://brew.sh/):
62+
63+
```bash
64+
brew install binutils
65+
```
5566

5667
## How to add to your project
5768

microros_utils/library_builder.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, library_folder, packages_folder, distro, python_env):
5555
self.env = {}
5656

5757
def run(self, meta, toolchain, user_meta = ""):
58-
if os.path.exists(self.library_path):
58+
if os.path.exists(self.library):
5959
print("micro-ROS already built")
6060
return
6161

@@ -183,6 +183,7 @@ def build_mcu_environment(self, meta_file, toolchain_file, user_meta = ""):
183183
sys.exit(1)
184184

185185
def package_mcu_library(self):
186+
binutils_path = self.resolve_binutils_path()
186187
aux_folder = self.build_folder + "/aux"
187188

188189
shutil.rmtree(aux_folder, ignore_errors=True)
@@ -194,12 +195,12 @@ def package_mcu_library(self):
194195
if f.endswith('.a'):
195196
os.makedirs(aux_folder + "/naming", exist_ok=True)
196197
os.chdir(aux_folder + "/naming")
197-
os.system("ar x {}".format(root + "/" + f))
198+
os.system("{}ar x {}".format(binutils_path, root + "/" + f))
198199
for obj in [x for x in os.listdir() if x.endswith('obj')]:
199200
os.rename(obj, '../' + f.split('.')[0] + "__" + obj)
200201

201202
os.chdir(aux_folder)
202-
command = "ar rc libmicroros.a $(ls *.o *.obj 2> /dev/null); rm *.o *.obj 2> /dev/null; ranlib libmicroros.a"
203+
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)
203204
result = run_cmd(command)
204205

205206
if 0 != result.returncode:
@@ -221,3 +222,15 @@ def package_mcu_library(self):
221222
if os.path.exists(repeated_path):
222223
shutil.copytree(repeated_path, folder_path, copy_function=shutil.move, dirs_exist_ok=True)
223224
shutil.rmtree(repeated_path)
225+
226+
def resolve_binutils_path(self):
227+
if sys.platform == "darwin":
228+
homebrew_binutils_path = "/opt/homebrew/opt/binutils/bin/"
229+
if os.path.exists(homebrew_binutils_path):
230+
return homebrew_binutils_path
231+
232+
print("ERROR: GNU binutils not found. ({}) Please install binutils with homebrew: brew install binutils"
233+
.format(homebrew_binutils_path))
234+
sys.exit(1)
235+
236+
return ""

0 commit comments

Comments
 (0)