Native: how declare a module that only exports headers?

native

(ZOSROTHKO) #1

Hi

I have a module that contains only includes files and would like to export them to be consumed by the other modules. So, the build.gradle would be like

model {
	components {
		assert(NativeLibrarySpec) {
                    sources {
                        cpp {
                            exportedHeaders {
                              srcDirs "include"
                            } 
                       }
                   }
	      }
	}
}

but the build fails with a closure exception

A problem occurred configuring project ':libs:assert'.
> Exception thrown while executing model rule: components { ... } @ libs\assert\build.gradle line 2, column 2
   > Cannot cast object 'build_74j8sva4y7dbyjzuvyl68onma$_run_closure1$_closure2$_closure3@50cb21' with class 'build_74j8sva4y7dbyjzuvyl68onma$_run_closure1$_closure2$_closure3' to class 'org.gradle.nativeplatform.NativeLibrarySpec'

How should be declared a include only module?


(Alexander Volanis) #2

I believe you are running into a known issue with Java/Groovy keywords mixed into Gradle DSL. “assert” is a keyword and should be placed in quotes to avoid confusing it with the keyword.

This would work:

model {
	components {
		"assert"(NativeLibrarySpec) {
                    sources {
                        cpp {
                            exportedHeaders {
                              srcDirs "include"
                            } 
                       }
                   }
	      }
	}
}

Note how the component name is in quotes.


(ZOSROTHKO) #3

I am also wondering why the module should be a NativeLibrarySpec. Why a NativeComponentSpec does not work? THis module will never produce any NativeBinary but is somewhat a component part of the building process?


(Alexander Volanis) #4

A NativeLibrary is a component that supports exportedHeaders. NativeComponentSpec is a base class for all component types and does not have an exportedHeaders capability. Gradle will not build a native binary for such a library and when making a reference to such a library linkage: must be set to ‘api’ to signal that you are not expecting a library to link with, just new headers added to the include paths.