Skip to content

Commit

Permalink
Merge "Merge cherrypicks of [2086355, 2086356, 2043295, 2094905, 2101…
Browse files Browse the repository at this point in the history
…534, 2101916, 2112126, 2133534, 2132760, 2134712, 2136926, 2136927, 2136928, 2136929, 2136930, 2136931] into ndk-r25-release." into ndk-r25-release
  • Loading branch information
Android Build Coastguard Worker authored and Gerrit Code Review committed Jun 27, 2022
2 parents 9693f65 + 3b5809b commit 49760b5
Show file tree
Hide file tree
Showing 26 changed files with 281 additions and 40 deletions.
1 change: 1 addition & 0 deletions build/cmake/android-legacy.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ if(ANDROID_PLATFORM_LEVEL LESS 30)
endif()

list(APPEND ANDROID_LINKER_FLAGS -Wl,--fatal-warnings)
list(APPEND ANDROID_LINKER_FLAGS -Wl,--gc-sections)
list(APPEND ANDROID_LINKER_FLAGS_EXE -Wl,--gc-sections)

# Debug and release flags.
Expand Down
1 change: 1 addition & 0 deletions build/cmake/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if(CMAKE_SYSTEM_VERSION LESS 30)
endif()

string(APPEND _ANDROID_NDK_INIT_LDFLAGS " -Wl,--fatal-warnings")
string(APPEND _ANDROID_NDK_INIT_LDFLAGS " -Wl,--gc-sections")
string(APPEND _ANDROID_NDK_INIT_LDFLAGS_EXE " -Wl,--gc-sections")

# Toolchain and ABI specific flags.
Expand Down
1 change: 1 addition & 0 deletions build/core/default-build-commands.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ TARGET_DISABLE_FORMAT_STRING_CFLAGS := -Wno-error=format-security

define cmd-build-shared-library
$(PRIVATE_CXX) \
-Wl,--gc-sections \
-Wl,-soname,$(notdir $(LOCAL_BUILT_MODULE)) \
-shared \
$(PRIVATE_LINKER_OBJECTS_AND_LIBRARIES) \
Expand Down
3 changes: 2 additions & 1 deletion build/dump_compile_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import json
import os

from shlex import join

def get_argument_parser() -> argparse.ArgumentParser:
"""Parses and returns command line arguments."""
Expand Down Expand Up @@ -71,7 +72,7 @@ def main() -> None:
if not args.command_file and not args.compile_command:
parser.error('Either --command-file or COMPILE_COMMAND is required.')

command = ' '.join(args.compile_command)
command = join(args.compile_command)
if args.command_file:
with open(args.command_file) as command_file:
command = command_file.read().strip()
Expand Down
14 changes: 8 additions & 6 deletions build/tools/make_standalone_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ def make_clang_scripts(install_dir, arch, api, windows):
with open(clang_path, 'w') as clang:
clang.write(textwrap.dedent("""\
#!/bin/bash
bin_dir=`dirname "$0"`
if [ "$1" != "-cc1" ]; then
`dirname $0`/clang{version} {flags} "$@"
"$bin_dir/clang{version}" {flags} "$@"
else
# target/triple already spelled out.
`dirname $0`/clang{version} "$@"
"$bin_dir/clang{version}" "$@"
fi
""".format(version=version_number, flags=flags)))

Expand All @@ -155,11 +156,12 @@ def make_clang_scripts(install_dir, arch, api, windows):
with open(clangpp_path, 'w') as clangpp:
clangpp.write(textwrap.dedent("""\
#!/bin/bash
bin_dir=`dirname "$0"`
if [ "$1" != "-cc1" ]; then
`dirname $0`/clang{version}++ {flags} "$@"
"$bin_dir/clang{version}++" {flags} "$@"
else
# target/triple already spelled out.
`dirname $0`/clang{version}++ "$@"
"$bin_dir/clang{version}++" "$@"
fi
""".format(version=version_number, flags=cxx_flags)))

