Giter VIP home page Giter VIP logo

scapix's Introduction

Scapix Language Bridge

πŸ‡ΊπŸ‡¦ If you like this project, please consider donating to one of the funds helping victims of russian aggression against Ukraine: ukraine.ua

Automatic, on the fly bindings from C++ to Java, Objective-C, Swift, Python, JavaScript (WebAssembly) and C#. Bridge code automatically generated directly from C++ header files, no need to manually maintain IDL definitions or bindings.

Scapix Bridge Intro

Integrating in CMake project

include(FetchContent)
FetchContent_Declare(
  cmodule
  URL "https://github.com/scapix-com/cmodule/archive/refs/tags/v2.0.0.tar.gz"
  URL_HASH SHA256=58695a9d73dc95a2c214097729917c7d9c366bf511e162d566cf55dd2b9cd7be
)
FetchContent_MakeAvailable(cmodule)

find_package(Scapix REQUIRED)

scapix_bridge_headers(
    chatlib
    "com.example.chat"
    "source/chat/contact.h"
    "source/chat/session.h"
    "source/chat/model.h"
)

Documentation

Examples:

License

Please carefully read license agreement.

In short: If you comply with license agreement, you may use Scapix Language Bridge free of charge to build commercial and/or open source applications. You may NOT modify and/or redistribute the Scapix Language Bridge product itself.

scapix's People

Contributors

boris-rasin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scapix's Issues

Learn more about SCAPIX_PLATFORM

Good day!
Could you tell me in more detail what the CMake SCAPIX_PLATFORM parameter means? I found only one use of it in the example on GitHub. I would like to learn more :)
Thank you for such a wonderful tool!

makefile integration?

I have a cpp core lib that I would like to use as a backend for different UIs. For now I will start with macOS/swift. The issue is that the cpp lib does not use cmake, is it at all possible to integrate scapix without switching to cmake? my lib is rather simple and I'm currently happy with the makefile setup.

If it is possible, can you give show me an example or point me to the right direction.
if it matters, I'm planning to use my lib as a statically linked one: libexample.a
Thanks a lot

Null pointer dereference (Android + JNI)

Hello,
At first, it's not a high priority issue in my opinion, but I found that Scapix may crash at:

// source/scapix/link/java/detail/api/ref.h
static jobject new_ref(jobject h) noexcept { return detail::env()->NewGlobalRef(h); }

Probably 'scope::local' and 'scope::weak' variants are also vulnerable to this issue.

When crash occurred I saw that 'jobject h' was nullptr, so 'NewLocalRef' caused abort with 'null pointer dereference' info. This issue may appear eg. when you store lambda with captured std::function to std::function (Scapix function stored here) and next you copy this std::function on another thread. I think that it may be relatated to detached JNI environment on another thread. I don't know if Scapix do some check like this one:
if (pVM->GetEnv((void**)&mEnvironment, JNI_VERSION_1_6) == JNI_EDETACHED && pVM->AttachCurrentThread(&mEnvironment, nullptr) == JNI_OK)
but if not it may be source of problem. However this issue may be relative easy solved by just store std::shared_ptr with std::function, so copy operate just on std::pointer instead of std::function, thats why I think that priority of this issue isn't high.

Best regards,
Patryk

vcpkg integration

Hello! Firstly thanks for your work! I think that this library should be in vcpkg (it's a C/C++ package manager written by Microsoft).

I'm trying to make a port. And I have some questions. Scapix has ScapixBin as a dependency. ScapixBin lays in another repo. And there are only 3 binary files. Do you have sources of these binaries anywhere in repos? Or I should download these binaries like in cmodule ?

Cannot use OpenCV with Scapix `1.0.28` or newer when building with `clang 12` or older

I have a project that uses OpenCV and Scapix 1.0.27 (cmodule 1.0.32) here -- it builds and works flawlessly as you can see in CI.

If I update Scapix to 1.0.28 or newer (in fact, I update cmodule to 1.0.33 or newer) as you can see in this branch where it's the only change, language interface generation fails with errors like this (I'm not sure if you can see it in the CI, so just copying from there)

