Skip to content

Trouble specifying default rmw implementation #10

Closed

Description

@dhood

Looking at https://github.com/ros2/rmw/blob/876645761751fc0be3fdaf4bf23d87b408f3e8b4/rmw_implementation_cmake/cmake/get_default_rmw_implementation.cmake, I thought you could specify the default rmw implementation through ament build --cmake-args -DRMW_IMPLEMENTATION or the environment variable RMW_IMPLEMENTATION

I can't do either, and I think it's because of this: 5eff3ff#diff-e874e8ccc0d49455417259661b3f88f5R17

The configured rmw_implementation-extras.cmake is always setting the default rmw implementation to whatever the default was when it was configured.

I want to build the rclcpp_examples package with a specific rmw implementation as default, which is different to the default when I built rmw_implementation. If I change the part of 5eff3ff which affects rmw_implementation-extras.cmake back to how it was, I can set the default rmw implementation through either the environment variable or the cmake args as expected.

Should I be allowed to set the default rmw implementation for rclcpp_examples independently to the default used to build rmw_implementation? Since get_default_rmw_implementation is being used everywhere I thought the answer was yes, but maybe this is the expected behaviour. If so I'd like to add a message that explains why the requested defaults are being ignored.

Activity

  1. wjwwood commented on Apr 14, 2016

    @wjwwood
    Member

    You need to rebuild with the --force-cmake option. You can choose to only rebuild the rmw_implementation package with --force-cmake and that should work as well, at least I think it will.

    The location you linked to is expanded each time cmake is run over that package. Since the CMake file for that package did not change, then cmake is not automatically re-run, and the file doesn't get updated.

    Other tools like catkin_make* and catkin tools will watch your command line arguments, and force cmake when you change the cmake variables you are passing. It sounds like that's either not implemented in ament_tools or broken, not sure which.

  2. dhood commented on Apr 14, 2016

    @dhood
    MemberAuthor

    did I understand you correctly that you would expect me to be able to run:

    ~/src/ros2examples$ ament build rclcpp_examples --force-cmake-configure --cmake-args -DRMW_IMPLEMENTATION=rmw_fastrtps_cpp
    

    (with export RMW_IMPLEMENTATION=rmw_fastrtps_cpp for good measure) and see something other than

    -- Using RMW implementation: rmw_connext_cpp
    

    appear in the output?

    Because I'm not seeing that (it finds rmw_connext_cpp, rmw_connext_dynamic_cpp, rmw_fastrtps_cpp, and rmw_opensplice_cpp i.e. fastrtps is installed)

  3. wjwwood commented on Apr 14, 2016

    @wjwwood
    Member

    No, I think the ament build you gave is a bit strange in that it takes rclcpp_examples, which should be a folder name (basepath)? I'd do this:

    $ ament build --force-cmake-configure --cmake-args -DRMW_IMPLEMENTATION=rmw_fastrtps_cpp --start-with rmw_implementation
    

    You could also do --only rmw_implementation and then --only rclcpp_examples, but I think that would be dangerous and I wouldn't recommend it, since the intermediate packages would not be rebuilt with the new setting.

  4. dhood commented on Apr 14, 2016

    @dhood
    MemberAuthor

    I am building in a standalone checkout of the ros2/examples repo, so rclcpp_examples is the basepath.

    From what I understand, the answer to my question is essentially "no, you cannot set the default rmw implementation for rclcpp_examples independently to the default used to build rmw_implementation" because in the invocation you just listed it is necessary to rebuild rmw_implementation first.

    Could you explain what the reason behind the change was? because how the rmw_implementation-extras.cmake was before, I could just rebuild rclcpp_examples with a particular default rmw implementation without needing to rebuild rmw_implementation. And so for this case, at least, it was more convenient how it was before, but I suspect that there was a different use case in mind when the change was implemented?

  5. wjwwood commented on Apr 14, 2016

    @wjwwood
    Member

    "no, you cannot set the default rmw implementation for rclcpp_examples independently to the default used to build rmw_implementation"

    Correct. Sorry, if that's what you were asking, I missed the distinction. The default rmw implementation is a build time decision that affects the rmw_implementation package and many packages above it.

  6. wjwwood commented on Apr 14, 2016

    @wjwwood
    Member

    I think if you were able to do it in the past that was in error. Not that I think the diff you linked to aimed to address this issue (I think it was an unintended side-effect of the refactor), but I think the current limitation is necessary.

    Consider that you built rclcpp with default as "A" and then built rclcpp_examples as "B". rclcpp would install it's default library (i.e. <prefix>/lib/librclcpp.so) against "A", but when you build rclcpp_examples and it builds talker, it builds it for "B", but I think it would still link it against the "default rclcpp library", which was built for "A". So for what you've described to work correctly, you would need to ensure that when rclcpp_examples builds the "default" version of talker (i.e. just talker rather than talker__rmw_opensplice_cpp or whatever), that it doesn't link against the "default rclcpp library" but rather that it finds the specific rclcpp library for what it currently thinks is the default.

    In general, changing the default across builds of different packages seems really dangerous to me, since there are a few subtle pitfalls that I can imagine.

    Perhaps we should take a step back, why do you need to change the default for rclcpp_examples? Is it to test something about the building of rclcpp_examples or is it just so you can do talker rather than talker__<impl> every time?

  7. dhood commented on Apr 15, 2016

    @dhood
    MemberAuthor

    I wanted to change the default for rclcpp_examples to check that what I am seeing for the tests of the linking of the default talker, for example, is correct in ros2/examples#105.

    I think you're right that it was just by luck that it was working. As it stands, I think the system is between the two scenarios you describe. That is, the problem you mention with linking against defaults somehow only happens with the list_parameters(_async) and the set_and_get_parameters(_async) examples - the rest of the examples e.g. talker get away with it. But I better understand the reasoning behind it now, thank you. You've made me realise that I will have to make sure the tests for the default example executables check the dependencies deeper than one level, which wasn't necessary for the non-default tests.

    Would you support adding documentation for this? something to make it clear that the RMW_IMPLEMENTATION environment variable and cmake argument essentially only affect the rmw_implementation package (if I've understood correctly)? perhaps somewhere in this tutorial is appropriate since otherwise someone might have an overlay for their own package and would run into the same issue of not re-building rmw_implementation. Or would the special under/overlay intelligence also take care of it in that case?

  8. wjwwood commented on Apr 15, 2016

    @wjwwood
    Member

    Would you support adding documentation for this?

    Always 😄. Let me know if I can help you with it.

    something to make it clear that the RMW_IMPLEMENTATION environment variable and cmake argument essentially only affect the rmw_implementation package (if I've understood correctly)?

    That's correct (at least that's how I believe it should work).

    perhaps somewhere in this tutorial is appropriate since otherwise someone might have an overlay for their own package and would run into the same issue of not re-building rmw_implementation.

    For that particular tutorial I think it would fit in as a note, but strictly speaking that tutorial might not be the right place. If we had a "talker/listener tutorial" about how to create a package that uses rclcpp, then I think it would fit perfectly there. Since we don't have that, I'd support putting it in the ament tutorial.

    Or would the special under/overlay intelligence also take care of it in that case?

    Not sure I understand what you mean here. I'd say the RMW_IMPLEMENTATION option only works when applied to the rmw_implementation package and therefore only the workspace in which that package is built, and when changed all packages and workspaces which build on top of rmw_implementation need to be rebuilt (and reconfigured).

  9. dhood commented on Apr 15, 2016

    @dhood
    MemberAuthor

    OK, I've opened #11 which will generate an error if someone gets into the same situation, for example in the ament tutorial. I agree that the documentation doesn't really belong in the ament tutorial - I think that that error will be sufficient now (it's pretty descriptive).

    How about we add a section like the following to the build-from-source instructions? It doesn't explain anything about the python examples, and probably belongs in 'tutorial 0' once it exists, but might help people who are wondering which rmw implementation is being used to generate the default nodes, as I did when I first ran talker.

    Managing multiple DDS vendors

    In addition to the talker and listener nodes, a version of each C++ example node has been created using each of the ROS middleware (RMW) implementations found. Typically an RMW implementation is generated for each DDS vendor detected during the build step above. So, talker__rmw_opensplice_cpp, for example, should also be on your path if PrismTech's Opensplice was found. The talker node without a suffix uses the default RMW implementation, which will be the first in alphabetical order unless otherwise specified. If you wish to specify the RMW implementation used in the nodes without suffixes, the RMW_IMPLEMENTATION environment variable or CMake argument can be used. For example, by adding --cmake-args -DRMW_IMPLEMENTATION=rmw_opensplice_cpp to the above build command to pass the specification to the rmw_implementation package.

    Regarding the --force-cmake-configure, it seems that it does trigger correctly, but the RMW_IMPLEMENTATION cmake var is stored in the cache, which doesn't seem to be cleared.
    That is, if I run:

    ament test rclcpp_examples --cmake-args -DRMW_IMPLEMENTATION=rmw_opensplice_cpp
    

    to generate an error because the default implementation doesn't match, and then run

    ament test rclcpp_examples
    

    then I do see Running cmake because arguments have changed. but I still get the error message when I shouldn't. To make the error message go away I have to manually do rm build/rclcpp_examples/CMakeCache.txt before building without specifying the default implementation.

    So my question is:
    Should the CMakeCache.txt be cleared somewhere here (either all of it or just that value), or
    Should the RMW_IMPLEMENTATION not end up in the CMakeCache in the first place?

  10. wjwwood commented on Apr 15, 2016

    @wjwwood
    Member

    @dhood I think the we should not remove the CMakeCache.txt at that point, but there are situations where it is appropriate.

    I think the root of the issue is that this variable is set/updated during the find_package process. The result of the find_package process is being cached (I think) and so this file is never rerun, so the older value is used. I'm not sure how to address that off-hand. You can probably see what I mean by putting a message(...) print out at the point where you set the default. You would then expect to see that message every time you run cmake, but instead you only see it the first time (or after clearing the CMakeCache.txt).

  11. dhood commented on Apr 16, 2016

    @dhood
    MemberAuthor

    There's already a printout where the default is set - it appears whenever cmake is called (either from removing the cache manually or using --force-cmake-configure)

    I think this problem might not be ament-specific. The entry in the CMakeCache.txt looks like:

    //No help, variable specified on the command line.
    RMW_IMPLEMENTATION:UNINITIALIZED=rmw_opensplice_cpp
    

    which I think is standard behaviour. Any command line cmake arguments specified with -D are added to the cache in this manner.

    It seems like it would be possible to detect variables specified on the command line and only clear those values from the cache. Or, a note could be made of which arguments were parsed from the command line here and either clear them (by default or only on --force-cmake-configure) or prevent them from going in the cache in the first place (by removing the -D for example).

    Having said this, while I was not expecting the command line variables to persist between invocations, since this is the standard behaviour of cmake it might not be a good idea to change it.

  12. dhood commented on Apr 16, 2016

    @dhood
    MemberAuthor

    To correct something I said: I don't think anymore that this is necessarily a 'problem', I think it's behaving as it should be, it just wasn't what I expected. So, there's probably no need to change anything. People can use --cmake-args -URMW_IMPLEMENTATION to unset the value, or clear the cache themselves.

    While I would support a temporary RMW_IMPLEMENTATION argument (a general ament argument that also happens to set the cmake variable (temporarily), for example), the environment variable can play that role for the moment

  13. wjwwood commented on Apr 16, 2016

    @wjwwood
    Member

    Ok, so can we close this then?

  14. dhood commented on Apr 16, 2016

    @dhood
    MemberAuthor

    Yeah

  15. added a commit that references this issue on Feb 15, 2021
  16. nightduck commented on Jul 26, 2022

    @nightduck

    I cannot for the life of me get this to use anything other than the default rmw_cyclone_dds. I've exported the environment variable RMW_IMPLEMENTATION, and run several variations of the command

    colcon build --merge-install --cmake-force-configure --cmake-args '-DRMW_IMPLEMENTATION=rmw_myrmw_cpp' --packages-select rmw_implementation test_rmw_implementation
    

    Yet in doing some testing:

    colcon test --merge-install --packages-select test_rmw_implementation
    

    It always uses rmw_cyclonedds_cpp. I can't test any other rmws. What exactly is the command I need to build this?

    Answered here

  17. christophebedard commented on Jul 26, 2022

    @christophebedard
    Member

    You need to export the environment variable in the terminal you use to run your application, not the one you use to build. This is a runtime parameter, not a buildtime parameter.

    If this still doesn't work, please ask a question on https://answers.ros.org/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions