-
Notifications
You must be signed in to change notification settings - Fork 22
Use Xcode as system generator and builder on OSX #127
Conversation
@wjwwood sorry for requesting a review from you specifically, but given that you're the one who uses OSX to work on ROS2, I thought you'd the most appropriate for checking out this. However, if anyone else on the @ros2/team feels like having a look at the changes, please feel free to do so. I believe the changes in this PR can be merged because they:
|
@esteve the changes look ok to me, but I would like to preserve the capability to build with make on macOS, something like a |
Just for some of my thinking behind that desire... Xcode is not currently a requirement for building ROS 2 because you can just install "Command Line Tools" and avoid Xcode, which requires an apple account (I think that's still the case anyways). Also, I like to go into my build folders and run But still, the ability to run in Xcode is pretty nice. Luckily I don't think it will be difficult to make this switch optional. |
@wjwwood probably bad phrasing on my part in my previous comment, but Xcode is not really a requirement for this. Another option, if you want to keep the Make-based system is to check what generator was used (CMake's |
@wjwwood what I mean is that, analogously to this code: https://github.com/esteve/ament_tools/blob/xcode/ament_tools/build_types/cmake.py#L410-L435 something similar could be done in the build phase:
and default to the Make generator. IMHO What do you think? I can write that logic, but it'd be good to run a CI build with Xcode as the generator as well. |
I don't actually mind what the default is on macOS (as long as it comes with CLT and doesn't introduce regressions), but I do think there should be a way to use |
@wjwwood I've updated the PR to support both Make and Xcode, I've left Xcode as the default, but it can easily be changed to Make here: https://github.com/esteve/ament_tools/blob/xcode/ament_tools/build_types/cmake.py#L171-L172 to override the default, the user can pass the However, I had always tested with PR without |
With the downside of not being able to use the symlink installs (not sure if that could be fixed, I don't have a platform with multi-config to test this on) I would propose to keep
I would suggest adding a option Please see #144 for a different PR adding support for Ninja which will likely interfere with this. |
@dirk-thomas I agree, it makes sense. I've made the Make generator the default again (and more explicit see https://github.com/esteve/ament_tools/blob/xcode/ament_tools/build_types/cmake.py#L181) and added a Since it's not the default, I also added As for the issue with multi-config generators and symlink installs, should I submit a PR with the change in esteve/ament_cmake@9c27a52 ? |
It would be good to separate that change. I don't see why the symlinks install should need to be disabled. It is supposed to replace the normal install rules transparently - and those obviously work for multi configuration generators. So it looks like the symlinks install stuff needs to be modified somehow to work in that scenario. |
@dirk-thomas this issue hadn't show up yet because the only multi config generator that's in use in ROS 2.0 is Visual Studio's and symlinks are not supported in Windows. However, macOS supports symlinks but the Xcode generator fails with the code here: invoking ament with
|
elif IS_MACOSX: | ||
if self._using_xcode_generator(context): | ||
if XCODEBUILD_EXECUTABLE is None: | ||
raise VerbExecutionError("Could not find 'xcodebuild' executable") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this prevent building with Makefiles
when xcodebuild
is not available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just based on the code, I think this only happens when you've specified that you want to use the xcode generator.
ament_tools/build_types/cmake.py
Outdated
flag.replace( | ||
'-j', '-IDEBuildOperationMaxNumberOfConcurrentCompileTasks=')) | ||
else: | ||
xcodebuild_flags.append(flag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is a bit difficult to follow. Shouldn't this be the equivalent of:
if flag.startswith('-j'):
xcodebuild_flags.append(flag.replace(
'-j', '-IDEBuildOperationMaxNumberOfConcurrentCompileTasks='))
elif not flag.startswith('-l'):
xcodebuild_flags.append(flag)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍, the altered logic is easier to read I think.
ament_tools/build_types/cmake.py
Outdated
xcodebuild_flags.append(flag) | ||
xcodebuild_flags += ['-configuration'] | ||
xcodebuild_flags += [self._get_configuration_from_cmake(context)] | ||
cmd.extend(xcodebuild_flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost the logic has been added above. This should be deduplicated.
Another time below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that some of this logic could be consolidated with the code above. Especially the handling of the context.make_flags
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I've added @dirk-thomas 's code and moved it to a separate function in 9ace6e8
Thanks!
Update: I removed the duplicated code since it was not needed and simplified the logic for flag processing in 1974198
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really close I think. There were a few requests to simplify logic and consolidate code. Once those are done and we test/merge @dirk-thomas change to support multiple build types with symlink install, then I'll spend some time testing this out locally on my own machine.
Thanks @esteve for iterating with us.
ament_tools/build_types/cmake.py
Outdated
elif IS_MACOSX: | ||
if context.use_xcode or self._using_xcode_generator(context): | ||
cmake_args += ['-G', 'Xcode'] | ||
cmake_args += ['-DCMAKE_XCODE_GENERATE_SCHEME=ON'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one assumes CMake 3.8.0 right? Could we conditionally add that with that version only? Or is there no point in running without it? My impression was that it just improved testing with Xcode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ament_tools/build_types/cmake.py
Outdated
flag.replace( | ||
'-j', '-IDEBuildOperationMaxNumberOfConcurrentCompileTasks=')) | ||
else: | ||
xcodebuild_flags.append(flag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍, the altered logic is easier to read I think.
ament_tools/build_types/cmake.py
Outdated
xcodebuild_flags.append(flag) | ||
xcodebuild_flags += ['-configuration'] | ||
xcodebuild_flags += [self._get_configuration_from_cmake(context)] | ||
cmd.extend(xcodebuild_flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that some of this logic could be consolidated with the code above. Especially the handling of the context.make_flags
.
@dirk-thomas @wjwwood I've addressed your feedback, let me know if there's anything else that needs to be fixed/improved. Thanks! |
@dirk-thomas @wjwwood I just realized that the duplicated code was not really needed in the |
Not directly related to this patch but a lot of this custom logic would be unnecessary if we would implement #88. But since I will leave it up to @wjwwood to try it on OS X and comment / merge this patch. |
I tested the I also ran CI with the default behavior to see if breaks anything, but it works (after 0371b58):
But of course just as I get it tested, it's all broken now that @dirk-thomas pushed #144 through. I'll have a look at the conflict resolution... |
Thanks again @esteve! |
Yay! Thanks @wjwwood for testing this and for fixing the conflicts. |
And thanks @dirk-thomas for the review. |
This PR replaces
make
withxcodebuild
as the builder for OSX, this among other things allows for ROS2 to be compiled for iOS and the iOS Simulator.I kept the name of the builder flags option (
make-flags
), but I think that if this gets merged it may make sense to rename it to something else (e.g.builder-flags
), since Linux would be the only platform to actually usemake