/**
   * Constructs the feature configuration from a {@code CToolchain} protocol buffer.
   *
   * @param toolchain the toolchain configuration as specified by the user.
   * @throws InvalidConfigurationException if the configuration has logical errors.
   */
  CcToolchainFeatures(CToolchain toolchain) throws InvalidConfigurationException {
    // Build up the feature graph.
    // First, we build up the map of name -> features in one pass, so that earlier features can
    // reference later features in their configuration.
    ImmutableList.Builder<Feature> features = ImmutableList.builder();
    HashMap<String, Feature> featuresByName = new HashMap<>();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      Feature feature = new Feature(toolchainFeature);
      features.add(feature);
      if (featuresByName.put(feature.getName(), feature) != null) {
        throw new InvalidConfigurationException(
            "Invalid toolchain configuration: feature '"
                + feature.getName()
                + "' was specified multiple times.");
      }
    }
    this.features = features.build();
    this.featuresByName = ImmutableMap.copyOf(featuresByName);

    // Next, we build up all forward references for 'implies' and 'requires' edges.
    ImmutableMultimap.Builder<Feature, Feature> implies = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, ImmutableSet<Feature>> requires =
        ImmutableMultimap.builder();
    // We also store the reverse 'implied by' and 'required by' edges during this pass.
    ImmutableMultimap.Builder<Feature, Feature> impliedBy = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, Feature> requiredBy = ImmutableMultimap.builder();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      String name = toolchainFeature.getName();
      Feature feature = featuresByName.get(name);
      for (CToolchain.FeatureSet requiredFeatures : toolchainFeature.getRequiresList()) {
        ImmutableSet.Builder<Feature> allOf = ImmutableSet.builder();
        for (String requiredName : requiredFeatures.getFeatureList()) {
          Feature required = getFeatureOrFail(requiredName, name);
          allOf.add(required);
          requiredBy.put(required, feature);
        }
        requires.put(feature, allOf.build());
      }
      for (String impliedName : toolchainFeature.getImpliesList()) {
        Feature implied = getFeatureOrFail(impliedName, name);
        impliedBy.put(implied, feature);
        implies.put(feature, implied);
      }
    }
    this.implies = implies.build();
    this.requires = requires.build();
    this.impliedBy = impliedBy.build();
    this.requiredBy = requiredBy.build();
  }
Exemple #2
0
  private CToolchain.Builder createAarch64Toolchain() {

    String toolchainName = "aarch64-linux-android-4.9";
    String targetPlatform = "aarch64-linux-android";

    CToolchain.Builder toolchain =
        CToolchain.newBuilder()
            .setToolchainIdentifier("aarch64-linux-android-4.9")
            .setTargetSystemName("aarch64-linux-android")
            .setTargetCpu("arm64-v8a")
            .setCompiler("gcc-4.9")
            .addAllToolPath(ndkPaths.createToolpaths(toolchainName, targetPlatform))
            .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("arm64"))

            // Compiler flags
            .addCompilerFlag("-fpic")
            .addCompilerFlag("-ffunction-sections")
            .addCompilerFlag("-funwind-tables")
            .addCompilerFlag("-fstack-protector-strong")
            .addCompilerFlag("-no-canonical-prefixes")
            .addCompilerFlag("-fno-canonical-system-headers")

            // Linker flags
            .addLinkerFlag("-no-canonical-prefixes")

            // Additional release flags
            .addCompilationModeFlags(
                CompilationModeFlags.newBuilder()
                    .setMode(CompilationMode.OPT)
                    .addCompilerFlag("-O2")
                    .addCompilerFlag("-g")
                    .addCompilerFlag("-DNDEBUG")
                    .addCompilerFlag("-fomit-frame-pointer")
                    .addCompilerFlag("-fstrict-aliasing")
                    .addCompilerFlag("-funswitch-loops")
                    .addCompilerFlag("-finline-limit=300"))

            // Additional debug flags
            .addCompilationModeFlags(
                CompilationModeFlags.newBuilder()
                    .setMode(CompilationMode.DBG)
                    .addCompilerFlag("-O0")
                    .addCompilerFlag("-UNDEBUG")
                    .addCompilerFlag("-fno-omit-frame-pointer")
                    .addCompilerFlag("-fno-strict-aliasing"));

    ndkPaths.addToolchainIncludePaths(toolchain, toolchainName, targetPlatform, "4.9");
    stlImpl.addStlImpl(toolchain, "4.9");
    return toolchain;
  }
