Skip to content

Changing CXXFLAGS and LDFLAGS is ignored due to Gradle daemon #2888

@avsdev-cw

Description

@avsdev-cw

Apologies for the length, I've tried to provide as much detail as possible. I'm trying to natively compile this on an nVidia Jetson TX2 board (aarch64)

What version of gRPC are you using?

nvidia@tegra-ubuntu:~/grpc-java$ git show --oneline -s

903197b core: StreamTracer (#2863)

What JVM are you using (java -version)?

nvidia@tegra-ubuntu:~/grpc-java$ java -version

openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

What did you do?

nvidia@tegra-ubuntu:~$ git clone https://github.com/google/protobuf.git && cd protobuf
nvidia@tegra-ubuntu:~/protobuf$ git checkout v3.1.0
nvidia@tegra-ubuntu:~/protobuf$ ./autogen.sh
nvidia@tegra-ubuntu:~/protobuf$ ./configure --prefix=/opt/protobuf
nvidia@tegra-ubuntu:~/protobuf$ make && make install
nvidia@tegra-ubuntu:~/protobuf$ export PATH=/opt/protobuf/bin/:$PATH
nvidia@tegra-ubuntu:~/protobuf$ export LD_LIBRARY_PATH=/opt/protobuf/lib/:$LD_LIBRARY_PATH
nvidia@tegra-ubuntu:~/protobuf$ export CXXFLAGS=-I/opt/protobuf/include
nvidia@tegra-ubuntu:~/protobuf$ export LDFLAGS=-L/opt/protobuf/lib
nvidia@tegra-ubuntu:~/protobuf$ ls -l /opt/protobuf/{lib,bin,include/google/protobuf/io}
/opt/protobuf/bin:
total 268
-rwxr-xr-x 1 root root 272752 Apr  7 13:47 protoc

/opt/protobuf/include/google/protobuf/io:
total 160
-rw-r--r-- 1 root root 59255 Apr  7 13:47 coded_stream.h
-rw-r--r-- 1 root root  6598 Apr  7 13:47 gzip_stream.h
-rw-r--r-- 1 root root 16666 Apr  7 13:47 printer.h
-rw-r--r-- 1 root root  2431 Apr  7 13:47 strtod.h
-rw-r--r-- 1 root root 16598 Apr  7 13:47 tokenizer.h
-rw-r--r-- 1 root root 10185 Apr  7 13:47 zero_copy_stream.h
-rw-r--r-- 1 root root 13655 Apr  7 13:47 zero_copy_stream_impl.h
-rw-r--r-- 1 root root 16753 Apr  7 13:47 zero_copy_stream_impl_lite.h

/opt/protobuf/lib:
total 209472
-rw-r--r-- 1 root root 60953590 Apr  7 13:47 libprotobuf.a
-rwxr-xr-x 1 root root      991 Apr  7 13:47 libprotobuf.la
-rw-r--r-- 1 root root  5724374 Apr  7 13:47 libprotobuf-lite.a
-rwxr-xr-x 1 root root     1026 Apr  7 13:47 libprotobuf-lite.la
lrwxrwxrwx 1 root root       26 Apr  7 13:47 libprotobuf-lite.so -> libprotobuf-lite.so.12.0.0
lrwxrwxrwx 1 root root       26 Apr  7 13:47 libprotobuf-lite.so.12 -> libprotobuf-lite.so.12.0.0
-rwxr-xr-x 1 root root  2390392 Apr  7 13:47 libprotobuf-lite.so.12.0.0
lrwxrwxrwx 1 root root       21 Apr  7 13:47 libprotobuf.so -> libprotobuf.so.12.0.0
lrwxrwxrwx 1 root root       21 Apr  7 13:47 libprotobuf.so.12 -> libprotobuf.so.12.0.0
-rwxr-xr-x 1 root root 24405752 Apr  7 13:47 libprotobuf.so.12.0.0
-rw-r--r-- 1 root root 91333170 Apr  7 13:47 libprotoc.a
-rwxr-xr-x 1 root root     1010 Apr  7 13:47 libprotoc.la
lrwxrwxrwx 1 root root       19 Apr  7 13:47 libprotoc.so -> libprotoc.so.12.0.0
lrwxrwxrwx 1 root root       19 Apr  7 13:47 libprotoc.so.12 -> libprotoc.so.12.0.0
-rwxr-xr-x 1 root root 29662544 Apr  7 13:47 libprotoc.so.12.0.0
drwxr-xr-x 2 root root     4096 Apr  7 13:47 pkgconfig
nvidia@tegra-ubuntu:~/protobuf$ cd ~/
nvidia@tegra-ubuntu:~$ git clone https://github.com/grpc/grpc-java.git && cd grpc-java
nvidia@tegra-ubuntu:~/grpc-java$ ./gradlew build
*** Building codegen requires Protobuf version 3.2.0
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':grpc-compiler'.
> Exception thrown while executing model rule: NativeComponentModelPlugin.Rules#createBinaries(TargetedNativeComponentInternal, PlatformResolvers, BuildTypeContainer, FlavorContainer, ServiceRegistry)
   > Invalid NativePlatform: linux_aarch64

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.646 secs

Googled for a bit and found this discussion amongst others so made some mods...

nvidia@tegra-ubuntu:~/grpc-java$ git diff

diff --git a/compiler/build.gradle b/compiler/build.gradle
index 10d9c31..cfd1850 100644
--- a/compiler/build.gradle
+++ b/compiler/build.gradle
@@ -48,6 +48,9 @@ model {
     }
     gcc(Gcc) {
       target("ppcle_64")
+      target("linux_aarch64"){
+        cppCompiler.executable = "/usr/bin/gcc"
+      }
     }
     clang(Clang) {
     }
@@ -60,6 +63,9 @@ model {
     x86_64 {
       architecture "x86_64"
     }
+    linux_aarch64 {
+      architecture "arm64"
+    }
     ppcle_64 {
       architecture "ppcle_64"
     }
@@ -67,7 +73,7 @@ model {
 
   components {
     java_plugin(NativeExecutableSpec) {
-      if (arch in ['x86_32', 'x86_64', 'ppcle_64']) {
+      if (arch in ['x86_32', 'x86_64', 'arm64', 'ppcle_64']) {
         // If arch is not within the defined platforms, we do not specify the
         // targetPlatform so that Gradle will choose what is appropriate.
         targetPlatform arch

nvidia@tegra-ubuntu:~/grpc-java$ ./gradlew build

*** Building codegen requires Protobuf version 3.2.0
*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin
:grpc-context:compileJava
:grpc-context:processResources NO-SOURCE
:grpc-context:classes
:grpc-context:jar
:grpc-core:compileJava
:grpc-core:processResources
:grpc-core:classes
:grpc-core:jar
:grpc-auth:compileJava
:grpc-auth:processResources NO-SOURCE
:grpc-auth:classes
:grpc-auth:jar
:grpc-netty:compileJava
:grpc-netty:processResources
:grpc-netty:classes
:grpc-netty:jar
:grpc-okhttp:compileJava
:grpc-okhttp:processResources
:grpc-okhttp:classes
:grpc-okhttp:jar
:grpc-compiler:compileJava_pluginExecutableJava_pluginCppIn file included from /home/nvidia/grpc-java/compiler/src/java_plugin/cpp/java_generator.cpp:1:0:
/home/nvidia/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:49: fatal error: google/protobuf/io/zero_copy_stream.h: No such file or directory
compilation terminated.

In file included from /home/nvidia/grpc-java/compiler/src/java_plugin/cpp/java_plugin.cpp:8:0:
/home/nvidia/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:49: fatal error: google/protobuf/io/zero_copy_stream.h: No such file or directory
compilation terminated.

/home/nvidia/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:49: fatal error: google/protobuf/io/zero_copy_stream.h: No such file or directory
compilation terminated.

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':grpc-compiler:compileJava_pluginExecutableJava_pluginCpp'.
> Multiple build operations failed.
      C++ compiler failed while compiling java_generator.cpp.
      C++ compiler failed while compiling java_plugin.cpp.
      C++ compiler failed while compiling java_generator.h.
  See the complete log at: file:///home/nvidia/grpc-java/compiler/build/tmp/compileJava_pluginExecutableJava_pluginCpp/output.txt

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 43.251 secs

What did you expect to see?

Successful build

What did you see instead?

In short:

/home/nvidia/grpc-java/compiler/src/java_plugin/cpp/java_generator.h:8:49: fatal error: google/protobuf/io/zero_copy_stream.h: No such file or directory
compilation terminated.

despite protobuf being compiled & installed and CXXFLAGS and LDFLAGS being set.

Also tried adding the 4 exports above at the end of my .bashrc file as it seemed to have helped in [this issue] (#1346)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions