Skip to content

Commit

Permalink
clean up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
freedomtan committed Oct 5, 2021
1 parent 4186b32 commit 76bbb84
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static String createCcToolchainRule(
NdkPaths.stripRepositoryPrefix(toolchain.getBuiltinSysroot()) + "/**/*";

List<String> toolchainFileGlobPatterns = new ArrayList<>();
// toolchainFileGlobPatterns.add(androidPlatformIncludes);
toolchainFileGlobPatterns.add(androidPlatformIncludes);

for (String cxxFlag : toolchain.getUnfilteredCxxFlagList()) {
if (!cxxFlag.startsWith("-")) { // Skip flag names
Expand All @@ -200,16 +200,7 @@ private static String createCcToolchainRule(
}

// For NDK 15 and up. Unfortunately, the toolchain does not encode the NDK revision number.
// toolchainFileGlobPatterns.add("ndk/sysroot/**/*");

// For NDK 22 and up. Unfortunately, it's in clang
// toolchainFileGlobPatterns.add("ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/incude/**/*");

// test
// String hostPlatform = AndroidNdkCrosstools.getHostPlatform(31);
// toolchainFileGlobPatterns.add("ndk/toolchains/llvm/prebuilt/" + hostPlatform + "/lib64/clang/12.0.5/include/**/*");
toolchainFileGlobPatterns.add("ndk/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/12.0.5/include/**/*");
toolchainFileGlobPatterns.add("ndk/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/12.0.5/include/**/*");
toolchainFileGlobPatterns.add("ndk/sysroot/**/*");

// If this is a clang toolchain, also add the corresponding gcc toolchain to the globs.
int gccToolchainIndex = toolchain.getCompilerFlagList().indexOf("-gcc-toolchain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ toolchain(

filegroup(
name = "%toolchainName%-all_files",
#srcs = glob(["ndk/toolchains/%toolchainDirectory%/**"]) + glob([
srcs = glob([
srcs = glob(["ndk/toolchains/%toolchainDirectory%/**"]) + glob([
%toolchainFileGlobs%
]) + [
":%dynamicRuntimeLibs%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private AndroidNdkCrosstools() {}
.put(19, new NdkMajorRevisionR19("8.0.2"))
.put(20, new NdkMajorRevisionR20("8.0.7"))
.put(21, new NdkMajorRevisionR21("9.0.8"))
.put(22, new NdkMajorRevisionR21("11.0.5"))
.put(23, new NdkMajorRevisionR23("12.0.5"))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ImmutableList<ToolPath> createToolpaths(String toolchainName, String targ
if (!Arrays.asList(excludedTools).contains(tool)) {

String toolPath = createToolPath(toolchainName, targetPlatform + "-" + tool.getNamePart());
if (tool.getNamePart() == "ar") {
if ((toolchainName == "llvm") && (tool.getNamePart() == "ar")) {
toolPath = createToolPath(toolchainName, "llvm-" + tool.getNamePart());
}

Expand Down Expand Up @@ -206,11 +206,6 @@ public String createBuiltinSysroot() {
// This location does not exist prior to NDK 15
Preconditions.checkState(majorRevision >= 15);

StackTraceElement[] elements = Thread.currentThread().getStackTrace();
for (int i = 1; i < elements.length; i++) {
StackTraceElement s = elements[i];
}

return "%externalExecPathBase%/%repositoryName%/ndk/sysroot"
.replace("%externalExecPathBase%", externalExecPathBase)
.replace("%repositoryName%", repositoryName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ protected static Iterable<String> createIncludeFlags(Iterable<String> includePat
includeFlags.add("-isystem");
includeFlags.add(includePath);
}
/*
includeFlags.add("-isystem");
includeFlags.add("toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/12.0.5/include");
includeFlags.add("-isystem");
includeFlags.add("external/androidndk/ndk/toolchains/llvm/prebuilt/include");
*/
return includeFlags.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void addStlImpl(CToolchain.Builder toolchain, @Nullable String gccVersion
addBaseStlImpl(toolchain, null);
toolchain.addAllUnfilteredCxxFlag(createIncludeFlags(ndkPaths.createLibcxxIncludePaths()));
toolchain.addLinkerFlag("-L" + ndkPaths.createLibcppLinkerPath(toolchain.getTargetCpu()));
}
}
}

public static class StlPortStlImpl extends StlImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ private static ImmutableList<CToolchain> createToolchains(
// builtin_sysroot is set individually on each toolchain.
// platforms/arch sysroot
toolchainBuilder.addCxxBuiltinIncludeDirectory("%sysroot%/usr/include");
/*
toolchainBuilder.addCxxBuiltinIncludeDirectory(
ndkPaths.createBuiltinSysroot() + "/usr/include");
toolchainBuilder.addUnfilteredCxxFlag(
"-isystem%ndk%/usr/include".replace("%ndk%", ndkPaths.createBuiltinSysroot()));
*/

toolchains.add(toolchainBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 The Bazel Authors. All rights reserved.
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,16 +50,10 @@ ImmutableList<CToolchain.Builder> createCrosstools() {
}

private CToolchain.Builder createAarch64ClangToolchain() {
// String toolchainName = "aarch64-linux-android-4.9";
String toolchainName = "llvm";
String targetPlatform = "aarch64-none-linux-android";
// String gccToolchain = ndkPaths.createGccToolchainPath(toolchainName);
// String clangToolchain = ndkPaths.createClangToolchainPath(toolchainName);
String llvmTriple = "aarch64-none-linux-android" + ndkPaths.getCorrectedApiLevel("arm");

System.out.println("sysroot: " + ndkPaths.createClangBuiltinSysroot());
// System.out.println("clang tool:" + ndkPaths.createClangToolpaths(toolchainName, targetPlatform, null));

return CToolchain.newBuilder()
.setToolchainIdentifier("aarch64-linux-android-clang" + clangVersion)
.setTargetSystemName(targetPlatform)
Expand All @@ -69,32 +63,12 @@ private CToolchain.Builder createAarch64ClangToolchain() {
.addCxxBuiltinIncludeDirectory(
ndkPaths.createClangToolchainBuiltinIncludeDirectory(clangVersion))
.setBuiltinSysroot(ndkPaths.createClangBuiltinSysroot())
// .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("arm64"))
// .setBuiltinSysroot("external/androidndk/ndk/sysroot")

// Compiler flags
// .addCompilerFlag("-gcc-toolchain")
// .addCompilerFlag(gccToolchain)
.addCompilerFlag("-target")
.addCompilerFlag(llvmTriple)
.addCompilerFlag("-fpic")
/*
.addCompilerFlag("-isystemexternal/androidndk/ndk/sources/cxx-stl/llvm-libc++/include")
.addCompilerFlag("-isystemexternal/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include")
.addCompilerFlag("-isystemexternal/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/linux")
.addCompilerFlag("-isystemexternal/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android")
.addCompilerFlag("-isystemexternal/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/12.0.5/include")*/
/*
.addCompilerFlag(
"-isystem%ndk%/usr/include/%triple%"
.replace("%ndk%", ndkPaths.createBuiltinSysroot())
.replace("%triple%", targetPlatform))
*/
// .addCompilerFlag("-D__ANDROID_API__=" + ndkPaths.getCorrectedApiLevel("arm"))

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

Expand All @@ -119,7 +93,8 @@ private CToolchain.Builder createArmeabiClangToolchain() {
// String toolchainName = "arm-linux-androideabi-4.9";
String toolchainName = "llvm";
String targetPlatform = "arm-linux-androideabi";
String gccToolchain = ndkPaths.createGccToolchainPath("arm-linux-androideabi-4.9");
// String gccToolchain = ndkPaths.createGccToolchainPath("arm-linux-androideabi-4.9");
String llvmTriple = "arm-none-linux-android" + ndkPaths.getCorrectedApiLevel("arm");

return CToolchain.newBuilder()
.setToolchainIdentifier("arm-linux-androideabi-clang" + clangVersion + "-v7a")
Expand All @@ -130,33 +105,21 @@ private CToolchain.Builder createArmeabiClangToolchain() {
.addCxxBuiltinIncludeDirectory(
ndkPaths.createClangToolchainBuiltinIncludeDirectory(clangVersion))
.setBuiltinSysroot(ndkPaths.createClangBuiltinSysroot())
// .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("arm"))
.addCompilerFlag("-D__ANDROID_API__=" + ndkPaths.getCorrectedApiLevel("arm"))
/*
.addCompilerFlag(
"-isystem%ndk%/usr/include/%triple%"
.replace("%ndk%", ndkPaths.createBuiltinSysroot())
.replace("%triple%", targetPlatform))
*/

// Compiler flags
.addCompilerFlag("-target")
.addCompilerFlag("armv7-none-linux-androideabi") // LLVM_TRIPLE
.addCompilerFlag(llvmTriple)
.addCompilerFlag("-march=armv7-a")
.addCompilerFlag("-mfloat-abi=softfp")
// "32-bit ARM targets should use -mfpu=vfpv3-d16 when compiling unless using NEON. This
// allows the compiler to make use of the FPU."
// https://android.googlesource.com/platform/ndk/+/ndk-release-r19/docs/BuildSystemMaintainers.md#additional-required-arguments
.addCompilerFlag("-mfpu=vfpv3-d16")
// .addCompilerFlag("-gcc-toolchain")
// .addCompilerFlag(gccToolchain)
.addCompilerFlag("-fpic")

// Linker flags
.addLinkerFlag("-target")
.addLinkerFlag("armv7-none-linux-androideabi") // LLVM_TRIPLE
// .addLinkerFlag("-gcc-toolchain")
// .addLinkerFlag(gccToolchain)
.addLinkerFlag(llvmTriple)

// Additional release flags
.addCompilationModeFlags(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ final class X86Crosstools {
}

ImmutableList<CToolchain.Builder> createCrosstools() {
String targetPlatform = "x86-none-linux-android";
/** x86 */
// clang
CToolchain.Builder x86Clang =
Expand All @@ -45,21 +46,18 @@ ImmutableList<CToolchain.Builder> createCrosstools() {
.addCompilerFlag("-mstackrealign")
.setToolchainIdentifier("x86-clang" + clangVersion)
.setTargetCpu("x86")
.addAllToolPath(ndkPaths.createClangToolpaths("x86-4.9", "i686-linux-android", null))
.addAllToolPath(ndkPaths.createClangToolpaths("llvm", "x86-none-linux-android", null))
.setBuiltinSysroot(ndkPaths.createClangBuiltinSysroot());
// .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("x86"));

stlImpl.addStlImpl(x86Clang, null);

/** x86_64 */
CToolchain.Builder x8664Clang =
createBaseX86ClangToolchain("x86_64", "x86_64", "x86_64-linux-android")
.setToolchainIdentifier("x86_64-clang" + clangVersion)
.setTargetCpu("x86_64")
.addAllToolPath(
ndkPaths.createClangToolpaths("x86_64-4.9", "x86_64-linux-android", null))
.setToolchainIdentifier("x86_64-clang" + clangVersion)
.addAllToolPath(ndkPaths.createClangToolpaths("llvm", "x86_64-none-linux-android", null))
.setBuiltinSysroot(ndkPaths.createClangBuiltinSysroot());
// .setBuiltinSysroot(ndkPaths.createBuiltinSysroot("x86_64"));

stlImpl.addStlImpl(x8664Clang, null);

Expand All @@ -69,7 +67,7 @@ ImmutableList<CToolchain.Builder> createCrosstools() {
private CToolchain.Builder createBaseX86ClangToolchain(
String x86Arch, String llvmArch, String triple) {
String gccToolchain = ndkPaths.createGccToolchainPath(x86Arch + "-4.9");
String llvmTriple = llvmArch + "-none-linux-android";
String llvmTriple = llvmArch + "-none-linux-android" + ndkPaths.getCorrectedApiLevel("x86");

CToolchain.Builder cToolchainBuilder = CToolchain.newBuilder();

Expand All @@ -79,22 +77,12 @@ private CToolchain.Builder createBaseX86ClangToolchain(
ndkPaths.createClangToolchainBuiltinIncludeDirectory(clangVersion))

// Compiler flags
.addCompilerFlag("-gcc-toolchain")
.addCompilerFlag(gccToolchain)
.addCompilerFlag("-target")
.addCompilerFlag(llvmTriple)
.addCompilerFlag("-fPIC")
/*
.addCompilerFlag(
"-isystem%ndk%/usr/include/%triple%"
.replace("%ndk%", ndkPaths.createBuiltinSysroot())
.replace("%triple%", triple))
*/
.addCompilerFlag("-D__ANDROID_API__=" + ndkPaths.getCorrectedApiLevel(x86Arch))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable

private static final PathFragment BUILD_PATH_FRAGMENT = PathFragment.create("BUILD");

private static final boolean VALIDATION_DEBUG_WARN = true;
private static final boolean VALIDATION_DEBUG_WARN = false;

@VisibleForTesting public static final String CPP_COMPILE_MNEMONIC = "CppCompile";
@VisibleForTesting public static final String OBJC_COMPILE_MNEMONIC = "ObjcCompile";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ private void reallyGlob(Path base, boolean baseIsDir, int idx, GlobTaskContext c
} else {
processFileOrDirectory(child, childType == Dirent.Type.DIRECTORY, idx, context);
}
}
}
}
}

Expand Down

0 comments on commit 76bbb84

Please sign in to comment.