@@ -66,16 +66,92 @@ def _rosidl_generate_genrule_impl(ctx):
66
66
args .add (ctx .attr .group )
67
67
args .add_all (ctx .files .interfaces , map_each = _as_idl_tuple )
68
68
inputs = ctx .files .interfaces + ctx .files .includes
69
+
70
+ expected_outputs = []
71
+ cpp_visibility_header_file = None
72
+
73
+ # The cpp visibility header is not generated by rosidl generate, so we must
74
+ # handle its generation separately.
75
+ for generated_source in ctx .outputs .generated_sources :
76
+ if "cpp__visibility_control.hpp" in generated_source .path :
77
+ cpp_visibility_header_file = generated_source
78
+ else :
79
+ expected_outputs .append (generated_source )
80
+
69
81
ctx .actions .run_shell (
70
82
tools = [ctx .executable ._tool ],
71
83
arguments = [args ],
72
84
inputs = inputs ,
73
85
command = "{} $@ > /dev/null" .format (
74
86
ctx .executable ._tool .path ,
75
87
),
76
- outputs = ctx . outputs . generated_sources ,
88
+ outputs = expected_outputs ,
77
89
)
78
90
91
+ # This is a temporary hack to get the build working again. This should be
92
+ # redone so that the real template file from the ROS distribution is used,
93
+ # rather than our adaptation below.
94
+ # TODO(calderpg-tri) Replace this hack.
95
+ if cpp_visibility_header_file != None :
96
+ # This template is adapted directly from the mentioned template file.
97
+ cpp_visibility_header_template = (
98
+ """
99
+ // generated from rosidl_generator_cpp/resource/rosidl_generator_cpp__visibility_control.hpp.in
100
+ // generated code does not contain a copyright notice
101
+
102
+ #ifndef {package_name_upper}__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
103
+ #define {package_name_upper}__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
104
+
105
+ #ifdef __cplusplus
106
+ extern "C"
107
+ {{
108
+ #endif
109
+
110
+ // This logic was borrowed (then namespaced) from the examples on the gcc wiki:
111
+ // https://gcc.gnu.org/wiki/Visibility
112
+
113
+ #if defined _WIN32 || defined __CYGWIN__
114
+ #ifdef __GNUC__
115
+ #define ROSIDL_GENERATOR_CPP_EXPORT_{package_name} __attribute__ ((dllexport))
116
+ #define ROSIDL_GENERATOR_CPP_IMPORT_{package_name} __attribute__ ((dllimport))
117
+ #else
118
+ #define ROSIDL_GENERATOR_CPP_EXPORT_{package_name} __declspec(dllexport)
119
+ #define ROSIDL_GENERATOR_CPP_IMPORT_{package_name} __declspec(dllimport)
120
+ #endif
121
+ #ifdef ROSIDL_GENERATOR_CPP_BUILDING_DLL_{package_name}
122
+ #define ROSIDL_GENERATOR_CPP_PUBLIC_{package_name} ROSIDL_GENERATOR_CPP_EXPORT_{package_name}
123
+ #else
124
+ #define ROSIDL_GENERATOR_CPP_PUBLIC_{package_name} ROSIDL_GENERATOR_CPP_IMPORT_{package_name}
125
+ #endif
126
+ #else
127
+ #define ROSIDL_GENERATOR_CPP_EXPORT_{package_name} __attribute__ ((visibility("default")))
128
+ #define ROSIDL_GENERATOR_CPP_IMPORT_{package_name}
129
+ #if __GNUC__ >= 4
130
+ #define ROSIDL_GENERATOR_CPP_PUBLIC_{package_name} __attribute__ ((visibility("default")))
131
+ #else
132
+ #define ROSIDL_GENERATOR_CPP_PUBLIC_{package_name}
133
+ #endif
134
+ #endif
135
+
136
+ #ifdef __cplusplus
137
+ }}
138
+ #endif
139
+
140
+ #endif // {package_name_upper}__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
141
+ """ # noqa
142
+ )
143
+
144
+ package_name = str (ctx .attr .group )
145
+ package_name_upper = package_name .upper ()
146
+
147
+ ctx .actions .write (
148
+ output = cpp_visibility_header_file ,
149
+ content = cpp_visibility_header_template .format (
150
+ package_name = package_name ,
151
+ package_name_upper = package_name_upper ,
152
+ ),
153
+ )
154
+
79
155
rosidl_generate_genrule = rule (
80
156
attrs = dict (
81
157
generated_sources = attr .output_list (mandatory = True ),
@@ -492,7 +568,8 @@ def rosidl_cc_library(
492
568
"""
493
569
include , root = _deduce_source_paths (group , "cpp" )
494
570
495
- generated_cc_headers = []
571
+ visibility_header = "msg/rosidl_generator_cpp__visibility_control.hpp"
572
+ generated_cc_headers = ["{}/{}" .format (root , visibility_header )]
496
573
for ifc in interfaces :
497
574
parent , basename = _deduce_source_parts (ifc )
498
575
generated_cc_headers .append (
@@ -507,6 +584,9 @@ def rosidl_cc_library(
507
584
generated_cc_headers .append (
508
585
"{}/{}/detail/{}__traits.hpp" .format (root , parent , basename ),
509
586
)
587
+ generated_cc_headers .append (
588
+ "{}/{}/detail/{}__type_support.hpp" .format (root , parent , basename ),
589
+ )
510
590
511
591
rosidl_generate_genrule (
512
592
name = _make_private_name (name , "_gen" ),
0 commit comments