Tool chain 'gcc' (GNU GCC): Don't know how to build for platform 'linux_aarch64'

I am trying to edit this build.gradle script to build this software on an arm 64 platform:

https://github.com/grpc/grpc-java/blob/v0.15.0/compiler/build.gradle#L55

The initial error I was getting was this one …

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

I opened this ticket:
https://github.com/grpc/grpc-java/issues/2202

the suggested solution was to edit the gradle script to build for this platform.

I made the following change …

  platforms {
    x86_32 {
      architecture "x86"
    }
    x86_64 {
      architecture "x86_64"
    }
    linux_aarch64 {
      operatingSystem "linux"
      architecture "arm64"
    }
  }
  components {
    java_plugin(NativeExecutableSpec) {
      if (arch in ['x86_32', 'x86_64', 'linux_aarch64']) {
        // If arch is not within the defined platforms, we do not specify the
        // targetPlatform so that Gradle will choose what is appropriate.
        targetPlatform arch
      }
      baseName "$protocPluginBaseName"
    }
  }

The build goes farther now, but I am getting a new error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':grpc-compiler:compileJava_pluginExecutableJava_pluginCpp'.
> No tool chain is available to build for platform 'linux_aarch64':
    - Tool chain 'visualCpp' (Visual Studio): Visual Studio is not available on this operating system.
    - Tool chain 'gcc' (GNU GCC): Don't know how to build for platform 'linux_aarch64'.
    - Tool chain 'clang' (Clang): Don't know how to build for platform 'linux_aarch64'.

I am uncertain how to tell the gcc tool chain to build for the platform linux_aarch64.

I found one guy who had a similar problem
this is what he did …

http://gradle.1045684.n5.nabble.com/Customizing-path-to-gcc-doesn-t-seem-to-work-td5712422.html

toolChains {
    gcc(Gcc) {
        path '/path/to/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/bin'
        getCCompiler().executable = 'x86_64-linux-g++'
        getCppCompiler().executable = 'x86_64-linux-g++'
        getLinker().executable = 'x86_64-linux-ld'
        getAssembler().executable = 'x86_64-linux-as'
    }

I am guessing that I should do something similar, to specify the arm64 architecture, but I’m not sure exactly what. Could not find the doc on this.

UPDATED

I tried this …

gcc(Gcc) {
  getCCompiler().executable = 'aarch64-linux-gnu-gcc'
  getCppCompiler().executable = 'aarch64-linux-gnu-g++'
  getLinker().executable = 'aarch64-linux-gnu-ld'
  getAssembler().executable = 'aarch64-linux-gnu-as'
}

but I got this error …

* What went wrong:
A problem occurred configuring project ':grpc-compiler'.
> Exception thrown while executing model rule: toolChains { ... } @ compiler/build.gradle line 42, column 3
   > Could not find method getCCompiler() for arguments [] on Tool chain 'gcc' (GNU GCC) of type org.gradle.nativeplatform.toolchain.internal.gcc.GccToolChain.

Working on the same problem. You can get past this error with the following:

toolChains {
    // If you have both VC and Gcc installed, VC will be selected, unless you
    // set 'vcDisable=true'
    if (!vcDisable) {
      visualCpp(VisualCpp) {
      }
    }
    clang(Clang)
    gcc(Gcc){
        target("linux_aarch64") {
	        cppCompiler.executable = "/usr/bin/gcc"
	    }
    }
    
  }

EDIT: got it fixed!

First, I’m working on branch v0.13.2 because that’s what I need to compile bazel to compile tensorflow.

diff --git a/compiler/build.gradle b/compiler/build.gradle
index a487992..f1d593b 100644
--- a/compiler/build.gradle
+++ b/compiler/build.gradle
@@ -46,10 +46,13 @@ model {
       visualCpp(VisualCpp) {
       }
     }
-    gcc(Gcc) {
-    }
-    clang(Clang) {
+    clang(Clang)
+    gcc(Gcc){
+        target("linux_aarch64") {
+	        cppCompiler.executable = "/usr/bin/gcc"
+	    }
     }
+    
   }
 
   platforms {
@@ -59,11 +62,15 @@ model {
     x86_64 {
       architecture "x86_64"
     }
+    linux_aarch64 {
+      architecture "arm64"
+      operatingSystem "linux"
+    }
   }
 
   components {
     java_plugin(NativeExecutableSpec) {
-      if (arch in ['x86_32', 'x86_64']) {
+      if (arch in ['x86_32', 'x86_64', 'arm64']) {
         // If arch is not within the defined platforms, we do not specify the
         // targetPlatform so that Gradle will choose what is appropriate.
         targetPlatform arch
@@ -91,7 +98,7 @@ model {
           // Clang under OSX doesn't support these options.
           linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-static-libgcc",
                       "-static-libstdc++",
-                      "-Wl,-Bdynamic", "-lpthread", "-s"
+                      "-lpthread", "-lc", "-s", "-static"
         }
         addEnvArgs("LDFLAGS", linker.args)
       } else if (toolChain in VisualCpp) {

I don’t know if I needed to change the linker options, but I figured it couldn’t hurt based on some of the bazel docs.

Also, here’s my gradle.properties file
skipCodegen=false
protoc=/usr/bin/protoc

Where the /usr/bin/protoc was a custom compiled version as described in the grpc-java docs.

1 Like

This solution works as well …
https://www.neotitans.net/install-tensorflow-on-odroid-c2.html