Modify mj_PLUGIN_LIB_INIT to support multiple plugins in the same compilation unit.

Previously on MSVC we used DllMain to register plugins, you cannot have multiple definitions of DllMain in a single unit so you would get errors if you tried to register two plugins. This modifies the implementation to insert a function pointer into the C runtime initialization instead.

PiperOrigin-RevId: 896612678
Change-Id: I07732147b955d741c836acff6da986db0e9b9eff
This commit is contained in:
Sam Haves
2026-04-08 11:34:33 -07:00
committed by Copybara-Service
parent 33fd2fe40e
commit f2461f9ce6
14 changed files with 60 additions and 53 deletions
+1 -1
View File
@@ -17,6 +17,6 @@
namespace mujoco::plugin::actuator {
mjPLUGIN_LIB_INIT { Pid::RegisterPlugin(); }
mjPLUGIN_LIB_INIT(actuator) { Pid::RegisterPlugin(); }
} // namespace mujoco::plugin::actuator
+1 -1
View File
@@ -17,7 +17,7 @@
namespace mujoco::plugin::elasticity {
mjPLUGIN_LIB_INIT {
mjPLUGIN_LIB_INIT(elasticity) {
Cable::RegisterPlugin();
}
+1 -1
View File
@@ -114,7 +114,7 @@ int CanDecode(const mjResource* resource) {
} // namespace
mjPLUGIN_LIB_INIT {
mjPLUGIN_LIB_INIT(obj_decoder) {
mjpDecoder decoder;
mjp_defaultDecoder(&decoder);
decoder.content_type = "model/obj";
+2 -1
View File
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <mujoco/mjplugin.h>
#include "bolt.h"
#include "bowl.h"
#include "gear.h"
@@ -20,7 +21,7 @@
namespace mujoco::plugin::sdf {
mjPLUGIN_LIB_INIT {
mjPLUGIN_LIB_INIT(sdf) {
Bolt::RegisterPlugin();
Bowl::RegisterPlugin();
Gear::RegisterPlugin();
+1 -1
View File
@@ -17,7 +17,7 @@
namespace mujoco::plugin::sensor {
mjPLUGIN_LIB_INIT {
mjPLUGIN_LIB_INIT(sensor) {
TouchGrid::RegisterPlugin();
}
+1 -1
View File
@@ -132,7 +132,7 @@ int CanDecode(const mjResource* resource) {
} // namespace
mjPLUGIN_LIB_INIT {
mjPLUGIN_LIB_INIT(stl_decoder) {
mjpDecoder decoder;
mjp_defaultDecoder(&decoder);
decoder.content_type = "model/stl";
+1 -1
View File
@@ -2459,7 +2459,7 @@ int CanDecode(const mjResource* resource) {
} // namespace
// clang-format off
mjPLUGIN_LIB_INIT {
mjPLUGIN_LIB_INIT(usd_decoder) {
mjpDecoder decoder;
mjp_defaultDecoder(&decoder);
decoder.content_type = "model/usd";