Skip to content

Commit 1d7c3da

Browse files
committed
Updating the build for the 3.3.0 release
1 parent 7597d15 commit 1d7c3da

File tree

3 files changed

+127
-311
lines changed

3 files changed

+127
-311
lines changed

build-linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ echo "JavaCPP configs:"
4545
$JAVA_HOME/bin/java -jar $SCRIPT_DIR/javacpp-platform-$JAVACPP_VER-bin/javacpp.jar -Dcompiler.includepath=$BUILDDIR/include/ -print properties.includepath
4646

4747
$JAVA_HOME/bin/java -jar $SCRIPT_DIR/javacpp-platform-$JAVACPP_VER-bin/javacpp.jar org/mujoco/MuJoCoConfig.java
48+
4849
echo "Start compile \n\n"
4950
$JAVA_HOME/bin/java -jar $SCRIPT_DIR/javacpp-platform-$JAVACPP_VER-bin/javacpp.jar -copylibs -copyresources -Xcompiler "-no-pie" -Xcompiler "-I$JAVADIR" -Xcompiler "-L$JAVADIR" org/mujoco/MuJoCoLib.java
5051
LIBPATH=$PWD/../resources/$TYPE/

src/main/java/org/mujoco/MuJoCoConfig.java

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,50 @@ public class MuJoCoConfig implements InfoMapper {
2121
public void map(InfoMap infoMap) {
2222
infoMap.put(new Info("MJ_STATIC").define(true));
2323
infoMap.put(new Info("mjtNum").cast().valueTypes("double").pointerTypes("DoublePointer"));
24+
// infoMap.put(new Info("mjString")
25+
// .cast()
26+
// .valueTypes("@StdString String")
27+
// .pointerTypes("@StdString BytePointer"));
28+
// Define mjString as an opaque pointer type to avoid direct conversions
29+
// Add this to your JavaCPP configuration
30+
//infoMap.put(new Info().define("mjString std::string"));
31+
32+
// Then skip the mjString type and use String/BytePointer directly
33+
// infoMap.put(new Info("mjString").skip());
34+
// infoMap.put(new Info("std::string").annotations("@StdString").pointerTypes("BytePointer").valueTypes("String"));
35+
36+
// Handle mjString (std::string)
37+
infoMap.put(new Info("mjString").skip());
38+
infoMap.put(new Info("std::string").annotations("@StdString").pointerTypes("BytePointer").valueTypes("String"));
39+
40+
// Handle mjStringVec (std::vector<std::string>)
41+
infoMap.put(new Info("mjStringVec").skip());
42+
infoMap.put(new Info("std::vector<std::string>").pointerTypes("StringVector").valueTypes("StringVector"));
43+
44+
// Handle mjIntVec (std::vector<int>)
45+
infoMap.put(new Info("mjIntVec").skip());
46+
infoMap.put(new Info("std::vector<int>").pointerTypes("IntPointer").valueTypes("IntBuffer"));
47+
48+
// Handle mjIntVecVec (std::vector<std::vector<int>>)
49+
infoMap.put(new Info("mjIntVecVec").skip());
50+
infoMap.put(new Info("std::vector<std::vector<int>>").pointerTypes("PointerPointer<IntPointer>"));
51+
52+
// Handle mjFloatVec (std::vector<float>)
53+
infoMap.put(new Info("mjFloatVec").skip());
54+
infoMap.put(new Info("std::vector<float>").pointerTypes("FloatPointer").valueTypes("FloatBuffer"));
55+
56+
// Handle mjFloatVecVec (std::vector<std::vector<float>>)
57+
infoMap.put(new Info("mjFloatVecVec").skip());
58+
infoMap.put(new Info("std::vector<std::vector<float>>").pointerTypes("PointerPointer<FloatPointer>"));
59+
60+
// Handle mjDoubleVec (std::vector<double>)
61+
infoMap.put(new Info("mjDoubleVec").skip());
62+
infoMap.put(new Info("std::vector<double>").pointerTypes("DoublePointer").valueTypes("DoubleBuffer"));
63+
64+
// Handle mjByteVec (std::vector<std::byte>)
65+
infoMap.put(new Info("mjByteVec").skip());
66+
infoMap.put(new Info("std::vector<std::byte>").pointerTypes("BytePointer").valueTypes("ByteBuffer"));
67+
2468
// mjString
2569
// infoMap.put(new
2670
// Info("mjString").cast().valueTypes("String").pointerTypes("StringPointer"));
@@ -79,42 +123,14 @@ public void map(InfoMap infoMap) {
79123
infoMap.put(new Info("mjs_firstElement").skip());
80124
// mjs_firstChild
81125
infoMap.put(new Info("mjs_firstChild").skip());
82-
// Add this to your MuJoCoConfig.java
83-
// Add this to your JavaCPP configuration class
84-
// This adds custom code at the beginning of the generated file
85-
infoMap.put(new Info().cppText(
86-
// Add a macro that will be used for string assignments
87-
"#include <string>\n" +
88-
"#define ASSIGN_TO_STRING_PTR(ptr, val) if(ptr) *ptr = val;\n" +
89-
90-
// Create a function to override the problematic assignments
91-
"template<typename T>\n" +
92-
"void assign_string(T* ptr, const std::string& val) {\n" +
93-
" if(ptr) *ptr = val;\n" +
94-
"}\n" +
95-
96-
// This is the critical part - redefine the cast operator to call our safe function
97-
"#define __JAVACPP_HACK\n" +
98-
"#ifdef __JAVACPP_HACK\n" +
99-
"#define JAVACPP_STRING_CAST(x)\n" +
100-
"#endif\n"
101-
));
102-
103-
// Tell JavaCPP how to handle specific problematic cases
104-
infoMap.put(new Info("ptr->meshdir = (std::basic_string< char >&)adapter0")
105-
.define(false)
106-
.cppText(" assign_string(ptr->meshdir, adapter0)"));
107-
108-
infoMap.put(new Info("ptr->modelname = (std::basic_string< char >&)adapter0")
109-
.define(false)
110-
.cppText(" assign_string(ptr->modelname, adapter0)"));
111-
112-
infoMap.put(new Info("ptr->modelfiledir = (std::basic_string< char >&)adapter0")
113-
.define(false)
114-
.cppText(" assign_string(ptr->modelfiledir, adapter0)"));
115-
116-
// Add similar entries for other problematic assignments
117-
126+
// mjSpec_modelfiledir
127+
infoMap.put(new Info("mjs_setString").skip());
128+
infoMap.put(new Info("mjs_getString").skip());
129+
//modelname
118130

131+
infoMap.put(new Info("modelname").skip());
132+
//modelfiledir
133+
infoMap.put(new Info("modelfiledir").skip());
134+
119135
}
120136
}

0 commit comments

Comments
 (0)