[ 14%] Building CXX object _deps/scapix-1.0.28-build/CMakeFiles/scapix.dir/source/scapix/link/java/detail/exception.cpp.o
[ 28%] Linking CXX static library libscapix.a
[ 28%] Built target scapix
[ 42%] Running Scapix Bridge for /home/runner/work/SgbmDepthAndroid/SgbmDepthAndroid/sgbmdepth/src/main/cpp/include/DepthEstimator.h
In file included from /home/runner/work/SgbmDepthAndroid/SgbmDepthAndroid/sgbmdepth/src/main/cpp/include/DepthEstimator.h:7:
In file included from /home/runner/work/SgbmDepthAndroid/SgbmDepthAndroid/sgbmdepth/src/main/cpp/build/opencv-download/opencv-4.5.5/modules/core/include/opencv2/core.hpp:52:
In file included from /home/runner/work/SgbmDepthAndroid/SgbmDepthAndroid/sgbmdepth/src/main/cpp/build/opencv-download/opencv-4.5.5/modules/core/include/opencv2/core/cvdef.h:349:
In file included from /home/runner/work/SgbmDepthAndroid/SgbmDepthAndroid/sgbmdepth/src/main/cpp/build/opencv-download/opencv-4.5.5/modules/core/include/opencv2/core/cv_cpu_dispatch.h:210:
/usr/lib/llvm-[11](https://github.com/TimPushkin/SgbmDepthAndroid/runs/7496540399?check_suite_focus=true#step:7:12)/lib/clang/11.0.0/include/emmintrin.h:2374:19: error: use of undeclared identifier '__builtin_ia32_pmaxsw[12](https://github.com/TimPushkin/SgbmDepthAndroid/runs/7496540399?check_suite_focus=true#step:7:13)8'
  return (__m128i)__builtin_ia32_pmaxsw128((__v8hi)__a, (__v8hi)__b);
                  ^
/usr/lib/llvm-11/lib/clang/11.0.0/include/emmintrin.h:2394:19: error: use of undeclared identifier '__builtin_ia32_pmaxub128'
  return (__m128i)__builtin_ia32_pmaxub128((__v16qi)__a, (__v16qi)__b);
                  ^
/usr/lib/llvm-11/lib/clang/11.0.0/include/emmintrin.h:24[14](https://github.com/TimPushkin/SgbmDepthAndroid/runs/7496540399?check_suite_focus=true#step:7:15):19: error: use of undeclared identifier '__builtin_ia32_pminsw128'
  return (__m128i)__builtin_ia32_pminsw128((__v8hi)__a, (__v8hi)__b);
                  ^
/usr/lib/llvm-11/lib/clang/11.0.0/include/emmintrin.h:2434:19: error: use of undeclared identifier '__builtin_ia32_pminub128'
  return (__m128i)__builtin_ia32_pminub128((__v[16](https://github.com/TimPushkin/SgbmDepthAndroid/runs/7496540399?check_suite_focus=true#step:7:17)qi)__a, (__v16qi)__b);
                  ^
4 errors generated.
Error while processing /home/runner/work/SgbmDepthAndroid/SgbmDepthAndroid/sgbmdepth/src/main/cpp/include/DepthEstimator.h.
make[2]: *** [src/CMakeFiles/sgbmdepth.dir/build.make:75: ../generated/bridge/java/DepthEstimator.cpp] Error 1
make[1]: *** [CMakeFiles/Makefile2:[17](https://github.com/TimPushkin/SgbmDepthAndroid/runs/7496540399?check_suite_focus=true#step:7:18)9: src/CMakeFiles/sgbmdepth.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Error: Process completed with exit code 2.

Here you can see how it's built in CI, but I'm getting the same errors locally. Everything builds fine if I disable Scapix. What may be causing the issue?

java code generation - ignoring std::int64_t fields

Hello!

After the java code generation I've got std::int64_t fields ignored.
If std::int64_t is replaced by long long, it works well though.

I've checked your example1, there is no such problem there.

Could you tell me if you have any ideas why it happens, please?

my cpp code:

#include <cstdint>
#include <scapix/bridge/object.h>

class VD1;
class VD1 : public scapix::bridge::object<VD1> {
public:
    std::int64_t getHandle() const {
        return handle_;
    }

    void setHandle(std::int64_t handle) {
        handle_ = handle;
    }

private:
    std::int64_t handle_;
};


class VD2;
class VD2 : public scapix::bridge::object<VD2> {
public:
    long long getHandle() const {
        return handle_;
    }

    void setHandle(long long handle) {
        handle_ = handle;
    }

private:
    long long handle_;
};

generated java code:

class VD1 extends com.scapix.Bridge
{
	public VD1() { super(nop); _init(); }

//	public native !UNKNOWN! getHandle();
//	public native void setHandle(!UNKNOWN! handle);

	private native void _init();
	protected VD1(Nop nop) { super(nop); }
	static { System.loadLibrary("pjvcelib"); }
}

class VD2 extends com.scapix.Bridge
{
	public VD2() { super(nop); _init(); }

	public native long getHandle();
	public native void setHandle(long handle);

	private native void _init();
	protected VD2(Nop nop) { super(nop); }
	static { System.loadLibrary("pjvcelib"); }
}

Java bridge: generate all classes as public

Today, bridged class with the same name as it's C++ header is generated as public, but additional bridged classes in the same C++ header generated as package-private.

One possible solution is to generate each Java class in it's own source file, so they can all be public.

Interfacing with methods inherited from parent virtual classes (like interfaces).

I was trying to use methods in an interface object that was defined in a parent class but there's no bridging code being created.

A quick example:

class test_inheritance
{
public:
  int
  method1 (void)
  {
    return 3;
  }
};

class test_inheritance2 : public test_inheritance, public scapix::bridge::object<test_inheritance2>
{
public:
  test_inheritance2 () {}

  int
  method2 (void)
  {
    return method1 ();
  }
};

I would like to call method1() directly from the bridged languages instead of having to go through method2(). Is that possible ?

Add a license clause to the scapix link headers?

https://www.scapix.com/objc_link/ is interesting. Thank you.

The associated code is in this repository but has no explicit license in the header files.

Questions:

  1. Can you please clarify if the code can be used under a BSD (or equivalent) license?
  2. Can the link code be redistributed?

Might I suggest that you explicitly license the files in scapix/link?

Cheers.

Generated library (.so) name incorrect

From my (limited) understanding, a library is named from one's CMakeLists.txt file when calling add_library. For instance:

add_library {
mylib
SHARED
./native_libs/mylib/mylib.cpp
./native_libs/mylib/mylib.hpp
}

The corresponding library name would be "mylib."

I have a similar setup in an example (Flutter) application I've been tinkering with. However, after running cmake, generated/bridge/java/com/example/flutter_example/Person.java was attempting to load library "flutter_examplelib" instead of "person" (please see this commit).

I'm curious what caused it to generate the wrong library name. Is my configuration incorrect somewhere? πŸ€”

Thank you very much for your time.

C# - Problem returning null shared_pointer.

Hi,
First, congratulation for your great job, it's pretty easy and work great.

I have encountered an issue when I return a null shared_ptr.
I work on a unity plugin, so I use your work to bind my C++ library in C#. And when I return a nullptr, Unity stop working.

A simple example to reproduce the problem:

class A : public scapix::bridge::object<A>
{
public:
    static std::shared_ptr<A> Create() { return nullptr; }
};

I have worked around the problem for now but I think this is a necessary feature.

Incomplete bindings from C API

Hello! Very cool project.

I tried to integrate scapix into my open source codec project

https://github.com/GrokImageCompression/grok/tree/scapix

When I compile, I don't get a complete binding for any language. In fact, most API methods are missing.
The library has a C API, but the implementation is in C++. Any ideas why this might be the case ?
I assume that it would work for C API as C is a subset of C++.

Thanks!

Support for C++20 does not work with CMAKE_CXX_STANDARD

scapix does not use the same C++ standard version of the project when the version is set with CMAKE_CXX_STANDARD. The following snippet is what I use to set the compiler C++ version.

set(CMAKE_CXX_STANDARD 20)

The issue can be fixed by setting the compiler version with the following snippet.

 target_compile_features(<target> PUBLIC cxx_std_20)

In my opinion, scapix should recognize the compiler version when is set with CMAKE_CXX_STANDARD.

Q: Support for POD structs

Hello,

If I understand the documentation correctly, and am not making mistakes in my tests, plain struct export is not supported by Scapix.

Could you please elaborate technical reasons to this decision?

Example:

struct MyData { 
  int a; 
  double b; 
};
class MyExportedClass : public scapix::bridge::object<MyExportedClass> {
public:
  MyData someData() const;
};

will result in a missing wrapper: //-(!UNKNOWN!)someData;

Thank you!

Best regards,
Sergey

Bug: compilation fails for unsigned integer types in containers

Using tiny_bridge example add a function returning a container of uint8_ts (or any other uint type):

#include <string>
#include <scapix/bridge/object.h>

#include <vector>

namespace tiny {

class contact : public scapix::bridge::object<contact>
{
public:
   std::vector<std::uint8_t> testUInt8Vec() const { return {0, 1, 2}; } // ADDED

   std::string name() { return "Hello from C++"; }
};

} // namespace tiny

Compile with:

cmake -B build/xcode_mac_objc -G "Xcode" -DSCAPIX_BRIDGE=objc -DSCAPIX_PLATFORM=apple
cmake --build build/xcode_mac_objc

The build fails:

In file included from ~/src/scapix-uint-bug/generated/bridge/objc/bridge/bridge/Contact.mm:4:
In file included from ~/.cmodule/scapix/1.0.11/source/../../../../src/scapix-uint-bug/contact.h:2:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/object.h:11:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/objc/object.h:91:
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:32:12: error: implicit instantiation of undefined template 'scapix::link::objc::convert<NSNumber *, unsigned char, void>'
    return convert<remove_cvref_t<ObjC>, remove_cvref_t<Cpp>>::objc(std::forward<Cpp>(cpp));
           ^
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:258:29: note: in instantiation of function template specialization 'scapix::link::objc::convert_objc<NSNumber *, const unsigned char &>' requested here
            [arr addObject: convert_objc<objc_value>(element)];
                            ^
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:32:64: note: in instantiation of member function 'scapix::link::objc::convert<NSArray<NSNumber *> *, std::__1::vector<unsigned char,
      std::__1::allocator<unsigned char> >, void>::objc' requested here
    return convert<remove_cvref_t<ObjC>, remove_cvref_t<Cpp>>::objc(std::forward<Cpp>(cpp));
                                                               ^
In file included from ~/src/scapix-uint-bug/generated/bridge/objc/bridge/bridge/Contact.mm:4:
In file included from ~/.cmodule/scapix/1.0.11/source/../../../../src/scapix-uint-bug/contact.h:2:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/object.h:11:
~/.cmodule/scapix/1.0.11/source/scapix/bridge/objc/object.h:212:38: note: in instantiation of function template specialization 'scapix::bridge::objc::call_impl<&tiny::contact::testUInt8Vec>::call<NSArray<NSNumber *>
      *, Contact>' requested here
    return call_impl<Func>::template call<ObjcRet>(args...);
                                     ^
In file included from ~/src/scapix-uint-bug/generated/bridge/objc/bridge/bridge/Contact.mm:4:
In file included from ~/.cmodule/scapix/1.0.11/source/../../../../src/scapix-uint-bug/contact.h:2:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/object.h:11:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/objc/object.h:91:
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:27:8: note: template is declared here
struct convert;
       ^
1 warning and 1 error generated.

** BUILD FAILED **


The following build commands failed:
	CompileC build/xcode_mac_objc/tiny_bridge.build/Debug/bridge.build/Objects-normal/x86_64/Contact.o generated/bridge/objc/bridge/bridge/Contact.mm normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

How does scapix parse C++ headers?

I'm not sure if opening an issue for this is appropriate but I have a question regarding scapix's implementation.

I've started to work on a similar project before I came across this and I'm wondering whether scapix can already do what I was trying to achieve. But after skimming through the website and the source code I still don't quite understand how scapix generates bindings. In particular, at some point it must surely parse the C++ headers for which bindings should be generated.

In my project I use Clang for this and then generate Bindings by working with the generated AST via Clang's C++ interface. However, I don't see scapix doing this. The code base seems to consist almost solely of target language specific stuff and is in general much smaller than I would have expected it to be.

So how exactly does scapix process C++ headers?

Weird source files in multilevel CMake build

I have a CMake project with layout like this:

project_root/
    examples/
        CMakeLists.txt
        <some executable examples>
    external/
        CMakeLists.txt
        scapix/
                CMakeLists.txt  <-- Scapix is loaded here
    include/
        <headers to parse are here>
    src/
        CMakeLists.txt  <-- The main library target is created here
        <sources are here>
    CMakeLists.txt

The top-level CMake file includes other files via add_subdirectory: firstly the main target is created in src subfolder via add_library, then Scapix and other libraries are configured, then examples subfolder is added the same way, containing some executable targets created via add_executable (the library is linked to them). The project builds and works fine without Scapix.

The problem is that when I add Scapix to the project with

scapix_bridge_headers(<main library target> com.example.something <path to SomeClass.h>)

and run CMake with -DSCAPIX_BRIDGE=java I get the following errors at configure time:

CMake Error at src/CMakeLists.txt:3 (add_library):
  Cannot find source file:

    <my project path>/generated/bridge/java/SomeClass.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc


CMake Error at examples/CMakeLists.txt:2 (add_executable):
  Cannot find source file:

    <my project path>/generated/bridge/java/com/example/something/SomeClass.java

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc

I do not specify the missing files by myself, it seems like Scapix adds them to the targets somehow.

I can get rid of the first one if I place the content of the CMake file that loads Scapix into the CMake file that creates the library target (src/CMakeLists.txt), but then the second one remains, and I can get rid of the second one if I place it into the CMake file that creates the example target (examples/CMakeLists.txt), but then the first one remains.

Is it possible to fix these errors without throwing all CMake code into a single CMake file?

C# bindings for existing complex libraries

I'm trying to generate c# bindings for existing open-source c++ geometry processing libraries. One example would be the Polygon Mesh Processing library.

My naive attempt to reuse the example and just add the entire pmp source code to the example source folder fails miserably.

What would be the correct way of generating c# bindings for pmp?

Supported stl types?

Is there some documentation that covers which stl types are supported? I tried std::shared_ptr which appears to work nicely, but I also wanted to use std::future but without any luck ("!UNKNOWN!").

std::function parameter in std::function

Hello,
At first, congrats for this very interesting project. I try to implement it into project and found a first problem. A following code doesn't compile:

class TestCase : public scapix::bridge::object<TestCase>
{
public:
    void problem(std::function<void(std::function<void()>)> value){};
};

I see a following error (I try to generate JNI bridges for Android):

error: no member named 'jni' in 'scapix::link::java::convert<scapix::link::java::ref<scapix::link::java::function<scapix::meta::string<'p', 'l', '/', 'a', 'b', 'c', '/', 't', 'e', 's', 't', '/', 'T', 'e', 's', 't', 'C', 'a', 's', 'e', '$', 'F', 'u', 'n', 'c', 't', 'i', 'o', 'n', '1'>, void ()>, scapix::link::java::detail::api::scope::generic>, std::function<void ()>>'

Do you have any plans about implement support for stuff like this?
Best regards,

Error: Failed to checkout tag

OS: Windows 10 1903

I have a very simple project set up to play with scapix. I'm running into an issue when cmake runs the scapix.cmake file.

Checking Build System
Performing download step (git clone) for 'scapix-bin-populate'
Cloning into 'bin'...
fatal: not a git repository (or any of the parent directories): .git
CMake Error at Temp/apps/scapix-example/build/_deps/scapix-bin-subbuild/scapix-bin-populate-prefix/tmp/scapix-bin-populate-gitclone.cmake:40 (message):
  Failed to checkout tag: '7'

I'm very new to cmake and scapix, so there very well could be something in my config/source that's causing issue. I confirmed the project builds and runs prior to introducing scapix into the equation.

Steps to build ios bridge need some clarification

Hey! First off, great project!
I find this tool quite simplistic compared to others out there to bridge c++ with mobile platform.

However I have trouble understanding the steps involved (maybe I am not very well versed in cmake).

While example projects are great, it would be desirable to have step by step instruction about how one goes on to build something from scratch? This is because example projects do not tell what is generated vs what is bare minimum.

Here is my CMakeList.txt:

cmake_minimum_required(VERSION 3.14)

project(MyProject)

include(FetchContent)
FetchContent_Declare(
  cmodule
  URL "https://github.com/scapix-com/cmodule/archive/v1.0.22.tar.gz"
  URL_HASH SHA256=f331d227ae1be52677833baf4fd4728a7c6ee66ec570db6e60d22db0ae43854f
)
FetchContent_MakeAvailable(cmodule)

find_package(Scapix REQUIRED)

scapix_add_target(
    mylib
    "com.example.mylib"
    "cppSource/myclass.hpp"
    "cppSource/myclass.cpp"
)

Here, MyProject is my desired project name and mylib is my intended library name (in iOS target parlance).

Without project line, it complains about it being required. When I supply it to be my desired MyProject, it complains it is not there. But I see sometimes it generates the project automatically.

The command that I run is bash xcode_ios_objc.sh while I encounter project missing error. Previous error (probably the cause of it) is:

CMake Error at /../CMakeLists.txt:492 (add_custom_command):
  Attempt to add a custom rule to output

    /Users/Admin/Desktop/Mapbox/MapProject/generated/bridge/java/map.cpp.rule

  which already has a custom rule.
Call Stack (most recent call first):
  /Users/Admin/.cmodule/scapix/1.0.20/CMakeLists.txt:104 (scapix_bridge)
  /Users/Admin/.cmodule/scapix/1.0.20/CMakeLists.txt:518 (scapix_bridge_headers)
  CMakeLists.txt:19 (scapix_add_target)

Again, while I understand my knowledge of CMake is not great, I think some steps (in readme or in examples) how one goes about it generating project from scratch would be greatly helpful.

Thanks again for the most useful utility!

Support interfaces as callbacks from C++ (in addition to std::function support)

First for all: very interesting project! I was testing it for a new project but I need the ability to implement a C++ interface in the "client" languages.
I could see from https://github.com/scapix-com/example1/blob/a0a0b5a27e4c68c1e2f6bb210901206ff378b213/source/chat/contact.h there is some traces of something along those lines (scapix::bridge::interface). What is the current status of this? Was it scratched or is it coming in the pipelines?

Bug: compilation fails for an std::function with an std::function parameter

Hi,

The use case is somewhat irregular, but I had met it actually trying to bridge a library API to Objective-C, so it's not made up.

Such construct:

class contact : public scapix::bridge::object<contact>
{
public:
   using CbType = function<void(string)>;

   void doAsync(function<void(CbType)> asyncOp)
   {
      CbType cb = [](string msg) -> void { cout << "Async op " << msg << endl; };
      asyncOp(std::move(cb));
   }
};

Compiled with:

cmake -B build/xcode_mac_objc -G "Xcode" -DSCAPIX_BRIDGE=objc -DSCAPIX_PLATFORM=apple
cmake --build build/xcode_mac_objc

fails with:

In file included from ~/src/scapix-test/generated/bridge/objc/bridge/bridge/Contact.mm:4:
In file included from ~/.cmodule/scapix/1.0.11/source/../../../../src/scapix-test/contact.h:1:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/object.h:11:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/objc/object.h:91:
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:32:69: error: rvalue reference to type 'function<...>' cannot bind to lvalue of type 'function<...>'
    return convert<remove_cvref_t<ObjC>, remove_cvref_t<Cpp>>::objc(std::forward<Cpp>(cpp));
                                                                    ^~~~~~~~~~~~~~~~~~~~~~
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:406:30: note: in instantiation of function template specialization 'scapix::link::objc::convert_objc<void (^)(NSString *), std::__1::function<void
      (std::__1::basic_string<char>)> &>' requested here
                return value(convert_objc<ObjcArgs>(args)...);
                             ^
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:38:64: note: in instantiation of member function 'scapix::link::objc::convert<void (^)(void (^)(NSString *)), std::__1::function<void
      (std::__1::function<void (std::__1::basic_string<char>)>)>, void>::cpp' requested here
    return convert<remove_cvref_t<ObjC>, remove_cvref_t<Cpp>>::cpp(std::forward<ObjC>(objc));
                                                               ^
In file included from ~/src/scapix-test/generated/bridge/objc/bridge/bridge/Contact.mm:4:
In file included from ~/.cmodule/scapix/1.0.11/source/../../../../src/scapix-test/contact.h:1:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/object.h:11:
~/.cmodule/scapix/1.0.11/source/scapix/bridge/objc/object.h:212:38: note: in instantiation of function template specialization 'scapix::bridge::objc::call_impl<&tiny::contact::doAsync>::call<void, Contact, void
      (^)(void (^)(NSString *))>' requested here
    return call_impl<Func>::template call<ObjcRet>(args...);
                                     ^
In file included from ~/src/scapix-test/generated/bridge/objc/bridge/bridge/Contact.mm:4:
In file included from ~/.cmodule/scapix/1.0.11/source/../../../../src/scapix-test/contact.h:1:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/object.h:11:
In file included from ~/.cmodule/scapix/1.0.11/source/scapix/bridge/objc/object.h:91:
~/.cmodule/scapix/1.0.11/source/scapix/link/objc/convert.h:412:56: note: passing argument to parameter 'value' here
    static block_type objc(std::function<R(Args...)>&& value)
                                                       ^
1 warning and 1 error generated.

** BUILD FAILED **

The Objective-C generated wrapper looks correct, but C++ templates fail to instantiate.
The typedef/alias for callback type does not affect the behaviour.

what's the purpose of std folder inside scapix ?

Excuse me, sir.

I would like to understand how to adjust the compiler options for scapix. Can I force scapix to use a particular version of gcc or g++ or clang or llvm ?

I also notice there is a folder at https://github.com/scapix-com/scapix/tree/master/std that contains sources for clang and libcxx, how to do I find out if those files are compatible with the compiler I am using.

Using scapix yields errors related to 'std' folder and stdlib.h

/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/stdlib.h:38:12: error:
no member named 'abort' in namespace 'std'
using std::abort;
~~~~~^
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/stdlib.h:39:12: error:
no member named 'atexit' in namespace 'std'
using std::atexit;
~~~~~^
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/stdlib.h:40:12: error:
no member named 'exit' in namespace 'std'
using std::exit;
~~~~~^

scapix/std/libcxxstdlib.h:111:82: error:
use of undeclared identifier 'labs'; did you mean 'abs'?
...long abs( long __x) _NOEXCEPT {return labs(__x);}
/scapix/std/libcxx/stdlib.h:113:81: error:
use of undeclared identifier 'llabs'
...long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
^
/scapix/std/libcxx/stdlib.h:116:35: error:
unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) ...

/scapix/std/libcxx/stdlib.h:116:95: error:
use of undeclared identifier 'ldiv'; did you mean 'div'?
...ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);}

/scapix/std/libcxx/cstdlib:101:9: error:
no member named 'div_t' in the global namespace
using ::div_t;

SIGABRT crash on object creation

I have an interface Foo, it's implementation and the factory Bar that produces Foo.
I get a SIGABRT on creating Foo object in JNI:

JNI DETECTED ERROR IN APPLICATION: can't make objects of type com.scapix.chat.Foo: 0x139a2ba8
    in call to NewObjectV
    from com.scapix.chat.Foo com.scapix.chat.Bar.getFoo()

I use NDK - 20.1.5948944 (clang version 8.0.7), variables are set to:
SCAPIX_BRIDGE - java
SCAPIX_PLATFORM - android
SCAPIX_JAVA_API - android-28

Bar.h

#include <memory>

#include <scapix/bridge/object.h>
#include "Foo.h"

class Bar : public scapix::bridge::object<Bar> {
public:
    std::shared_ptr<Foo> getFoo() {
        return std::static_pointer_cast<Foo>(std::make_shared<FooImpl>());
    }
};

Foo.h

#include <scapix/bridge/object.h>

class Foo : public scapix::bridge::object<Foo> {
public:
    virtual ~Foo() = default;
    virtual void baz() = 0;
};

class FooImpl : public Foo {
public:
    void baz() override {}
};

client's code

val bar = Bar()
val foo = bar.getFoo()   //  SIGABRT here
foo.baz()

Enum class is not propagated to the Python bindings.

Enums are correctly recognised and treated as ints in Java bindings. In Python, however, enums do not work because of the missing declaration.

The C++ code

enum class MyEnum { One = 1, Two };

MyEnum test_return_enum() { return MyEnum::One;}

Causes exception:

Traceback (most recent call last):
  File "test.py", line 23, in <module>
    c.test_return_enum()
TypeError: Unable to convert function return value to a Python type! The signature was
        (self: tests.main) -> tests::MyEnum

To FIX this issue, the scapix generator should generate the following code

pybind11::enum_<MyEnum>(m, "MyEnum", pybind11::arithmetic())
        .value("One", MyEnum::One)
        .value("Two", MyEnum::Two)
        .export_values();

Recursive initialization in `scapix_JNI_OnLoad`

I use Scapix to generate Java interface for my Android app. It works perfectly when the app is built with Android optimizations disabled. But if I enable them (by specifying minifyEnabled true in Gradle) I get the following runtime error when my native class gets called through the Scapix-generated interface:

__cxa_guard_acquire detected recursive initialization
2023-03-26 19:02:54.805  6251-6251  libc                    com.example.myapp     A  Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 6251 (myapp), pid 6251 (myapp)
Cmdline: com.example.myapp
pid: 6251, tid: 6251, name: myapp  >>> com.example.myapp <<<
#01 pc 00000000000d71eb  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libc++_shared.so (BuildId: de4901415b117d03796c38214752f9d82ebc73ca)
#02 pc 00000000000ed1f4  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libc++_shared.so (__cxa_guard_acquire+244) (BuildId: de4901415b117d03796c38214752f9d82ebc73ca)
#03 pc 00000000000d463e  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libMyNativeLib.so (scapix::link::java::object<scapix::meta::string<c, o, m, /, s, c, a, p, i, x, /, N, a, t, i, v, e, E, x, c, e, p, t, i, o, n>, _jthrowable*>::class_object()+62) (BuildId: fbf539b845ed70794f0d2d77fdbb54f620592c61)
#04 pc 0000000000126a90  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libMyNativeLib.so (scapix::link::java::detail::throw_exception(_jthrowable*)+80) (BuildId: fbf539b845ed70794f0d2d77fdbb54f620592c61)
#05 pc 00000000000d483f  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libMyNativeLib.so (scapix::link::java::object<scapix::meta::string<c, o, m, /, s, c, a, p, i, x, /, N, a, t, i, v, e, E, x, c, e, p, t, i, o, n>, _jthrowable*>::class_object()+575) (BuildId: fbf539b845ed70794f0d2d77fdbb54f620592c61)
#06 pc 0000000000126a90  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libMyNativeLib.so (scapix::link::java::detail::throw_exception(_jthrowable*)+80) (BuildId: fbf539b845ed70794f0d2d77fdbb54f620592c61)
#07 pc 00000000000d41e0  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libMyNativeLib.so (scapix::link::java::native_methods<scapix::meta::string<c, o, m, /, s, c, a, p, i, x, /, N, a, t, i, v, e, E, x, c, e, p, t, i, o, n>, scapix::link::java::native_method<scapix::meta::string<f, i, n, a, l, i, z, e>, void (long), void (long), &(scapix::link::java::detail::native_exception::finalize(long))> >::register_()+480) (BuildId: fbf539b845ed70794f0d2d77fdbb54f620592c61)
#08 pc 00000000000d3747  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/base.apk!libMyNativeLib.so (scapix_JNI_OnLoad+87) (BuildId: fbf539b845ed70794f0d2d77fdbb54f620592c61)
#16 pc 0000000000160590  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/oat/x86_64/base.vdex (m4.a.<clinit>+4)
#24 pc 00000000000e8930  /data/app/~~gXjVxylFaFGZZQTr910l-g==/com.example.myapp-PwE5DB0K7_C1EcQOpuVJFQ==/oat/x86_64/base.vdex (com.example.MyNativeLib.MyNativeClass.<clinit>+0)
... (a long list of unrelated Android classes follows)

What might be the cause of this?

Compilation issues with CMake 3.22.3 and Android

Hello,
With CMake 3.22.3 I see a following issues during Android compilation:

In file included from /home/patryk/.cmodule/scapix/1.0.27/source/scapix/bridge/object.h:11:
In file included from /home/patryk/.cmodule/scapix/1.0.27/source/scapix/bridge/java/object.h:14:
In file included from /home/patryk/.cmodule/scapix/1.0.27/source/scapix/link/java/vm.h:11:
/home/patryk/.cmodule/scapix/1.0.27/source/scapix/link/java/thread.h:75:53: error: cannot initialize a parameter of type 'JNIEnv **' (aka '_JNIEnv **') with an rvalue of type 'detail::jnienv_api_type **' (aka 'void **')
auto r = detail::jvm()->AttachCurrentThread((detail::jnienv_api_type**)&detail::env(), args);
                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/data/sdk/android/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/jni.h:1057:39: note: passing argument to parameter 'p_env' here
jint AttachCurrentThread(JNIEnv** p_env, void* thr_args)
                                                       ^

and:

In file included from /home/patryk/.cmodule/scapix/1.0.27/source/scapix/bridge/object.h:11:
In file included from /home/patryk/.cmodule/scapix/1.0.27/source/scapix/bridge/java/object.h:14:
/home/patryk/.cmodule/scapix/1.0.27/source/scapix/link/java/vm.h:61:9: error: no matching function for call to 'JNI_CreateJavaVM'
return JNI_CreateJavaVM(&detail::jvm(), (detail::jnienv_api_type**)&detail::env(), args);
          ^~~~~~~~~~~~~~~~
/data/sdk/android/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/jni.h:1101:6: note: candidate function not viable: no known conversion from 'detail::jnienv_api_type **' (aka 'void **') to 'JNIEnv **' (aka '_JNIEnv **') for 2nd argument
jint JNI_CreateJavaVM(JavaVM**, JNIEnv**, void*);
     ^

with CMake 3.20.2 all works fine. I saw that since CMake 3.21.0 Google's own toolchain uses built-in CMake toolchain file for Android, so maybe this is a source of problems.

ld: library not found for -l<your cpp lib>

Hello, traing to use Scapix in my project for IOS.
Tested scapix_example_objc it works fine.
Tryed to integrate to my project and error below are occured.

`
Ld /Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Products/Debug-iphonesimulator/iosapp.app/iosapp normal (in target 'iosapp' from project 'iosapp')
cd /Users/user/mydata/code/ios/test/objc/example4/scapix_example_objc/iosapp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-ios14.5-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk -L/Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Products/Debug-iphonesimulator -F/Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Products/Debug-iphonesimulator -filelist /Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Intermediates.noindex/iosapp.build/Debug-iphonesimulator/iosapp.build/Objects-normal/x86_64/iosapp.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Intermediates.noindex/iosapp.build/Debug-iphonesimulator/iosapp.build/Objects-normal/x86_64/iosapp_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -lswiftapi -lscapix -lc++ -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Intermediates.noindex/iosapp.build/Debug-iphonesimulator/iosapp.build/iosapp.app-Simulated.xcent -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Intermediates.noindex/iosapp.build/Debug-iphonesimulator/iosapp.build/Objects-normal/x86_64/iosapp_dependency_info.dat -o /Users/user/Library/Developer/Xcode/DerivedData/scapix_example-gatyqgsxryvuoydydfdqoiulcxgq/Build/Products/Debug-iphonesimulator/iosapp.app/iosapp

ld: library not found for -lswiftapi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`

I am tottaly new for c++, can you please provide any suggestions?

Enum are supported

Hi meanwhile thank you for the awesome project, and a question for you enum are supported?

Getting `multiple overloads of 'tuple_base' instantiate to the same signature 'void ()'` error

I'm getting errors like this trying to build a project with Scapix:

In file included from /<my project>/generated/bridge/java/my_class.cpp:4:
In file included from /home/<my username>/.cmodule/scapix/1.0.30/source/scapix/bridge/java/init.h:10:
In file included from /home/<my username>/.cmodule/scapix/1.0.30/source/scapix/link/java/native_method.h:10:
/home/<my username>/.cmodule/scapix/1.0.30/source/scapix/core/tuple.h:33:12: error: multiple overloads of 'tuple_base' instantiate to the same signature 'void ()'
        constexpr tuple_base(Types... values) : tuple_value<Indexes, Types>{ values }... {}
                  ^
/home/<my username>/.cmodule/scapix/1.0.30/source/scapix/core/tuple.h:44:16: note: in instantiation of template class 'scapix::detail::tuple_base<std::integer_sequence<unsigned long>>' requested here
struct tuple : detail::tuple_base<std::index_sequence_for<Types...>, Types...>
               ^
/home/<my username>/.cmodule/scapix/1.0.30/source/scapix/link/java/native_method.h:105:61: note: in instantiation of template class 'scapix::tuple<>' requested here
        inline constexpr static tuple<decltype(Methods::get())...> methods = { Methods::get()... };
                                                                   ^
/<my project>/generated/bridge/java/my_class.cpp:37:22: note: in instantiation of template class 'scapix::link::java::native_methods<scapix::meta::string<'c', 'o', 'm', '/', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '/', 'm', 'y', 'p', 'r', 'o', 'j', '/', 'M', 'y', 'C', 'l', 'a', 's', 's'>>' requested here
        scapix::link::java::native_methods
                            ^
/home/<my username>/.cmodule/scapix/1.0.30/source/scapix/core/tuple.h:30:12: note: previous definition is here
        constexpr tuple_base() = default;
                  ^
1 error generated.
gmake[3]: *** [src/CMakeFiles/myproj.dir/build.make:188: src/CMakeFiles/myproj.dir/__/generated/bridge/java/my_class.cpp.o] Error 1

I'm using clang 14 as a compiler. I have three classes derived from a common virtual class which is derived from scapix::bridge::object<T>. I'm trying to generate a Java interface for all of these classes. The same error appears for all three of the derived classes.

I also tried to derive all of the classes from scapix::bridge::object<T> but this didn't change anything.

Cannot return `std::vector<bool>`

When I'm trying to generate an interface for a class with a method that returns std::vector<bool> I get the following error:

[100%] Building CXX object CMakeFiles/jnav.dir/generated/bridge/java/library.cpp.o
In file included from /mnt/d/Projects/jnav/generated/bridge/java/library.cpp:4:
In file included from /home/eyjafl/.cmodule/scapix/1.0.30/source/scapix/bridge/java/init.h:10:
In file included from /home/eyjafl/.cmodule/scapix/1.0.30/source/scapix/link/java/native_method.h:12:
/home/eyjafl/.cmodule/scapix/1.0.30/source/scapix/link/java/convert.h:210:77: error: 'this' argument to member function 'data' has type 'const std::vector<bool, allocator<bool>>', but function is not marked const
                a->set_region(0, static_cast<jsize>(v.size()), reinterpret_cast<const J*>(v.data()));
                                                                                          ^
/home/eyjafl/.cmodule/scapix/1.0.30/source/scapix/link/java/ref.h:163:60: note: in instantiation of member function 'scapix::link::java::convert<scapix::link::java::ref<scapix::link::java::array<unsigned char>, scapix::link::java::detail::api::scope::generic>, std::vector<bool>>::jni' requested here
        return convert<remove_cvref_t<Jni>, remove_cvref_t<Cpp>>::jni(std::forward<Cpp>(cpp));
                                                                  ^
/home/eyjafl/.cmodule/scapix/1.0.30/source/scapix/link/java/native_method.h:137:29: note: in instantiation of member function 'scapix::link::java::param<scapix::link::java::ref<scapix::link::java::array<unsigned char>, scapix::link::java::detail::api::scope::generic>, std::vector<bool>>::jni' requested here
                                        return param<JniR, R>::jni((get_object<class_type>(thiz).*Method)(param<JniArgs, Args>::cpp(args)...));
                                                               ^
/home/eyjafl/.cmodule/scapix/1.0.30/source/scapix/link/java/native_method.h:186:168: note: in instantiation of member function 'scapix::link::java::native_method<scapix::meta::string<'t', 'e', 's', 't'>, scapix::link::java::ref<scapix::link::java::array<unsigned char>, scapix::link::java::detail::api::scope::generic> (scapix::link::java::ref<scapix::link::java::array<scapix::link::java::array<double>>, scapix::link::java::detail::api::scope::generic>, scapix::link::java::ref<scapix::link::java::array<scapix::link::java::array<double>>, scapix::link::java::detail::api::scope::generic>, scapix::link::java::ref<scapix::link::java::array<scapix::link::java::array<double>>, scapix::link::java::detail::api::scope::generic>), std::vector<bool> (G2oTester::*)(std::vector<std::vector<double>>, std::vector<std::vector<double>>, std::vector<std::vector<double>>) const, &G2oTester::test>::type<true, scapix::link::java::ref<scapix::link::java::array<unsigned char>, scapix::link::java::detail::api::scope::generic> (scapix::link::java::ref<scapix::link::java::array<scapix::link::java::array<double>>, scapix::link::java::detail::api::scope::generic>, scapix::link::java::ref<scapix::link::java::array<scapix::link::java::array<double>>, scapix::link::java::detail::api::scope::generic>, scapix::link::java::ref<scapix::link::java::array<scapix::link::java::array<double>>, scapix::link::java::detail::api::scope::generic>), std::vector<bool> (std::vector<std::vector<double>>, std::vector<std::vector<double>>, std::vector<std::vector<double>>)>::func' requested here
        inline static constexpr auto func = &type<std::is_member_pointer_v<Type>, JniType, remove_function_qualifiers_t<member_pointer_type_t<std::remove_pointer_t<Type>>>>::func;
                                                                                                                                                                              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_bvector.h:964:7: note: 'data' declared here
      data() _GLIBCXX_NOEXCEPT { }
      ^
1 error generated.

Everything works if I just replace bool with uint8_t, for example.

JNI FindClass return null on Android main thread

Hello,
I found a serious problem with Scapix for Android. Problem is related to a following method:

// source/scapix/link/java/class.h
static local_ref<class_> find_class(const char* name)
{
	jclass cls = detail::env()->FindClass(name);
	detail::check_exception(cls);
	return local_ref<class_>(cls);
}

It looks like a standard system vs. application class loader problem. Thats why in manually written bridges I cached jclass at JNI_OnLoad step, however I can't do that similar trick with Scapix.

To produce this issue on Xiaomi phone with Android 12 I just needed to create simple lambda like a:

[this]() -> void
{
	std::shared_ptr<A> a = std::make_shared<A>();
	mCallbackForA(a); // FindClass return null for a, null for NativeException and next abort
}

and enqueue it from a main thread to Android main thread via standard Android looper (solution required for async tasks with final steps at main thread, just I didn't even need to spawn a secondary std::thread for this test). I even compared std:: thread ::id, just to ensure it's not a bug in my app. After that steps FindClass returned null for all my classes and Scapix classes like a NativeException thats why finally I've got '__cxa_guard_acquire detected recursive initialization' error. Maybe you know some quick, temporary workaround for this issue in Scapix? This issue block a release of important update to our app.
Best regards,
Patryk

Custom name for JNI_OnLoad

Hello,
I'm not sure if this functionality doesn't exist in Scapix, but I couldn't find it, so thats why I write this message. In our project we have a lot of JNI code and we can't replace all of them by Scapix in an easy way, but we want to use Scapix for new screens. At this point I found a problem related to JNI_OnLoad. It would be nice to tell a Scapix to generate 'JNI_OnLoad' with a custom name and separate it to *.h and *.cpp file if custom name is provided eg:

[H]
jint customname_JNI_OnLoad(JavaVM* pVM, void* pReserved);
[CPP]
jint customname_JNI_OnLoad(JavaVM* pVM, void* pReserved)
{
    // Scapix code
}

With this feature we will be able to just execute 'customname_JNI_OnLoad' from our 'JNI_OnLoad'. What do you think about this feature?
Patryk,

What is this license?

How does this license compare to well-known open source licenses like Apache2, MIT, BSD etc? Why is there a need for a custom one?

How does scapix parse C++ headers?

I accidentally closed an identical issue earlier, here it is again:

I'm not sure if opening an issue for this is appropriate but I have a question regarding scapix's implementation.

I've started to work on a similar project before I came across this and I'm wondering whether scapix can already do what I was trying to achieve. But after skimming through the website and the source code I still don't quite understand how scapix generates bindings. In particular, at some point it must surely parse the C++ headers for which bindings should be generated.

In my project I use Clang for this and then generate Bindings by working with the generated AST via Clang's C++ interface. However, I don't see scapix doing this. The code base seems to consist almost solely of target language specific stuff and is in general much smaller than I would have expected it to be.

So how exactly does scapix process C++ headers?

Generating a bridge without changing the library

Good day :)
Your tool perfectly helped us integrate a small library into our android application, but there was some question.
Can your tool be used on large libraries without changing the source files of the library itself? We have a library written in std types, and we would like to generate a bridge more automatically without affecting the source files (connecting them, for example, through a submodule).
Maybe you are already doing this or do you have any ideas on this topic?

cmodule SHA256 mismatch

Hello,
Today something wrong was happen. I cannot build any Scapix project (Scapix examples too). I tried on 2 PCs. At the morning all worked fine, but since ~6:00 P.M. (UTC+1) I see a following issue:

-- Using src='https://github.com/scapix-com/cmodule/archive/refs/tags/v1.0.36.tar.gz'
-- [download 75% complete]
-- [download 100% complete]
-- verifying file...
       file='/data/programowanie/example1/build/default/_deps/cmodule-subbuild/cmodule-populate-prefix/src/v1.0.36.tar.gz'
-- SHA256 hash of
    /data/programowanie/example1/build/default/_deps/cmodule-subbuild/cmodule-populate-prefix/src/v1.0.36.tar.gz
  does not match expected value
    expected: '1abd27aa1338bd79daba32543fd7546342eaec949b29401d283a2434b8b568e9'
      actual: '066c86ec465e3a3d05bcc1277c91c446479f38bd47bc8acfdf6af067c50f417f'
-- Hash mismatch, removing...

Maybe it's a some GitHub issue? Do you see a similar problem?

Avoid generation for all specified languages

Good day! Many thanks for this great tool! Could you, please, give me a tip -- is there a way to generate files only for the target platform? For example, in our case, we build a bridge from C++ library to Java-code in Android app and wonder is there a flag/option not to generate bindigs for other languages (Swift, js, python, etc)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.