Exemple #3
0
  /** Flags common to arm-linux-androideabi* */
  private CToolchain.Builder createBaseArmeabiToolchain(
      boolean thumb,
      String gccVersion,
      String stackProtectorFlag,
      CppConfiguration.Tool... excludedTools) {

    String toolchainName = "arm-linux-androideabi-" + gccVersion;
    String targetPlatform = "arm-linux-androideabi";

    CToolchain.Builder toolchain =
        CToolchain.newBuilder()
            .setTargetSystemName(targetPlatform)
            .setCompiler("gcc-" + gccVersion)
            .addAllToolPath(ndkPaths.createToolpaths(toolchainName, targetPlatform, excludedTools))
            .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("arm"))
            .addCompilerFlag(stackProtectorFlag)

            // Compiler flags
            .addCompilerFlag("-fpic")
            .addCompilerFlag("-ffunction-sections")
            .addCompilerFlag("-funwind-tables")
            .addCompilerFlag("-no-canonical-prefixes")
            .addCompilerFlag("-fno-canonical-system-headers")

            // Linker flags
            .addLinkerFlag("-no-canonical-prefixes");

    if (thumb) {
      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.OPT)
              .addCompilerFlag("-mthumb")
              .addCompilerFlag("-Os")
              .addCompilerFlag("-g")
              .addCompilerFlag("-DNDEBUG")
              .addCompilerFlag("-fomit-frame-pointer")
              .addCompilerFlag("-fno-strict-aliasing")
              .addCompilerFlag("-finline-limit=64"));

      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.DBG)
              .addCompilerFlag("-g")
              .addCompilerFlag("-fno-strict-aliasing")
              .addCompilerFlag("-finline-limit=64")
              .addCompilerFlag("-O0")
              .addCompilerFlag("-UNDEBUG")
              .addCompilerFlag("-marm")
              .addCompilerFlag("-fno-omit-frame-pointer"));
    } else {
      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.OPT)
              .addCompilerFlag("-O2")
              .addCompilerFlag("-g")
              .addCompilerFlag("-DNDEBUG")
              .addCompilerFlag("-fomit-frame-pointer")
              .addCompilerFlag("-fstrict-aliasing")
              .addCompilerFlag("-funswitch-loops")
              .addCompilerFlag("-finline-limit=300"));

      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.DBG)
              .addCompilerFlag("-g")
              .addCompilerFlag("-funswitch-loops")
              .addCompilerFlag("-finline-limit=300")
              .addCompilerFlag("-O0")
              .addCompilerFlag("-UNDEBUG")
              .addCompilerFlag("-fno-omit-frame-pointer")
              .addCompilerFlag("-fno-strict-aliasing"));
    }

    ndkPaths.addToolchainIncludePaths(toolchain, toolchainName, targetPlatform, gccVersion);
    return toolchain;
  }