Expand All @@ -181,13 +183,13 @@ def make_clang_scripts(install_dir, arch, api, windows):
call :find_bin
if "%1" == "-cc1" goto :L
set "_BIN_DIR=" && %_BIN_DIR%{exe} {flags} %*
set "_BIN_DIR=" && "%_BIN_DIR%{exe}" {flags} %*
if ERRORLEVEL 1 exit /b 1
goto :done
:L
rem target/triple already spelled out.
set "_BIN_DIR=" && %_BIN_DIR%{exe} %*
set "_BIN_DIR=" && "%_BIN_DIR%{exe}" %*
if ERRORLEVEL 1 exit /b 1
goto :done
Expand Down
28 changes: 14 additions & 14 deletions docs/BuildSystemMaintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ otherwise. Using `clang++` ensures that the C++ standard library is linked.

### Target Selection

[Cross-compilation] targets can be selected in one of two ways.
[Cross-compilation] targets can be selected in one of two ways: by using
the `--target` flag, or by using target-specific wrapper scripts.

First, the `--target` flag can be used (see the [Clang User Manual] for more
details on Clang's supported arguments). The value passed is a Clang target
If possible, we recommend using the `--target` flag, which is described more
fully in the [Clang User Manual]. The value passed is a Clang target
triple suffixed with an Android API level. For example, to target API 26 for
32-bit ARM, use `--target armv7a-linux-androideabi26`.

Expand All @@ -179,18 +180,17 @@ for Clang to generate ARMv7 code rather than the slower ARMv5 code. Specifying
ARMv5 and thumb code generation will result in Thumb-1 being generated rather
than Thumb-2, which is less efficient.

Second, a target-specific Clang can be used. In addition to the `clang` and
`clang++` binaries, there are also `<triple><API-level>-clang` and
`<triple><API-level>-clang++` scripts. For example, to target API 26 32-bit ARM,
If not possible to use the `--target` flag, we supply wrapper scripts alongside
the `clang` and `clang++` binaries, named `<triple><API-level>-clang` and
`<triple><API-level>-clang++`. For example, to target API 26 32-bit ARM,
invoke `armv7a-linux-androideabi26-clang` or
`armv7a-linux-androideabi26-clang++` instead of `clang` or `clang++`.

Note: Target specific Clangs are currently implemented as shell scripts. Linux
and Mac NDKs have Bash scripts, Windows includes Bash scripts to support Cygwin
and WSL but also batch scripts (with `.cmd` extensions) for Windows command
line support. For large numbers of relatively small source files, the additional
overhead caused by these scripts may be noticably slower than using `--target`,
especially on Windows where `CreateProcess` is slower than `fork`.
`armv7a-linux-androideabi26-clang++` instead of `clang` or `clang++`. These
wrappers come in two forms: Bash scripts (for Mac, Linux, Cygwin, and WSL) and
Windows batch files (with `.cmd` extensions).

Note: For projects with many source files, the wrapper scripts may cause
noticeable overhead, which is why we recommend using `--target`. The overhead
is most significant on Windows, as `CreateProcess` is slower than `fork`.

For more information on Android targets, see the [Architectures] and [OS
Versions] sections.
Expand Down
15 changes: 13 additions & 2 deletions docs/changelogs/Changelog-r25.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@ directly, see the [build system maintainers guide].

[GitHub]: https://github.com/android/ndk/issues
[Android Studio site]: http://tools.android.com/filing-bugs
[build system maintainers]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
[build system maintainers guide]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md

## Changes

* Includes Android-T (Tiramisu) Beta 1 APIs.
* Includes Android 13 Beta 2 APIs.
* Updated LLVM to clang-r450784d, based on LLVM 14 development.
* Eliminate duplicate static libraries in API-versioned sysroot directories.
This reduces the uncompressed size of the NDK by 500 MB.
* Strip some binaries and libraries. This reduces the uncompressed size of
the NDK by 300 MB.
* Remove python2. All scripts now use python3.
* [Issue 933]: Updated reference ASan wrap.sh to support attaching the Java
debugger.
* [Issue 1334]: Improved argument escaping for compile_commands.json files
generated by ndk-build.
* [Issue 1634]: Fixed the build rule for the libshaderc_combined target.
* [Issue 1693]: The NDK's toolchain file for CMake (`android.toolchain.cmake`)
defaults to the legacy toolchain file for all versions of CMake. The new
toolchain file can still be enabled using
`-DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF`.
* [Issue 1717]: Arranged for --gc-sections to be passed to the linker when
building shared libraries.

[Issue 933]: https://github.com/android/ndk/issues/933
[Issue 1334]: https://github.com/android/ndk/issues/1334
[Issue 1634]: https://github.com/android/ndk/issues/1634
[Issue 1693]: https://github.com/android/ndk/issues/1693
[Issue 1717]: https://github.com/android/ndk/issues/1717

## Known Issues

Expand Down
23 changes: 17 additions & 6 deletions ndk/checkbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,11 +1389,12 @@ def write_clang_shell_script(
textwrap.dedent(
"""\
#!/bin/bash
bin_dir=`dirname "$0"`
if [ "$1" != "-cc1" ]; then
`dirname $0`/{clang} {flags} "$@"
"$bin_dir/{clang}" {flags} "$@"
else
# Target is already an argument.
`dirname $0`/{clang} "$@"
"$bin_dir/{clang}" "$@"
fi
""".format(
clang=clang_name, flags=" ".join(flags)
Expand All @@ -1417,13 +1418,13 @@ def write_clang_batch_script(
call :find_bin
if "%1" == "-cc1" goto :L
set "_BIN_DIR=" && %_BIN_DIR%{clang} {flags} %*
set "_BIN_DIR=" && "%_BIN_DIR%{clang}" {flags} %*
if ERRORLEVEL 1 exit /b 1
goto :done
:L
rem Target is already an argument.
set "_BIN_DIR=" && %_BIN_DIR%{clang} %*
set "_BIN_DIR=" && "%_BIN_DIR%{clang}" %*
if ERRORLEVEL 1 exit /b 1
goto :done
Expand Down Expand Up @@ -2353,6 +2354,15 @@ def parse_args() -> Tuple[argparse.Namespace, List[str]]:
help="Increase logging verbosity.",
)

parser.add_argument(
"--permissive-python-environment",
action="store_true",
help=(
"Disable strict Python path checking. This allows using a non-prebuilt "
"Python when one is not available."
),
)

parser.add_argument(
"-j",
"--jobs",
Expand Down Expand Up @@ -2649,9 +2659,10 @@ def main() -> None:
total_timer = ndk.timer.Timer()
total_timer.start()

ensure_python_environment()

args, module_names = parse_args()

ensure_python_environment(args.permissive_python_environment)

if args.verbosity >= 2:
logging.basicConfig(level=logging.DEBUG)
elif args.verbosity == 1:
Expand Down
16 changes: 12 additions & 4 deletions ndk/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ def exe_suffix(self) -> str:
@classmethod
def current(cls) -> Host:
"""Returns the Host matching the current machine."""
if sys.platform in ("linux", "linux2"):
# Mypy is rather picky about how these are written. `startswith` and `==` work
# fine, but `in` behaves differently. The pattern here comes straight from the
# mypy docs, so better work.
# https://mypy.readthedocs.io/en/stable/common_issues.html#version-and-platform-checks
#
# But of course pylint thinks we *shouldn't* do that...
# pylint: disable=no-else-return
if sys.platform == "linux":
return Host.Linux
if sys.platform == "darwin":
elif sys.platform == "darwin":
return Host.Darwin
if sys.platform == "win32":
elif sys.platform == "win32":
return Host.Windows64
raise RuntimeError(f"Unsupported host: {sys.platform}")
else:
raise RuntimeError(f"Unsupported host: {sys.platform}")

@classmethod
def from_tag(cls, tag: str) -> Host:
Expand Down
5 changes: 3 additions & 2 deletions ndk/pythonenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def purge_user_site_packages() -> None:
sys.path = [p for p in sys.path if p != site.getusersitepackages()]


def ensure_python_environment() -> None:
def ensure_python_environment(permissive_path: bool) -> None:
"""Verifies that the current Python environment is what we expect."""
check_python_is_prebuilt()
if not permissive_path:
check_python_is_prebuilt()
ensure_poetry_if_available()
purge_user_site_packages()
19 changes: 15 additions & 4 deletions ndk/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ def push_tests_to_device(
dest_dir,
)
device.push(str(src_dir), str(dest_dir), sync=use_sync)
if sys.platform == "win32":
device.shell(["chmod", "-R", "777", str(dest_dir)])
# Tests that were built and bundled on Windows but pushed from Linux or macOS will
# not have execute permission by default. Since we don't know where the tests came
# from, chmod all the tests regardless.
device.shell(["chmod", "-R", "777", str(dest_dir)])


def finish_workqueue_with_ui(workqueue: WorkQueue) -> None:
Expand Down Expand Up @@ -391,6 +393,15 @@ def ExistingFileArg(path: str) -> Path:
raise argparse.ArgumentTypeError("{} is not a file".format(path))
return expanded_path.resolve(strict=True)

parser.add_argument(
"--permissive-python-environment",
action="store_true",
help=(
"Disable strict Python path checking. This allows using a non-prebuilt "
"Python when one is not available."
),
)

config_options = parser.add_argument_group("Test Configuration Options")
config_options.add_argument(
"--filter", help="Only run tests that match the given pattern."
Expand Down Expand Up @@ -712,10 +723,10 @@ def run_tests(args: argparse.Namespace) -> Results:


def main() -> None:
ensure_python_environment()

args = parse_args()

ensure_python_environment(args.permissive_python_environment)

log_levels = [logging.WARNING, logging.INFO, logging.DEBUG]
verbosity = min(args.verbose, len(log_levels) - 1)
log_level = log_levels[verbosity]
Expand Down
3 changes: 3 additions & 0 deletions sources/android/cpufeatures/Android.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This library is provided only for legacy support. For a maintained library,
# migrate to https://github.com/google/cpu_features.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
Expand Down
4 changes: 4 additions & 0 deletions sources/android/cpufeatures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cpufeatures

This library is provided only for legacy support. For a maintained library,
migrate to https://github.com/google/cpu_features.
5 changes: 5 additions & 0 deletions sources/android/cpufeatures/cpu-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
* SUCH DAMAGE.
*/

/*
* This library is provided only for legacy support. For a maintained library,
* migrate to https://github.com/google/cpu_features.
*/

/* ChangeLog for this library:
*
* NDK r10e?: Add MIPS MSA feature.
Expand Down
5 changes: 5 additions & 0 deletions sources/android/cpufeatures/cpu-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

#pragma once

/*
* This library is provided only for legacy support. For a maintained library,
* migrate to https://github.com/google/cpu_features.
*/

#include <sys/cdefs.h>
#include <stdint.h>

Expand Down
22 changes: 22 additions & 0 deletions tests/build/cmake_exports/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.22)
project(CMakeExportsTest C CXX)

if(NOT DEFINED CMAKE_C_COMPILER)
message(FATAL_ERROR "CMAKE_C_COMPILER not set")
endif()

if(NOT DEFINED CMAKE_CXX_COMPILER)
message(FATAL_ERROR "CMAKE_CXX_COMPILER not set")
endif()

if(NOT DEFINED CMAKE_AR)
message(FATAL_ERROR "CMAKE_AR not set")
endif()

if(NOT DEFINED CMAKE_STRIP)
message(FATAL_ERROR "CMAKE_STRIP not set")
endif()

if(NOT DEFINED CMAKE_RANLIB)
message(FATAL_ERROR "CMAKE_RANLIB not set")
endif()
4 changes: 4 additions & 0 deletions tests/build/gc_sections/project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.22.1)
project("--gc-sections test")

add_library(foo SHARED jni/foo.cpp)
6 changes: 6 additions & 0 deletions tests/build/gc_sections/project/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo.cpp
include $(BUILD_SHARED_LIBRARY)
1 change: 1 addition & 0 deletions tests/build/gc_sections/project/jni/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void foo() {}
Loading

0 comments on commit 49760b5

Please sign in to comment.