Unity: How to build grpc_csharp_ext for Magic Leap (and any other platforms)

61 views
Skip to first unread message

ryok...@gmail.com

unread,
Mar 26, 2019, 2:17:47 AM3/26/19
to grpc.io
I'm trying to make streaming speech recognition (Google.Cloud.Speech.V1) work in Magic Leap app.


I've managed to make it work in Unity Editor (Windows x64) as in this video: 
But once I build it straight into Magic Leap runtime, I'll get this error:

grpc_csharp_ext.dll not found

... since this DLL in the project is built for Windows x64 runtime (which I just copied & pasted from repo) which works in Editor but won't get carried to Magic Leap runtime.
So I'm trying to build "grpc_csharp_ext.dll" for Magic Leap myself. And I'm stuck :)


Magic Leap has its own Linux OS called LuminOS, which has its own C/C++ builder called "Mabu".
Build files (.mabu) in Mabu look like this:

KIND = shared
OUTNAME
= grpc_csharp_ext
SRCS
= ../ext/grpc_csharp_ext.c
INCS
= ../../../include

Above I'm basically telling Mabu to build a shared library (DLL) named as "grpc_csharp_ext", using the source C file and any files in the include folder for references.
Following is the log when Mabu runs the build file:

D:\Projects\_extern_\grpc\src\csharp\experimental>mabu grpc_csharp_ext.mabu -t release_win_msvc-2017_x64
[grpc_csharp_ext] Compiling grpc_csharp_ext.c...
grpc_csharp_ext
.c
[grpc_csharp_ext] Linking DLL grpc_csharp_ext.dll...
   
Creating library grpc_csharp_ext.lib and object grpc_csharp_ext.exp
grpc_csharp_ext
.c-99b723c0f96300a2.o : error LNK2019: unresolved external symbol grpc_raw_byte_buffer_create referenced in function string_to_byte_buffer
grpc_csharp_ext
.c-99b723c0f96300a2.o : error LNK2019: unresolved external symbol grpc_byte_buffer_length referenced in function grpcsharp_batch_context_recv_message_length
***** BUNCH OF OTHER LINK ISSUES *****
grpc_csharp_ext
.c-99b723c0f96300a2.o : error LNK2019: unresolved external symbol gpr_thd_currentid referenced in function grpcsharp_log_handler
grpc_csharp_ext
.dll : fatal error LNK1120: 67 unresolved externals
make
: *** [D:/Projects/_extern_/grpc/src/csharp/experimental/.out/release_win_msvc-2017_x64/grpc_csharp_ext.mk:22: D:/Projects/_extern_/grpc/src/csharp/experimental/.out/release_win_msvc-2017_x64/grpc_csharp_ext.dll] Error

Note "unresolved external symbol" errors.
I'm thinking the cause is that those .h files in the include folder don't have actual implementation .c files.
For example, grpc/impl/codegen/byte_buffer.h goes like:

#ifndef GRPC_IMPL_CODEGEN_BYTE_BUFFER_H
#define GRPC_IMPL_CODEGEN_BYTE_BUFFER_H

#include <grpc/impl/codegen/port_platform.h>

#include <grpc/impl/codegen/grpc_types.h>

#ifdef __cplusplus
extern "C" {
#endif

/** Returns a RAW byte buffer instance over the given slices (up to \a nslices).
 *
 * Increases the reference count for all \a slices processed. The user is
 * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/

GRPCAPI grpc_byte_buffer
* grpc_raw_byte_buffer_create(grpc_slice* slices,
                                                      size_t nslices
);

/** Returns a *compressed* RAW byte buffer instance over the given slices (up to
 * \a nslices). The \a compression argument defines the compression algorithm
 * used to generate the data in \a slices.
 *
 * Increases the reference count for all \a slices processed. The user is
 * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/

GRPCAPI grpc_byte_buffer
* grpc_raw_compressed_byte_buffer_create(
    grpc_slice
* slices, size_t nslices, grpc_compression_algorithm compression);

which defines grpc_raw_byte_buffer_create() but doesn't implement it, hense the "unresolved symbol" error above (1st one).
I couldn't find those implementation .c files anywhere in the repo (except PHP ones).

I did read iOS/Android build files in Unity experimental folder in the repo, but failed to track down where the .c files are coming from.


So I'm stuck here.
  • Can someone explain where all the other builds (cmakes) are fetching the implementation .c files from?
  • Or does it actually need to be implemented anew for LuminOS?

Thank you!
Ryo
How can



.com/ryoichirooka/status/1110313722826784768



ryok...@gmail.com

unread,
Mar 30, 2019, 8:06:12 PM3/30/19
to grpc.io
Self-updating...

I've managed a little forward and done following:

- Run cmake (which succeeds) with a bash script as following:

rmdir build
mkdir
-p build
cd build

cmake
../.. \
   
-DCMAKE_BUILD_TYPE=Release \
   
-DCMAKE_TOOLCHAIN_FILE=../magicleap.toolchain.cmake \
   
-DRUN_HAVE_POSIX_REGEX=0 \
   
-DRUN_HAVE_STD_REGEX=0 \
   
-DRUN_HAVE_STEADY_CLOCK=0 \

Now I'm attempting to build the "grpc_csharp_ext" library as in:

make grpc_csharp_ext

which fails, with error output as following:

...
[ 31%] Generating sha1-armv8.S
[ 31%] Generating sha256-armv8.S
Scanning dependencies of target fipsmodule
[ 31%] Building C object third_party/boringssl/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/bcm.c.o
[ 31%] Building C object third_party/boringssl/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/is_fips.c.o
[ 31%] Building ASM object third_party/boringssl/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/aesv8-armx.S.o
/Users/ryoichirooka/projects/grpc/cmake/build/third_party/boringssl/crypto/fipsmodule/aesv8-armx.S:37:2: error: instruction requires: neon
 eor v0
.16b,v0.16b,v0.16b
 
^
/Users/ryoichirooka/projects/grpc/cmake/build/third_party/boringssl/crypto/fipsmodule/aesv8-armx.S:38:2: error: instruction requires: neon
 ld1
{v3.16b},[x0],#16
 
^
/Users/ryoichirooka/projects/grpc/cmake/build/third_party/boringssl/crypto/fipsmodule/aesv8-armx.S:40:2: error: instruction requires: neon
 ld1
{v1.4s,v2.4s},[x3],#32
 
^
...

Note "error: instruction requires: neon".

I haven't figured out how to address this one and am actively looking for solution. Please let me know if you have any directions

Thank you,
Ryo

Jan Tattermusch

unread,
Apr 8, 2019, 6:43:29 AM4/8/19
to grpc.io
I have no experience with MagicLeap, but from your description it looks like you're trying to do the right thing - basically you need to custom-build a version of grpc_csharp_ext  that targets LuminOS (and your steps to achieving so seem to be correct).
The build error with boringssl could be because it tries to build the assembly-optimized version of boringssl (see e.g. https://github.com/grpc/grpc/blob/master/doc/ssl-performance.md) and for some reason it fails.
You can try to disable the asm-optimized build by setting -DOPENSSL_NO_ASM=ON while invoking cmake (see FTR https://github.com/grpc/grpc/blob/f10596f0f3d6ab2dfe67b86d259a8d3effb73a99/cmake/ssl.cmake#L26),
and maybe that will unblock your build.
Reply all
Reply to author
Forward
0 new messages