Exemple #4
0
  private CToolchain.Builder createBaseArmeabiClangToolchain(String clangVersion, boolean thumb) {

    String toolchainName = "arm-linux-androideabi-4.8";
    String targetPlatform = "arm-linux-androideabi";
    String gccToolchain = ndkPaths.createGccToolchainPath("arm-linux-androideabi-4.8");

    CToolchain.Builder toolchain =
        CToolchain.newBuilder()
            .setTargetSystemName("arm-linux-androideabi")
            .setCompiler("clang" + clangVersion)
            .addAllToolPath(
                ndkPaths.createClangToolpaths(
                    toolchainName,
                    targetPlatform,
                    clangVersion,
                    // gcc-4.8 arm doesn't have gcov-tool
                    CppConfiguration.Tool.GCOVTOOL))
            .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("arm"))

            // Compiler flags
            .addCompilerFlag("-gcc-toolchain")
            .addCompilerFlag(gccToolchain)
            .addCompilerFlag("-fpic")
            .addCompilerFlag("-ffunction-sections")
            .addCompilerFlag("-funwind-tables")
            .addCompilerFlag("-fstack-protector-strong")
            .addCompilerFlag("-Wno-invalid-command-line-argument")
            .addCompilerFlag("-Wno-unused-command-line-argument")
            .addCompilerFlag("-no-canonical-prefixes")
            .addCompilerFlag("-fno-canonical-system-headers")
            .addCompilerFlag("-fno-integrated-as")

            // Linker flags
            .addLinkerFlag("-gcc-toolchain")
            .addLinkerFlag(gccToolchain)
            .addLinkerFlag("-no-canonical-prefixes");

    if (thumb) {
      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.OPT)
              .addCompilerFlag("-mthumb")
              .addCompilerFlag("-Os")
              .addCompilerFlag("-g")
              .addCompilerFlag("-DNDEBUG")
              .addCompilerFlag("-fomit-frame-pointer")
              .addCompilerFlag("-fno-strict-aliasing"));

      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.DBG)
              .addCompilerFlag("-g")
              .addCompilerFlag("-fno-strict-aliasing")
              .addCompilerFlag("-O0")
              .addCompilerFlag("-UNDEBUG")
              .addCompilerFlag("-marm")
              .addCompilerFlag("-fno-omit-frame-pointer"));
    } else {
      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.OPT)
              .addCompilerFlag("-O2")
              .addCompilerFlag("-g")
              .addCompilerFlag("-DNDEBUG")
              .addCompilerFlag("-fomit-frame-pointer")
              .addCompilerFlag("-fstrict-aliasing"));

      toolchain.addCompilationModeFlags(
          CompilationModeFlags.newBuilder()
              .setMode(CompilationMode.DBG)
              .addCompilerFlag("-g")
              .addCompilerFlag("-O0")
              .addCompilerFlag("-UNDEBUG")
              .addCompilerFlag("-fno-omit-frame-pointer")
              .addCompilerFlag("-fno-strict-aliasing"));
    }

    ndkPaths.addToolchainIncludePaths(toolchain, toolchainName, targetPlatform, "4.8");
    return toolchain;
  }
Exemple #5
0
  private CToolchain.Builder createAarch64ClangToolchain(String clangVersion) {

    String toolchainName = "aarch64-linux-android-4.9";
    String targetPlatform = "aarch64-linux-android";
    String gccToolchain = ndkPaths.createGccToolchainPath(toolchainName);
    String llvmTriple = "aarch64-none-linux-android";

    CToolchain.Builder toolchain =
        CToolchain.newBuilder()
            .setToolchainIdentifier("aarch64-linux-android-clang" + clangVersion)
            .setTargetSystemName("aarch64-linux-android")
            .setTargetCpu("arm64-v8a")
            .setCompiler("clang" + clangVersion)
            .addAllToolPath(
                ndkPaths.createClangToolpaths(toolchainName, targetPlatform, clangVersion))
            .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("arm64"))

            // Compiler flags
            .addCompilerFlag("-gcc-toolchain")
            .addCompilerFlag(gccToolchain)
            .addCompilerFlag("-target")
            .addCompilerFlag(llvmTriple)
            .addCompilerFlag("-ffunction-sections")
            .addCompilerFlag("-funwind-tables")
            .addCompilerFlag("-fstack-protector-strong")
            .addCompilerFlag("-fpic")
            .addCompilerFlag("-Wno-invalid-command-line-argument")
            .addCompilerFlag("-Wno-unused-command-line-argument")
            .addCompilerFlag("-no-canonical-prefixes")
            .addCompilerFlag("-fno-canonical-system-headers")

            // Linker flags
            .addLinkerFlag("-gcc-toolchain")
            .addLinkerFlag(gccToolchain)
            .addLinkerFlag("-target")
            .addLinkerFlag(llvmTriple)
            .addLinkerFlag("-no-canonical-prefixes")

            // Additional release flags
            .addCompilationModeFlags(
                CompilationModeFlags.newBuilder()
                    .setMode(CompilationMode.OPT)
                    .addCompilerFlag("-O2")
                    .addCompilerFlag("-g")
                    .addCompilerFlag("-DNDEBUG")
                    .addCompilerFlag("-fomit-frame-pointer")
                    .addCompilerFlag("-fstrict-aliasing"))

            // Additional debug flags
            .addCompilationModeFlags(
                CompilationModeFlags.newBuilder()
                    .setMode(CompilationMode.DBG)
                    .addCompilerFlag("-O0")
                    .addCompilerFlag("-UNDEBUG")
                    .addCompilerFlag("-fno-omit-frame-pointer")
                    .addCompilerFlag("-fno-strict-aliasing"));

    ndkPaths.addToolchainIncludePaths(toolchain, toolchainName, targetPlatform, "4.9");
    stlImpl.addStlImpl(toolchain, "4.9");
    return toolchain;
  }