Ament Cmake: Attempting to export new message generator library corrupts other generator builds

asked 2020-07-26 21:13:25 -0500

atyshka gravatar image

Apologies in advance for posting yet a 3rd question this week related to a Swift client library, but please bear with me as I'm in the home stretch. I finally setup everything correctly for a Swift message generator, but I'm running into a really weird error where a swift library is interfering with the python generator's build.

I have a common package that contains code common between the message generator and client library. Here I have the CMakelists of the common package:

cmake_minimum_required(VERSION 3.15.1)

project(rclswift_common Swift)

find_package(ament_cmake REQUIRED)

add_library(${PROJECT_NAME}
  "swift/Interfaces.swift"
)

set_target_properties(${PROJECT_NAME} PROPERTIES Swift_MODULE_DIRECTORY modules)
set_target_properties(${PROJECT_NAME} PROPERTIES Swift_MODULE_NAME RclSwiftCommon)

target_include_directories(${PROJECT_NAME} PUBLIC  
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/modules>  
$<INSTALL_INTERFACE:modules> )

install(
  TARGETS ${PROJECT_NAME}
  EXPORT ${PROJECT_NAME}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

install(
  DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules/
  DESTINATION modules
)

ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET)

ament_package()

Nothing too crazy going on here, the only real difference from a C++ library is the setup for swift modules, a version of headers generated at compile time. I then include this library for the Swift lib in my message generation file:

  add_library(${PROJECT_NAME}_swift SHARED ${_generated_swift_files} ${_generated_modulemap_files})
  set(EMPTY_COMPILE_FLAGS "")
  set_target_properties(${PROJECT_NAME}_swift PROPERTIES COMPILE_OPTIONS "${EMPTY_COMPILE_FLAGS}")

  ament_target_dependencies(${PROJECT_NAME}_swift rclswift_common)

  if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
    install(TARGETS ${PROJECT_NAME}_swift
      EXPORT ${PROJECT_NAME}_swift
      ARCHIVE DESTINATION lib
      LIBRARY DESTINATION lib
      RUNTIME DESTINATION bin
    )

    install(
      DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules/
      DESTINATION modules
    )

    ament_export_targets(${PROJECT_NAME}_swift)

  endif()

Note that this is a stripped down version, ordinarily I would be linking against a C core library and other generated messages in the case of nested types, but for this example I have stripped back everything to the absolute minimum in hope of isolating the issue. Running this, I encounter the following error from Ninja:

ninja: error: build.ninja:84: multiple rules generate CMakeFiles/std_msgs__rosidl_typesupport_c__pyext.dir/rosidl_generator_py/std_msgs/_std_msgs_s.ep.rosidl_typesupport_c.c.o [-w dupbuild=err]

Note that this is the PYTHON generator... which I interact with nowhere in my Swift client library. Digging down into the actual ninja build at the offending line, I find this:

build rosidl_generator_py/std_msgs/std_msgs_s__rosidl_typesupport_c.cpython-38-x86_64-linux-gnu.so CMakeFiles/std_msgs__rosidl_typesupport_c__pyext.dir/rosidl_generator_py/std_msgs/_std_msgs_s.ep.rosidl_typesupport_c.c.o std_msgs__rosidl_typesupport_c__pyext.swiftmodule: Swift_SHARED_LIBRARY_LINKER__std_msgs__rosidl_typesupport_c__pyext rosidl_generator_py/std_msgs/_std_msgs_s.ep.rosidl_typesupport_c.c | rosidl_generator_py/std_msgs/libstd_msgs__python.so /usr/lib/x86_64-linux-gnu/libpython3.8.so libstd_msgs__rosidl_typesupport_c.so /opt/ros/foxy/lib/librmw.so /home/alex/ros2/install/rosidl_runtime_c/lib/librosidl_runtime_c.so libstd_msgs__rosidl_generator_c.so /home/alex/ros2/install/builtin_interfaces/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_c.so /home/alex/ros2/install/builtin_interfaces/lib/libbuiltin_interfaces__rosidl_generator_c.so /home/alex/ros2/install/builtin_interfaces/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_cpp.so /home/alex/ros2/install/rosidl_typesupport_introspection_cpp/lib/librosidl_typesupport_introspection_cpp.so /home/alex/ros2/install/rosidl_typesupport_introspection_c/lib/librosidl_typesupport_introspection_c.so /home/alex/ros2/install/builtin_interfaces/lib/libbuiltin_interfaces__rosidl_typesupport_cpp.so /opt/ros/foxy/lib/librosidl_typesupport_cpp.so /home/alex/ros2/install/builtin_interfaces/lib/libbuiltin_interfaces__swiftext.so /home/alex/ros2/install/builtin_interfaces/lib/libbuiltin_interfaces__rosidl_typesupport_c.so /opt/ros/foxy/lib/librosidl_typesupport_c.so /home/alex/ros2/install/rosidl_runtime_c/lib/librosidl_runtime_c.so /opt/ros/foxy/lib/librcpputils.so /opt/ros/foxy/lib/librcutils.so /home/alex/ros2/install/builtin_interfaces/lib/libbuiltin_interfaces_swift.so /home/alex/ros2 ...
(more)
edit retag flag offensive close merge delete

Comments

@esteve@Dirk Thomas, as core contributors to the message generation system, do you have any advice here?

atyshka gravatar image atyshka  ( 2020-07-28 18:36:31 -0500 )edit

Repo with build instructions available at https://github.com/atyshka/rclswift if anyone has a few minutes to try and reproduce

atyshka gravatar image atyshka  ( 2020-07-28 19:00:56 -0500 )edit