Creating a CPP native library from existing binaries


(Mate Molnar) #1

Hi,

I would like to use the new native plugins for our cpp build.

I’ve uploaded the artifact to the repo like:

apply plugin: 'maven-publish'
group = 'my.company'
version = '1.0'

publishing {
  repositories {
    maven {
      url = 'http://repo.url'
    }
  }
  publications  {
    myPublication(MavenPublication) {
      artifact('/path/to/file.so')
    }
  }
}

But when consuming it:

apply plugin: 'cpp-library'

repositories {
  maven {
    url = 'http://repo.url'
  }
}

library {
  dependencies {
    implementation 'my.company:dependency:1.0'
  }
}

I get the error:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all artifacts for configuration ':project:cppCompileDebug'.
> Could not resolve my.company:dependency:1.0.
  Required by:
      project :project
   > Unable to find a matching configuration of my.company:dependency:1.0:
       - Configuration 'compile':
           - Required org.gradle.native.debuggable 'true' but no value provided.
           - Required org.gradle.native.optimized 'false' but no value provided.
           - Required org.gradle.usage 'cplusplus-api' and found incompatible value 'java-api'.
       - Configuration 'runtime':
           - Required org.gradle.native.debuggable 'true' but no value provided.
           - Required org.gradle.native.optimized 'false' but no value provided.
           - Required org.gradle.usage 'cplusplus-api' and found incompatible value 'java-runtime'.

How can I create the missing Gradle Module Metadata file?

Thanks,
Mate


(Sterling Greene) #2

Hi @matemoln,

We have a lot of the pieces for this, but there’s not a built in API for this. You need to describe the relationship of headers, shared libraries, etc in a way that Gradle can select the right files for the scenario (use headers for compilation, use shared library for runtime, use static library for linking).

In our samples, we demonstrate a couple of ways to approach this depending on what you need.

We have a prebuilt sample that uses a library that was built by something outside of the current build (you could imagine this is on the file system):

We also have a sample that uses CMake to build things and wraps the output in a way that Gradle can understand.

We don’t have a sample for it, but you could probably also figure out a way to configure the cpp-library plugin to “build” a pre-existing library instead of manually configuring the publications like you have. That would generate an appropriate Gradle metadata file.

HTH


(Mate Molnar) #3

Thanks Sterling!
I can work with this. :slight_smile:


(Chip Dickson) #4

Did you happen to have any luck with this? I am trying to create something to publish several hundred 3rd party native libraries and would love to hear how you ended up approaching this.