Skip to content

Commit

Permalink
Targets to generate macos gen snapshot. (flutter#31950)
Browse files Browse the repository at this point in the history
  • Loading branch information
godofredoc authored Mar 29, 2022
1 parent 54f9795 commit f340b42
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 8 deletions.
37 changes: 35 additions & 2 deletions build/archives/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import("//flutter/build/zip_bundle.gni")
import("//flutter/sky/tools/macos_snapshots.gni")

zip_bundle("artifacts") {
output = "$full_platform_name/artifacts.zip"
deps = [
"//flutter/flutter_frontend_server:frontend_server",
"//flutter/lib/snapshot:generate_snapshot_bin",
"//flutter/shell/testing:testing",
]
prefix = "$full_platform_name/"
if (flutter_runtime_mode != "debug") {
prefix = "$full_platform_name-$flutter_runtime_mode/"
}
output = "$prefix/artifacts.zip"
files = [
{
source = "//third_party/icu/flutter/icudtl.dat"
Expand Down Expand Up @@ -78,7 +83,8 @@ zip_bundle("flutter_patched_sdk") {
if (build_engine_artifacts && flutter_prebuilt_dart_sdk) {
copy("dart_sdk_archive") {
sources = [ prebuilt_dart_sdk_archive ]
outputs = [ "$root_out_dir/zip_archives/dart-sdk-$full_platform_name.zip" ]
outputs =
[ "$root_out_dir/zip_archives/dart-sdk-$full_target_platform_name.zip" ]
}
}

Expand Down Expand Up @@ -134,4 +140,31 @@ if (is_mac) {
"//flutter/shell/platform/darwin/macos:macos_flutter_framework_archive",
]
}

macos_gen_snapshots("create_macos_gen_snapshots") {
visibility = [ ":*" ]
deps = [ "//flutter/lib/snapshot:generate_snapshot_bins" ]
arch = "$target_cpu"
}

zip_bundle("archive_gen_snapshot") {
deps = [ ":create_macos_gen_snapshots" ]
suffix = "-$flutter_runtime_mode"
if (flutter_runtime_mode == "debug") {
suffix = ""
}
output = "$full_platform_name$suffix/gen_snapshot.zip"
files = [
{
source = "$root_out_dir/gen_snapshot_$target_cpu"
destination = "gen_snapshot_$target_cpu"
},
]
}

group("flutter_embedder_framework") {
deps = [
"//flutter/shell/platform/embedder:flutter_embedder_framework_archive",
]
}
}
10 changes: 10 additions & 0 deletions common/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ if (_platform_name == "mac") {

full_platform_name = "$_platform_name-$host_cpu"

_platform_target_name = target_os
if (_platform_target_name == "mac") {
_platform_target_name = "darwin"
} else if (_platform_target_name == "win" ||
_platform_target_name == "winuwp") {
_platform_target_name = "windows"
}

full_target_platform_name = "$_platform_target_name-$target_cpu"

# Prebuilt Dart SDK location

if (flutter_prebuilt_dart_sdk) {
Expand Down
14 changes: 9 additions & 5 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -323,26 +323,30 @@ if (build_glfw_shell) {
}

zip_bundle("zip_macos_flutter_framework") {
output = "FlutterMacOS.framework.zip"
visibility = [ ":*" ]
deps = [ ":_generate_symlinks" ]
output = "tmp/FlutterMacOS.framework.zip"
visibility = [ ":*" ]
files = [
{
source = "$root_out_dir/FlutterMacOS.framework"
destination = "FlutterMacOS.framework.zip"
destination = "FlutterMacOS.framework"
},
]
}

zip_bundle("macos_flutter_framework_archive") {
output = "$full_platform_name/FlutterMacOS.framework.zip"
deps = [
":copy_framework_podspec",
":zip_macos_flutter_framework",
]
prefix = "$full_platform_name-$flutter_runtime_mode/"
if (flutter_runtime_mode == "debug") {
prefix = "$full_platform_name/"
}
output = "${prefix}FlutterMacOS.framework.zip"
files = [
{
source = "$root_out_dir/zip_archives/FlutterMacOS.framework.zip"
source = "$root_out_dir/zip_archives/tmp/FlutterMacOS.framework.zip"
destination = "FlutterMacOS.framework.zip"
},
{
Expand Down
33 changes: 32 additions & 1 deletion shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,13 @@ if (is_mac && !embedder_for_target) {
action("generate_symlinks") {
visibility = [ ":*" ]
script = "//build/config/mac/package_framework.py"
outputs = [ "$root_build_dir/FlutterEmbedder.stamp" ]
outputs = [
"$root_build_dir/FlutterEmbedder.stamp",
_flutter_embedder_framework_dir,
"$_flutter_embedder_framework_dir/Resources",
"$_flutter_embedder_framework_dir/Headers",
"$_flutter_embedder_framework_dir/Modules",
]
args = [
"--framework",
"FlutterEmbedder.framework",
Expand Down Expand Up @@ -428,6 +434,31 @@ group("flutter_engine") {
}
}

if (is_mac) {
zip_bundle("flutter_embedder_framework_archive") {
deps = [ ":generate_symlinks" ]
output = "$full_platform_name/FlutterEmbedder.framework.zip"
files = [
{
source = "$root_out_dir/FlutterEmbedder.framework"
destination = "FlutterEmbedder.framework"
},
{
source = "$root_out_dir/FlutterEmbedder.framework/Resources"
destination = "FlutterEmbedder.framework/Resources"
},
{
source = "$root_out_dir/FlutterEmbedder.framework/Headers"
destination = "FlutterEmbedder.framework/Headers"
},
{
source = "$root_out_dir/FlutterEmbedder.framework/Modules"
destination = "FlutterEmbedder.framework/Modules"
},
]
}
}

if (host_os == "linux" || host_os == "win") {
zip_bundle("embedder-archive") {
output = "$full_platform_name/$full_platform_name-embedder.zip"
Expand Down
47 changes: 47 additions & 0 deletions sky/tools/gen_snapshots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import argparse
import subprocess
import sys
import os


def main():
parser = argparse.ArgumentParser(
description='Copies architecture-dependent gen_snapshot binaries to output dir'
)

parser.add_argument('--dst', type=str, required=True)
parser.add_argument('--out-dir', type=str)
parser.add_argument('--arch', type=str)

args = parser.parse_args()

subdir = ''
if args.arch != 'x64':
subdir = 'clang_x64'

generate_gen_snapshot(
os.path.join(args.out_dir, subdir),
os.path.join(args.dst, 'gen_snapshot_%s' % args.arch)
)


def generate_gen_snapshot(directory, destination):
gen_snapshot_dir = os.path.join(directory, 'gen_snapshot')
if not os.path.isfile(gen_snapshot_dir):
print('Cannot find gen_snapshot at %s' % gen_snapshot_dir)
sys.exit(1)

subprocess.check_call(
['xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination]
)


if __name__ == '__main__':
sys.exit(main())

45 changes: 45 additions & 0 deletions sky/tools/macos_snapshots.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//flutter/common/config.gni")

# Generates macos gen snapshots $root_build_dir/zip_archives folder.
#

# The output variable specifies the name of the zip file to create.
# The files variable is an array of scopes that specify a source file or
# directory and a destination path in the archive to create.
#
# For example, to create a zip file named archive.zip with all files in the
# root directory of the archive:
#
# zip_bundle("sample") {
# output = "archive.zip"
# files = [
# {
# source = "$root_build_dir/some/path/to/lib.so"
# destination = "lib.so"
# },
# {
# source = "$root_build_dir/some/other/path/with/files"
# destination = "other_files"
# },
# ]
# }
template("macos_gen_snapshots") {
action(target_name) {
forward_variables_from(invoker, [ "visibility" ])
deps = invoker.deps
outputs = [ "$root_build_dir/gen_snapshot_${invoker.arch}" ]
script = "//flutter/sky/tools/gen_snapshots.py"
args = [
"--dst",
rebase_path("$root_out_dir/"),
"--out-dir",
rebase_path("$root_out_dir"),
"--arch",
invoker.arch,
]
}
}

0 comments on commit f340b42

Please sign in to comment.