Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/generating_java.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Where:

* `--force-namespace MyLib` is optional, but you'll usually want it. It puts the entities of the global C++ namespace (which includes the `std::` container instantiations) into the package of this namespace (`com.example.mylib.mylib` here, `Foo::Bar` becomes `foo.bar`). Without it they go directly to the base package, next to the runtime classes.

Class names longer than 100 characters (some `std::function` instantiations) are truncated and suffixed with a hash, since each class is a file and Windows limits the path length. `--max-class-name-length` changes the limit, 0 disables it.
Class names longer than 100 characters (some `std::function` instantiations, and the `ffi` classes named after long C file names) are truncated and suffixed with a hash, since each class is a file and Windows limits the path length. `--max-class-name-length` changes the limit, 0 disables it.

The generator prints a summary at the end: how many functions got wrappers, how many of those use raw C types, and how many were skipped because their C types can't be spelled in Java (`long double` and such). Pass `--verbose` to list the skipped ones.

Expand Down
1 change: 1 addition & 0 deletions src/generators/java/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ namespace mrbind::Java
}
if (ret.idents.empty())
throw std::runtime_error("Bad relative file name in the input JSON: `" + file.relative_name + "`.");
ret.idents.back() = ShortenClassName(ret.idents.back());
ret.java_path = base_package + ".ffi." + JoinNameParts(ret.idents, ".");
}
else if (ret.group != file.group)
Expand Down
5 changes: 5 additions & 0 deletions test/make_java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ shopt -s nullglob

JAVA_BIN="${JAVA_HOME:+$JAVA_HOME/bin/}"

# The class names are shortened more than by default: the output paths here are long already,
# and Windows checkouts of this repo as a submodule are limited to 260 characters per path.
build/mrbind_gen_java \
--input-json test/output_c/desc.json \
--output-dir test/output_java/src \
--clean-output-dir \
--package mrbind_test \
--force-namespace MR::CS \
--imported-lib-name bleh \
--max-class-name-length 64 \

build/mrbind_gen_java \
--input-json test/output_c_fixed_typedefs/desc.json \
Expand All @@ -21,6 +24,7 @@ build/mrbind_gen_java \
--package mrbind_test \
--force-namespace MR::CS \
--imported-lib-name bleh \
--max-class-name-length 64 \
--imported-split-lib-name MR_A_ bleh_A \
--imported-split-lib-name MR_B_ bleh_B \
--imported-split-lib-name MR_AB_ bleh_AB \
Expand All @@ -32,6 +36,7 @@ build/mrbind_gen_java \
--package mrbind_test \
--force-namespace MR::CS \
--imported-lib-name bleh \
--max-class-name-length 64 \
--imported-split-lib-name MR_AB_ bleh_AB \

# Compile each output. `javac` reads the list of sources from a file, the command line would be too long otherwise.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mrbind_test.ffi;

