From 34f107bb4121284f5e24bf9d061a2c2ec8f2fb19 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Thu, 13 Apr 2023 20:13:20 -0700 Subject: [PATCH] [Impeller] Fix the cmake example build. (flutter/engine#41148) [Impeller] Fix the cmake example build. --- DEPS | 16 +++++++ engine/src/flutter/.ci.yaml | 3 +- .../builders/mac_impeller_cmake_example.json | 36 ++++++--------- .../flutter/ci/impeller_cmake_build_test.py | 44 +++++++------------ engine/src/flutter/tools/gn | 39 ++++++++++++++++ 5 files changed, 86 insertions(+), 52 deletions(-) diff --git a/DEPS b/DEPS index 2e449cdd15..7eaf29ce69 100644 --- a/DEPS +++ b/DEPS @@ -100,6 +100,10 @@ vars = { # Setup Git hooks by default. "setup_githooks": True, + # This is not downloaded be default because it increases the + # `gclient sync` time by between 1 and 3 minutes. This option is enabled + # in flutter/ci/builders/mac_impeller_cmake_example.json, and is likely to + # only be useful locally when reproducing issues found by the bot. 'download_impeller_cmake_example': False, # Upstream URLs for third party dependencies, used in @@ -853,6 +857,18 @@ deps = { 'url': Var('github_git') + '/bdero/impeller-cmake-example.git' + '@' + '4d728722ac1559f59db28a3ef061fe929d6be4c6', 'condition': 'download_impeller_cmake_example', }, + + # cmake is only used by impeller-cmake-example. + 'src/buildtools/mac-x64/cmake': { + 'packages': [ + { + 'package': 'infra/3pp/tools/cmake/mac-amd64', + 'version': 'CGpMvZoP962wdEINR9d4OEvEW7ZOv0MPrHNKbBUBS0sC', + } + ], + 'condition': 'download_impeller_cmake_example and host_os == "mac"', + 'dep_type': 'cipd', + } } recursedeps = [ diff --git a/engine/src/flutter/.ci.yaml b/engine/src/flutter/.ci.yaml index c89b7890e8..20ad33cac9 100644 --- a/engine/src/flutter/.ci.yaml +++ b/engine/src/flutter/.ci.yaml @@ -450,12 +450,11 @@ targets: timeout: 60 properties: release_build: "true" - config_name: impeller_cmake_build_test + config_name: mac_impeller_cmake_example $flutter/osx_sdk : >- { "sdk_version": "14a5294e" } dependencies: >- [ - {"dependency": "cmake", "version": "build_id:8784715802296535313"}, {"dependency": "jazzy", "version": "0.14.1"} ] diff --git a/engine/src/flutter/ci/builders/mac_impeller_cmake_example.json b/engine/src/flutter/ci/builders/mac_impeller_cmake_example.json index 7c16ab9462..8986c1a360 100644 --- a/engine/src/flutter/ci/builders/mac_impeller_cmake_example.json +++ b/engine/src/flutter/ci/builders/mac_impeller_cmake_example.json @@ -1,37 +1,27 @@ { "builds": [ { - "name": "impeller_cmake_build_test", + "name": "impeller-cmake-example", "archives": [], "drone_dimensions": [ "device_type=none", "os=Mac-12", - "cpu=x86" + "cpu=arm64" ], - "gclient_custom_vars": { + "gclient_variables": { "download_android_deps": false, "download_impeller_cmake_example": true }, - "tests": [ - { - "language": "python3", - "name": "cmake", - "script": "flutter/ci/impeller_cmake_build_test.py", - "parameters": [ - "--cmake" - ], - "type": "local" - }, - { - "language": "python3", - "name": "build", - "script": "flutter/ci/impeller_cmake_build_test.py", - "parameters": [ - "--build" - ], - "type": "local" - } - ] + "gn": [ + "--impeller-cmake-example", + "--xcode-symlinks" + ], + "ninja": { + "config": "impeller-cmake-example", + "targets": [ + ] + }, + "tests": [] } ], "tests": [] diff --git a/engine/src/flutter/ci/impeller_cmake_build_test.py b/engine/src/flutter/ci/impeller_cmake_build_test.py index 17946c63ff..fbc718e8cd 100644 --- a/engine/src/flutter/ci/impeller_cmake_build_test.py +++ b/engine/src/flutter/ci/impeller_cmake_build_test.py @@ -8,6 +8,13 @@ import os import subprocess import sys +# When passed the --setup flag, this script fetches git submodules and other +# dependencies for the impeller-cmake-example. When passed the --cmake flag, +# this script runs cmake on impeller-cmake-example. That will create +# a build output directory for impeller-cmake-example under +# out/impeller-cmake-example, so the build can then be performed with +# e.g. ninja -C out/impeller-cmake-example-out. + SRC_ROOT = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ) @@ -17,13 +24,6 @@ def parse_args(argv): parser = argparse.ArgumentParser( description='A script that tests the impeller-cmake-example build.', ) - parser.add_argument( - '--build', - '-b', - default=False, - action='store_true', - help='Perform the build for impeller-cmake-example.', - ) parser.add_argument( '--cmake', '-c', @@ -62,7 +62,7 @@ def parse_args(argv): help='Emit verbose output.', ) parser.add_argument( - '--xcode-symlink', + '--xcode-symlinks', default=False, action='store_true', help='Symlink the Xcode sysroot to help Goma be successful.', @@ -91,10 +91,7 @@ def create_xcode_symlink(): os.path.join(SRC_ROOT, 'out', 'impeller-cmake-example-xcode-sysroot'), ] find_sdk_output = subprocess.check_output(find_sdk_command).decode('utf-8') - print(find_sdk_output) - sysroot_path = find_sdk_output.split('\n')[0] - print('sysroot path = {}'.format(sysroot_path)) - return sysroot_path + return find_sdk_output.split('\n')[0] def main(argv): @@ -105,7 +102,6 @@ def main(argv): impeller_cmake_dir = os.path.join(SRC_ROOT, args.path) if args.setup: - print('git submodule update with {} jobs'.format(str(os.cpu_count()))) git_command = [ 'git', '-C', @@ -114,7 +110,6 @@ def main(argv): 'update', '--init', '--recursive', - # '--single-branch', '--depth', '1', '--jobs', @@ -127,35 +122,30 @@ def main(argv): return 0 if args.cmake: + cmake_path = os.path.join( + SRC_ROOT, 'buildtools', 'mac-x64', 'cmake', 'bin', 'cmake' + ) cmake_command = [ - 'cmake', + cmake_path, '--preset', 'flutter-ci-mac-debug-x64', '-B', - os.path.join(SRC_ROOT, 'out', 'impeller-cmake-example-out'), + os.path.join(SRC_ROOT, 'out', 'impeller-cmake-example'), ] cmake_env = os.environ.copy() + ninja_path = os.path.join(SRC_ROOT, 'flutter', 'third_party', 'ninja') cmake_env.update({ + 'PATH': os.environ['PATH'] + ':' + ninja_path, 'FLUTTER_ENGINE_SRC_DIR': SRC_ROOT, 'FLUTTER_GOMA_DIR': args.goma_dir, }) - if args.xcode_symlink: + if args.xcode_symlinks: xcode_symlink_path = create_xcode_symlink() cmake_env.update({ 'FLUTTER_OSX_SYSROOT': xcode_symlink_path, }) subprocess.check_call(cmake_command, env=cmake_env, cwd=impeller_cmake_dir) - if args.build: - ninja_command = [ - 'ninja', - '-C', - os.path.join(SRC_ROOT, 'out', 'impeller-cmake-example-out'), - '-j', - '200', - ] - subprocess.check_call(ninja_command) - return 0 diff --git a/engine/src/flutter/tools/gn b/engine/src/flutter/tools/gn index 64ac90f9b5..9dfc5bcad6 100755 --- a/engine/src/flutter/tools/gn +++ b/engine/src/flutter/tools/gn @@ -672,6 +672,35 @@ def to_gn_wasm_args(args, gn_args): gn_args['flutter_prebuilt_dart_sdk'] = True +def run_impeller_cmake(args): + impeller_cmake_dir = os.path.join('third_party', 'impeller-cmake-example') + if not os.path.isdir(os.path.join(SRC_ROOT, impeller_cmake_dir)): + print( + 'The Impeller cmake example directory "{}" does not exist' + .format(impeller_cmake_dir) + ) + return 1 + goma_gn_args = setup_goma(args) + goma_dir = goma_gn_args['goma_dir'] + cmake_cmd = [ + 'python3', + os.path.join(SRC_ROOT, 'flutter', 'ci', 'impeller_cmake_build_test.py'), + '--path', + impeller_cmake_dir, + '--cmake', + ] + if goma_dir is not None: + cmake_cmd = cmake_cmd + ['--goma-dir', goma_dir] + if args.xcode_symlinks: + cmake_cmd = cmake_cmd + ['--xcode-symlinks'] + try: + cmake_call_result = subprocess.call(cmake_cmd, cwd=SRC_ROOT) + except subprocess.CalledProcessError as exc: + print('Failed to generate cmake files: ', exc.returncode, exc.output) + return 1 + return cmake_call_result + + def parse_args(args): args = args[1:] parser = argparse.ArgumentParser(description='A script to run `gn gen`.') @@ -1032,6 +1061,13 @@ def parse_args(args): '--malioc-path', type=str, help='The path to the malioc tool.' ) + parser.add_argument( + '--impeller-cmake-example', + default=False, + action='store_true', + help='Do not run GN. Instead configure the Impeller cmake example build.', + ) + # Sanitizers. parser.add_argument('--asan', default=False, action='store_true') parser.add_argument('--lsan', default=False, action='store_true') @@ -1084,6 +1120,9 @@ def main(argv): args = parse_args(argv) validate_args(args) + if args.impeller_cmake_example: + return run_impeller_cmake(args) + exe = '.exe' if sys.platform.startswith(('cygwin', 'win')) else '' command = [