Home | History | Annotate | Download | only in conscrypt
      1 //
      2 // Copyright (C) 2016 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 //
     18 // Definitions for building the Conscrypt Java library, native code,
     19 // and associated tests.
     20 //
     21 
     22 // Conscrypt is divided into subdirectories.
     23 //
     24 // The structure is:
     25 //
     26 //   constants/
     27 //       src/gen             # Generates NativeConstants.java.
     28 //   common/
     29 //       src/main/java       # Common Java source for all platforms.
     30 //       src/jni/
     31 //            main           # Common C++ source for all platforms.
     32 //            unbundled      # C++ source used for OpenJDK and unbundled Android.
     33 //       src/test/java       # Common test files for all platforms.
     34 //   android/
     35 //       src/main/java       # Java source for unbundled Android.
     36 //   openjdk/
     37 //       src/main/java       # Java source for OpenJDK.
     38 //       src/test
     39 //            java/          # Java source for common tests.
     40 //            resources/     # Support files for tests
     41 //   platform/
     42 //       src/main/java       # Java source for bundled Android.
     43 //       src/test
     44 //            java/          # Java source for bundled tests.
     45 //
     46 
     47 cc_defaults {
     48     name: "conscrypt_global",
     49 
     50     cflags: [
     51         "-Wall",
     52         "-Wextra",
     53         "-Werror",
     54         "-Wunused",
     55     ],
     56 
     57     srcs: [
     58         "common/src/jni/main/cpp/conscrypt/compatibility_close_monitor.cc",
     59         "common/src/jni/main/cpp/conscrypt/jniload.cc",
     60         "common/src/jni/main/cpp/conscrypt/jniutil.cc",
     61         "common/src/jni/main/cpp/conscrypt/native_crypto.cc",
     62         "common/src/jni/main/cpp/conscrypt/netutil.cc",
     63         "common/src/jni/main/cpp/conscrypt/trace.cc",
     64     ],
     65 
     66     local_include_dirs: [
     67         "common/src/jni/main/include",
     68     ],
     69 
     70     compile_multilib: "both",
     71     stl: "c++_static",
     72 }
     73 
     74 cc_defaults {
     75     name: "conscrypt_unbundled-jni-defaults",
     76 
     77     local_include_dirs: [
     78         "common/src/jni/unbundled/include",
     79     ],
     80 
     81     shared_libs: [
     82         "liblog",
     83     ],
     84 
     85     static_libs: [
     86         "libssl",
     87         "libcrypto",
     88     ],
     89 
     90     sdk_version: "9",
     91 }
     92 
     93 cc_library {
     94     name: "libconscrypt_jni",
     95     defaults: [
     96         "conscrypt_global",
     97         "conscrypt_unbundled-jni-defaults",
     98     ],
     99 }
    100 
    101 cc_library_host_shared {
    102     name: "libconscrypt_openjdk_jni",
    103     defaults: ["conscrypt_global"],
    104 
    105     cflags: [
    106         "-DCONSCRYPT_OPENJDK",
    107     ],
    108 
    109     local_include_dirs: [
    110         "common/src/jni/unbundled/include",
    111     ],
    112 
    113     static_libs: [
    114         "libssl",
    115         "libcrypto",
    116     ],
    117 
    118     // TODO: b/26097626. ASAN breaks use of this library in JVM.
    119     // Re-enable sanitization when the issue with making clients of this library
    120     // preload ASAN runtime is resolved. Without that, clients are getting runtime
    121     // errors due to unresolved ASAN symbols, such as
    122     // __asan_option_detect_stack_use_after_return.
    123     sanitize: {
    124         never: true,
    125     },
    126 
    127     stl: "libc++_static",
    128 
    129     // The post-build signing tools need signapk.jar and its shared libs
    130     multilib: {
    131         lib64: {
    132             dist: {
    133                 targets: ["droidcore"],
    134             },
    135         },
    136     },
    137 }
    138 
    139 cc_binary_host {
    140     name: "conscrypt_generate_constants",
    141     srcs: ["constants/src/gen/cpp/generate_constants.cc"],
    142     cflags: [
    143         "-Wall",
    144         "-Werror",
    145     ],
    146     shared_libs: [
    147         "libcrypto",
    148         "libssl",
    149     ],
    150 }
    151 
    152 genrule {
    153     name: "conscrypt-nojarjar_generated_constants",
    154     out: ["org/conscrypt/NativeConstants.java"],
    155     cmd: "$(location conscrypt_generate_constants) > $(out)",
    156     tools: ["conscrypt_generate_constants"],
    157 }
    158 
    159 // Create the conscrypt library without jarjar for tests
    160 java_library {
    161     name: "conscrypt-nojarjar",
    162     host_supported: true,
    163     hostdex: true,
    164 
    165     srcs: [
    166         "common/src/main/java/**/*.java",
    167         ":conscrypt-nojarjar_generated_constants",
    168     ],
    169 
    170     no_standard_libs: true,
    171     system_modules: "core-all-system-modules",
    172     target: {
    173         android: {
    174             srcs: ["platform/src/main/java/**/*.java"],
    175             libs: ["core-all"],
    176         },
    177         host: {
    178             srcs: ["openjdk/src/main/java/**/*.java"],
    179             javacflags: ["-XDignore.symbol.file"],
    180         },
    181     },
    182 
    183     required: ["libjavacrypto"],
    184     java_version: "1.7",
    185 }
    186 
    187 genrule {
    188     name: "conscrypt_generated_constants",
    189     out: ["com/android/org/conscrypt/NativeConstants.java"],
    190     cmd: "$(location conscrypt_generate_constants) com.android.org.conscrypt > $(out)",
    191     tools: ["conscrypt_generate_constants"],
    192 }
    193 
    194 filegroup {
    195     name: "conscrypt_java_files",
    196     srcs: [
    197         "repackaged/common/src/main/java/**/*.java",
    198         "repackaged/platform/src/main/java/**/*.java",
    199         ":conscrypt_generated_constants",
    200     ],
    201 }
    202 
    203 filegroup {
    204     name: "conscrypt_public_api_files",
    205     srcs: ["publicapi/src/main/java/**/*.java"]
    206 }
    207 
    208 // Create the conscrypt library from the source produced by the srcgen/generate_android_src.sh
    209 // script.
    210 java_library {
    211     name: "conscrypt",
    212     installable: true,
    213     hostdex: true,
    214 
    215     srcs: [
    216         ":conscrypt_java_files",
    217         ":conscrypt_public_api_files",
    218     ],
    219 
    220     // Conscrypt can be updated independently from the other core libraries so it must only depend
    221     // on public SDK and intra-core APIs.
    222     no_standard_libs: true,
    223     libs: ["core.intra.stubs"],
    224     patch_module: "java.base",
    225     system_modules: "core-intra-stubs-system-modules",
    226 
    227     // Workaround for b/124476339: libjavacrypto is required for both APEX and
    228     // hostdex builds, but adding a top-level required property results in
    229     // it being installed to /system on Android.
    230     // TODO(b/124476339): move required back to a top level property
    231     target: {
    232         hostdex: {
    233             required: ["libjavacrypto"],
    234         }
    235     },
    236 
    237     permitted_packages: [
    238         "android.net.ssl",
    239         "com.android.org.conscrypt",
    240     ],
    241 }
    242 
    243 // A guaranteed unstripped version of conscrypt.
    244 // The build system may or may not strip the conscrypt jar, but this one will
    245 // not be stripped. See b/24535627.
    246 java_library {
    247     name: "conscrypt-testdex",
    248     installable: true,
    249 
    250     static_libs: ["conscrypt"],
    251     dex_preopt: {
    252         enabled: false,
    253     },
    254 
    255     no_framework_libs: true,
    256 
    257     required: ["libjavacrypto"],
    258 }
    259 
    260 // Platform conscrypt crypto JNI library
    261 cc_defaults {
    262     name: "libjavacrypto-defaults",
    263 
    264     cflags: [
    265         "-Wall",
    266         "-Wextra",
    267         "-Werror",
    268         "-Wunused",
    269         "-fvisibility=hidden",
    270     ],
    271 
    272     srcs: ["common/src/jni/main/cpp/**/*.cc"],
    273     include_dirs: [
    274         "libcore/luni/src/main/native",
    275     ],
    276     local_include_dirs: ["common/src/jni/main/include"],
    277 }
    278 
    279 // Platform conscrypt crypto JNI library
    280 cc_library_shared {
    281     name: "libjavacrypto",
    282     host_supported: true,
    283     defaults: ["libjavacrypto-defaults"],
    284 
    285     cflags: ["-DJNI_JARJAR_PREFIX=com/android/"],
    286     header_libs: ["libnativehelper_header_only"],
    287     shared_libs: [
    288         "libcrypto",
    289         "liblog",
    290         "libssl",
    291     ],
    292 
    293     target: {
    294         darwin: {
    295             enabled: false,
    296         },
    297     },
    298 }
    299 
    300 // Unbundled Conscrypt jar
    301 java_library {
    302     name: "conscrypt_unbundled",
    303 
    304     srcs: [
    305         "common/src/main/java/**/*.java",
    306         "android/src/main/java/**/*.java",
    307         ":conscrypt-nojarjar_generated_constants",
    308     ],
    309 
    310     libs: ["conscrypt-stubs"],
    311 
    312     sdk_version: "current",
    313     java_version: "1.7",
    314 }
    315 
    316 // Stub library for unbundled builds
    317 java_library {
    318     name: "conscrypt-stubs",
    319 
    320     srcs: ["android-stub/src/main/java/**/*.java"],
    321 
    322     sdk_version: "current",
    323     java_version: "1.7",
    324 }
    325 
    326 // Static unbundled Conscrypt crypto JNI library
    327 cc_library_static {
    328     name: "libconscrypt_static",
    329     defaults: ["libjavacrypto-defaults"],
    330 
    331     cflags: [
    332         "-DJNI_JARJAR_PREFIX=com/google/android/gms/",
    333         "-DCONSCRYPT_UNBUNDLED",
    334         "-DSTATIC_LIB",
    335     ],
    336 
    337     local_include_dirs: ["common/src/jni/unbundled/include"],
    338 
    339     static_libs: [
    340         "libssl",
    341         "libcrypto",
    342     ],
    343     sdk_version: "9",
    344     stl: "c++_shared",
    345 }
    346 
    347 
    348 // Make the conscrypt-tests library.
    349 java_test {
    350     name: "conscrypt-tests",
    351     hostdex: true,
    352     srcs: [
    353         "repackaged/platform/src/test/java/**/*.java",
    354         "repackaged/common/src/test/java/**/*.java",
    355         "repackaged/openjdk-integ-tests/src/test/java/**/*.java",
    356         "repackaged/testing/src/main/java/**/*.java",
    357         "publicapi/src/test/java/**/*.java",
    358     ],
    359     java_resource_dirs: [
    360         // Resource directories do not need repackaging.
    361         "openjdk/src/test/resources",
    362         "openjdk-integ-tests/src/test/resources",
    363     ],
    364 
    365     no_standard_libs: true,
    366     libs: [
    367         "core-all",
    368         "conscrypt",
    369         "junit",
    370         "mockito-target-minus-junit4",
    371     ],
    372     system_modules: "core-all-system-modules",
    373 
    374     static_libs: [
    375         "bouncycastle-unbundled",
    376         "bouncycastle-bcpkix-unbundled",
    377         "bouncycastle-ocsp-unbundled",
    378     ],
    379     javacflags: [
    380         "-Xmaxwarns 9999999",
    381         //"-Xlint:all",
    382         //"-Xlint:-serial,-deprecation,-unchecked",
    383     ],
    384 
    385     required: ["libjavacrypto"],
    386     java_version: "1.7",
    387 }
    388 
    389 // Make the conscrypt-benchmarks library.
    390 java_test {
    391     name: "conscrypt-benchmarks",
    392     srcs: [
    393         "repackaged/testing/src/main/java/**/*.java",
    394         "repackaged/benchmark-base/src/main/java/**/*.java",
    395         "repackaged/benchmark-android/src/main/java/**/*.java",
    396     ],
    397     no_standard_libs: true,
    398     libs: [
    399         "core-all",
    400         "conscrypt",
    401         "junit",
    402         "bouncycastle-unbundled",
    403         "bouncycastle-bcpkix-unbundled",
    404         "bouncycastle-ocsp-unbundled",
    405         "caliper-api-target",
    406     ],
    407     system_modules: "core-all-system-modules",
    408 
    409     javacflags: [
    410         "-Xmaxwarns 9999999",
    411         //"-Xlint:all",
    412         //"-Xlint:-serial,-deprecation,-unchecked",
    413     ],
    414 
    415     required: ["libjavacrypto"],
    416     java_version: "1.7",
    417 }
    418