/** The downcall handles of the C bindings file `std_function_MR_CSharp_ExposedLayoutC_from_MR_CSharp_ExposedLayoutC`. */
public final class std_function_MR_CSharp_ExposedLayoutC_from_MR_CSharp_ExposedLayoutC
public final class std_function_MR_CSharp_ExposedLayoutC_from_MR_CSharp_ExposedLayo__90003873
{
private std_function_MR_CSharp_ExposedLayoutC_from_MR_CSharp_ExposedLayoutC() {}
private std_function_MR_CSharp_ExposedLayoutC_from_MR_CSharp_ExposedLayo__90003873() {}

public static final class H0
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mrbind_test.ffi;

/** The downcall handles of the C bindings file `std_tuple_MR_CSharp_ExposedLayout_ref_const_MR_CSharp_ExposedLayout_ref`. */
public final class std_tuple_MR_CSharp_ExposedLayout_ref_const_MR_CSharp_ExposedLayout_ref
public final class std_tuple_MR_CSharp_ExposedLayout_ref_const_MR_CSharp_ExposedLay__1bab9140
{
private std_tuple_MR_CSharp_ExposedLayout_ref_const_MR_CSharp_ExposedLayout_ref() {}
private std_tuple_MR_CSharp_ExposedLayout_ref_const_MR_CSharp_ExposedLay__1bab9140() {}

public static final class H0
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mrbind_test.ffi;

/** The downcall handles of the C bindings file `std_tuple_MR_CSharp_ExposedLayout_rvalue_ref_const_MR_CSharp_ExposedLayout_rvalue_ref`. */
public final class std_tuple_MR_CSharp_ExposedLayout_rvalue_ref_const_MR_CSharp_ExposedLayout_rvalue_ref
public final class std_tuple_MR_CSharp_ExposedLayout_rvalue_ref_const_MR_CSharp_Exp__2c745d14
{
private std_tuple_MR_CSharp_ExposedLayout_rvalue_ref_const_MR_CSharp_ExposedLayout_rvalue_ref() {}
private std_tuple_MR_CSharp_ExposedLayout_rvalue_ref_const_MR_CSharp_Exp__2c745d14() {}

public static final class H0
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mrbind_test.ffi;

/** The downcall handles of the C bindings file `std_tuple_const_int_const_float_int_ref_float_ref_const_int_ref_const_float_ref_int_rvalue_ref_flo__22dd`. */
public final class std_tuple_const_int_const_float_int_ref_float_ref_const_int_ref_const_float_ref_int_rvalue_ref_flo__22dd
public final class std_tuple_const_int_const_float_int_ref_float_ref_const_int_ref___843c200b
{
private std_tuple_const_int_const_float_int_ref_float_ref_const_int_ref_const_float_ref_int_rvalue_ref_flo__22dd() {}
private std_tuple_const_int_const_float_int_ref_float_ref_const_int_ref___843c200b() {}

public static final class H0
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mrbind_test.ffi;

/** The downcall handles of the C bindings file `std_tuple_const_int_ref_const_float_rvalue_ref_const_std_string_ref_const_std_string_rvalue_ref`. */
public final class std_tuple_const_int_ref_const_float_rvalue_ref_const_std_string_ref_const_std_string_rvalue_ref
public final class std_tuple_const_int_ref_const_float_rvalue_ref_const_std_string___80503fe8
{
private std_tuple_const_int_ref_const_float_rvalue_ref_const_std_string_ref_const_std_string_rvalue_ref() {}
private std_tuple_const_int_ref_const_float_rvalue_ref_const_std_string___80503fe8() {}

public static final class H0
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mrbind_test.ffi;

/** The downcall handles of the C bindings file `std_tuple_int_ref_float_rvalue_ref_std_string_ref_std_string_rvalue_ref`. */
public final class std_tuple_int_ref_float_rvalue_ref_std_string_ref_std_string_rvalue_ref
public final class std_tuple_int_ref_float_rvalue_ref_std_string_ref_std_string_rva__d6d42941
{
private std_tuple_int_ref_float_rvalue_ref_std_string_ref_std_string_rvalue_ref() {}
private std_tuple_int_ref_float_rvalue_ref_std_string_ref_std_string_rva__d6d42941() {}

public static final class H0
{
Expand Down
12 changes: 6 additions & 6 deletions test/output_java/src/mrbind_test/mr/cs/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ public static boolean opEqual(mrbind_test.mr.cs.std_set_float_const_iterator a,
*
* Calls `MR_C_sub_MR_C_std_vector_MR_StdContainers_NonDefaultConstructible_const_iterator()`.
*/
public static long opSub(mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterator a, mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterator b)
public static long opSub(mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterat__7063b67 a, mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterat__7063b67 b)
{
try
{
Expand All @@ -1987,7 +1987,7 @@ public static long opSub(mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaul
*
* Calls `MR_C_equal_MR_C_std_vector_MR_StdContainers_NonDefaultConstructible_const_iterator()`.
*/
public static boolean opEqual(mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterator a, mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterator b)
public static boolean opEqual(mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterat__7063b67 a, mrbind_test.mr.cs.std_vector_MR_StdContainers_NonDefaultConstructible_const_iterat__7063b67 b)
{
try
{
Expand Down Expand Up @@ -2371,7 +2371,7 @@ public static boolean opEqual(mrbind_test.mr.cs.std_unordered_set_MR_StdContaine
*
* Calls `MR_C_equal_MR_C_std_unordered_multiset_MR_StdContainers_NonAssignable_const_iterator()`.
*/
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_multiset_MR_StdContainers_NonAssignable_const_iterator a, mrbind_test.mr.cs.std_unordered_multiset_MR_StdContainers_NonAssignable_const_iterator b)
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_multiset_MR_StdContainers_NonAssignable_const_iter__8fb8fc8 a, mrbind_test.mr.cs.std_unordered_multiset_MR_StdContainers_NonAssignable_const_iter__8fb8fc8 b)
{
try
{
Expand Down Expand Up @@ -2491,7 +2491,7 @@ public static boolean opEqual(mrbind_test.mr.cs.std_multimap_MR_StdContainers_No
*
* Calls `MR_C_equal_MR_C_std_unordered_map_MR_StdContainers_NonAssignable_float_const_iterator()`.
*/
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_map_MR_StdContainers_NonAssignable_float_const_iterator a, mrbind_test.mr.cs.std_unordered_map_MR_StdContainers_NonAssignable_float_const_iterator b)
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_map_MR_StdContainers_NonAssignable_float_const_ite__97007713 a, mrbind_test.mr.cs.std_unordered_map_MR_StdContainers_NonAssignable_float_const_ite__97007713 b)
{
try
{
Expand Down Expand Up @@ -2539,7 +2539,7 @@ public static boolean opEqual(mrbind_test.mr.cs.std_unordered_map_MR_StdContaine
*
* Calls `MR_C_equal_MR_C_std_unordered_multimap_MR_StdContainers_NonAssignable_float_const_iterator()`.
*/
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_const_iterator a, mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_const_iterator b)
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_cons__8276285 a, mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_cons__8276285 b)
{
try
{
Expand All @@ -2563,7 +2563,7 @@ public static boolean opEqual(mrbind_test.mr.cs.std_unordered_multimap_MR_StdCon
*
* Calls `MR_C_equal_MR_C_std_unordered_multimap_MR_StdContainers_NonAssignable_float_iterator()`.
*/
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_iterator a, mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_iterator b)
public static boolean opEqual(mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_iter__8fb8fc8 a, mrbind_test.mr.cs.std_unordered_multimap_MR_StdContainers_NonAssignable_float_iter__8fb8fc8 b)
{
try
{
Expand Down
Loading