File: build.gradle

package info (click to toggle)
grpc-java 1.26.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 11,852 kB
  • sloc: java: 146,813; cpp: 1,174; xml: 1,037; sh: 662; makefile: 40; python: 40
file content (172 lines) | stat: -rw-r--r-- 6,404 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
plugins {
    id "cpp"
    id "java"
    id "maven-publish"
}

description = 'The protoc plugin for gRPC Java'

def artifactStagingPath = "$buildDir/artifacts" as File
// Adds space-delimited arguments from the environment variable env to the
// argList.
def addEnvArgs = { env, argList ->
    def value = System.getenv(env)
    if (value != null) {
        value.split(' +').each() { it -> argList.add(it) }
    }
}

// Adds corresponding "-l" option to the argList if libName is not found in
// LDFLAGS. This is only used for Mac because when building for uploadArchives
// artifacts, we add the ".a" files directly to LDFLAGS and without "-l" in
// order to get statically linked, otherwise we add the libraries through "-l"
// so that they can be searched for in default search paths.
def addLibraryIfNotLinked = { libName, argList ->
    def ldflags = System.env.LDFLAGS
    if (ldflags == null || !ldflags.contains('lib' + libName + '.a')) {
        argList.add('-l' + libName)
    }
}

def String arch = (System.env.DEB_TARGET_GNU_CPU != null) ? System.env.DEB_TARGET_GNU_CPU : System.env.DEB_HOST_GNU_CPU
def boolean vcDisable = true
def boolean usingVisualCpp // Whether VisualCpp is actually available and selected

model {
    toolChains {
        // If you have both VC and Gcc installed, VC will be selected, unless you
        // set 'vcDisable=true'
        if (!vcDisable) {
            visualCpp(VisualCpp) {
                // Prefer vcvars-provided environment over registry-discovered environment
                def String vsDir = System.getenv("VSINSTALLDIR")
                def String winDir = System.getenv("WindowsSdkDir")
                if (vsDir != null && winDir != null) {
                    installDir = vsDir
                    windowsSdkDir = winDir
                }
            }
        }
        gcc(Gcc) {
            target("ppcle_64")
            target("aarch_64") {
                cppCompiler.executable = 'aarch64-linux-gnu-g++'
                linker.executable = 'aarch64-linux-gnu-g++'
            }
            target("s390_64")
        }
        clang(Clang) {
        }
    }

    platforms {
        x86_32 { architecture "x86" }
        x86_64 { architecture "x86_64" }
        ppcle_64 { architecture "ppcle_64" }
        aarch_64 { architecture "aarch_64" }
        s390_64 { architecture "s390_64" }
    }

    components {
        java_plugin(NativeExecutableSpec) {
            if (arch in [
                'x86_32',
                'x86_64',
                'ppcle_64',
                'aarch_64',
                's390_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
            }
            baseName "$protocPluginBaseName"
        }
    }

    binaries {
        all {
            if (toolChain in Gcc || toolChain in Clang) {
                cppCompiler.define("GRPC_VERSION", version)
                cppCompiler.args "--std=c++0x"
                addEnvArgs("CXXFLAGS", cppCompiler.args)
                addEnvArgs("CPPFLAGS", cppCompiler.args)
                // Link protoc, protobuf, libgcc and libstdc++ statically.
                // Link other (system) libraries dynamically.
                // Clang under OSX doesn't support these options.
                linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-static-libgcc",
                        "-static-libstdc++",
                        "-Wl,-Bdynamic", "-lpthread", "-s"
                addEnvArgs("LDFLAGS", linker.args)
            } else if (toolChain in VisualCpp) {
                usingVisualCpp = true
                cppCompiler.define("GRPC_VERSION", version)
                cppCompiler.args "/EHsc", "/MT"
                if (rootProject.hasProperty('vcProtobufInclude')) {
                    cppCompiler.args "/I${rootProject.vcProtobufInclude}"
                }
                linker.args "libprotobuf.lib", "libprotoc.lib"
                if (rootProject.hasProperty('vcProtobufLibs')) {
                    linker.args "/LIBPATH:${rootProject.vcProtobufLibs}"
                }
            }
        }
    }
}

println "*** Building codegen requires Protobuf version ${protocVersion}"
println "*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin"

task buildArtifacts(type: Copy) {
    dependsOn 'java_pluginExecutable'
    from("$buildDir/exe") {
        rename 'protoc-gen-grpc-java', '$0.exe'
    }
    into artifactStagingPath
}

archivesBaseName = "$protocPluginBaseName"

task checkArtifacts {
    dependsOn buildArtifacts
    doLast {
        if (!usingVisualCpp) {
            def ret = exec {
                executable 'bash'
                args 'check-artifact.sh', System.env.DEB_HOST_GNU_SYSTEM, System.env.DEB_HOST_GNU_CPU
            }
            if (ret.exitValue != 0) {
                throw new GradleException("check-artifact.sh exited with " + ret.exitValue)
            }
        } else {
            def exeName = "$artifactStagingPath/java_plugin/${protocPluginBaseName}.exe"
            def os = new ByteArrayOutputStream()
            def ret = exec {
                executable 'dumpbin'
                args '/nologo', '/dependents', exeName
                standardOutput = os
            }
            if (ret.exitValue != 0) {
                throw new GradleException("dumpbin exited with " + ret.exitValue)
            }
            def dlls = os.toString() =~ /Image has the following dependencies:\s+(.*)\s+Summary/
            if (dlls[0][1] != "KERNEL32.dll") {
                throw new Exception("unexpected dll deps: " + dlls[0][1]);
            }
            os.reset()
            ret = exec {
                executable 'dumpbin'
                args '/nologo', '/headers', exeName
                standardOutput = os
            }
            if (ret.exitValue != 0) {
                throw new GradleException("dumpbin exited with " + ret.exitValue)
            }
            def machine = os.toString() =~ / machine \(([^)]+)\)/
            def expectedArch = [x86_32: "x86", x86_64: "x64"][arch]
            if (machine[0][1] != expectedArch) {
                throw new Exception("unexpected architecture: " + machine[0][1]);
            }
        }
    }
}