Skip to content

Commit 283051a

Browse files
zijiehe-google-comCommit Queue
authored and
Commit Queue
committed
Revert "[Fuchsia] Remove the legacy gn build rules for fuchsia"
This reverts commit 094202b. Reason for revert: Break flutter, this change should happen after flutter being migrated to the same gn-sdk. Original change's description: > [Fuchsia] Remove the legacy gn build rules for fuchsia > > The updated test-scripts contains https://crrev.com/c/5341620 which > allows to generate fidl apis with an env var controlled location > rather than a hard-coded one. So the existing fuchsia gn build rules > in dart/sdk become obsolete and can be fully removed in favor of the > one in //third_party/fuchsia/gn-sdk/. > > Meanwhile the gn-sdk has been updated with > https://crrev.com/c/5325282 to use api-level version'ed idk but not > the ones in arch/. > > Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try > Tested: ^^^^^ > Bug: 40935282 > Change-Id: I2ce958e6db1ff8221beef7b7ff953c32bb4525ba > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355283 > Reviewed-by: Ryan Macnak <[email protected]> > Reviewed-by: Alexander Thomas <[email protected]> > Commit-Queue: Zijie He <[email protected]> Bug: 40935282 Change-Id: I7c455d1d362210523671c97d99ef018ede1743f4 Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356307 Bot-Commit: Rubber Stamper <[email protected]> Auto-Submit: Zijie He <[email protected]> Reviewed-by: Derek Xu <[email protected]> Commit-Queue: Zijie He <[email protected]>
1 parent f60d321 commit 283051a

File tree

14 files changed

+770
-82
lines changed

14 files changed

+770
-82
lines changed

DEPS

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ Var("dart_root") + "/third_party/pkg/tar":
700700
"packages": [
701701
{
702702
"package": "chromium/fuchsia/test-scripts",
703-
"version": "EAdD2YcYwVrhF2q_zR6xUvPkcKlPb1tJyM_6_oOc84kC",
703+
"version": "version:2@49064713a73ae92d8c28164938b97869afd336aa",
704704
}
705705
],
706706
"condition": 'download_fuchsia_deps',
@@ -711,7 +711,7 @@ Var("dart_root") + "/third_party/pkg/tar":
711711
"packages": [
712712
{
713713
"package": "chromium/fuchsia/gn-sdk",
714-
"version": "RgErspyYHapUO2SpcW-vo2p8yaRUMUrq0eWjRVPfQjoC",
714+
"version": "version:2@7f1f23fce153ca079a77492d9d47d803d60b774e",
715715
}
716716
],
717717
"condition": 'download_fuchsia_deps',
@@ -836,16 +836,6 @@ hooks = [
836836
Var('emsdk_ver')],
837837
'condition': 'download_emscripten'
838838
},
839-
{
840-
'name': 'Erase arch/ from fuchsia sdk',
841-
'pattern': '.',
842-
'action': [
843-
'rm',
844-
'-rf',
845-
'sdk/third_party/fuchsia/sdk/linux/arch',
846-
],
847-
'condition': 'download_fuchsia_deps'
848-
},
849839
{
850840
'name': 'Download Fuchsia system images',
851841
'pattern': '.',
@@ -857,14 +847,4 @@ hooks = [
857847
],
858848
'condition': 'download_fuchsia_deps'
859849
},
860-
{
861-
'name': 'Generate Fuchsia GN build rules',
862-
'pattern': '.',
863-
'action': [
864-
'python3',
865-
'sdk/build/fuchsia/with_envs.py',
866-
'sdk/third_party/fuchsia/test_scripts/gen_build_defs.py',
867-
],
868-
'condition': 'download_fuchsia_deps'
869-
},
870850
]

build/config/BUILDCONFIG.gn

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ if (is_win) {
257257
"//build/config/win:winver",
258258
]
259259
if (is_clang) {
260-
_native_compiler_configs += [ "//build/config/win:relative_paths" ]
260+
_native_compiler_configs += [
261+
"//build/config/win:relative_paths",
262+
]
261263
}
262264
}
263265
if (is_posix) {
@@ -268,8 +270,8 @@ if (is_posix) {
268270
}
269271
if (is_fuchsia) {
270272
_native_compiler_configs += [
271-
"//third_party/fuchsia/gn-sdk/src/config:compiler",
272-
"//third_party/fuchsia/gn-sdk/src/config:runtime_library",
273+
"//build/config/fuchsia:compiler",
274+
"//build/config/fuchsia:runtime_library",
273275
]
274276
}
275277

@@ -448,8 +450,8 @@ foreach(_target_type,
448450
}
449451
if (is_fuchsia) {
450452
deps += [
453+
"//build/config/fuchsia:runtime_library_group",
451454
"//build/fuchsia/config/clang:c++-runtime-deps",
452-
"//third_party/fuchsia/gn-sdk/src/config:runtime_library_group",
453455
]
454456
}
455457
}

build/config/fuchsia/BUILD.gn

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright 2019 The Fuchsia Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//build/config/fuchsia/gn_configs.gni")
6+
7+
config("compiler") {
8+
sdk_version = "${fuchsia_sdk_id}"
9+
defines = [
10+
# To force full builds after SDK updates in case of ABI changes.
11+
"FUCHSIA_SDK_VERSION=$sdk_version",
12+
]
13+
cflags = []
14+
ldflags = []
15+
if (current_cpu == "arm64") {
16+
cflags += [ "--target=aarch64-fuchsia" ]
17+
} else if (current_cpu == "x64") {
18+
cflags += [ "--target=x86_64-fuchsia" ]
19+
} else {
20+
assert(false, "Unsupported architecture")
21+
}
22+
23+
# Pass the target API level to the compiler if specified.
24+
if (fuchsia_target_api_level != -1) {
25+
cflags += [ "-ffuchsia-api-level=${fuchsia_target_api_level}" ]
26+
}
27+
28+
# Add libfdio by default. This may change in future versions
29+
# in order to move away from POSIX applications and towards
30+
# the Fuchsia programming model.
31+
ldflags += [
32+
# We always want fdio or else e.g. stdio wouldn't be initialized if fdio
33+
# happens to not be directly referenced. The common POSIX-y compiler setup
34+
# uses -Wl,--as-needed which drops it if it's simply "-lfdio" from a libs
35+
# setting. Disable --as-needed, add fdio, and then set back to --as-needed.
36+
"-Wl,--no-as-needed",
37+
"-lfdio",
38+
"-Wl,--as-needed",
39+
]
40+
41+
lib_dirs = [ "${fuchsia_sdk}/arch/${current_cpu}/lib" ]
42+
43+
libs = [ "zircon" ]
44+
45+
ldflags += cflags
46+
asmflags = cflags
47+
}
48+
49+
# This should be applied to all targets.
50+
config("runtime_library") {
51+
asmflags = []
52+
cflags = []
53+
cflags_c = []
54+
cflags_cc = []
55+
cflags_objc = []
56+
cflags_objcc = []
57+
defines = []
58+
ldflags = []
59+
60+
sysroot = "${fuchsia_sdk}/arch/$current_cpu/sysroot"
61+
62+
# Pass the sysroot to all C compiler variants, the assembler, and linker.
63+
cflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
64+
ldflags = cflags
65+
asmflags = cflags
66+
}
67+
68+
# Copy the loader to place it at the expected path in the final package.
69+
copy("sysroot_dist_libs") {
70+
sources = [ "${fuchsia_sdk}/arch/${target_cpu}/sysroot/dist/lib/ld.so.1" ]
71+
outputs = [ "${root_out_dir}/lib/{{source_file_part}}" ]
72+
}
73+
74+
# This adds the runtime deps for //build/config/compiler:runtime_library
75+
# as that is a config target and thus cannot include data_deps.
76+
group("runtime_library_group") {
77+
data_deps = [
78+
":sysroot_dist_libs",
79+
80+
# This is used directly from //build/config/fuchsia:compiler and thus
81+
# also needs to be included by default.
82+
# "${fuchsia_sdk}/pkg/fdio",
83+
]
84+
}
85+
86+
config("sdk_lib_dirs_config") {
87+
visibility = [ "${fuchsia_sdk}/*" ]
88+
lib_dirs = [ "arch/${target_cpu}/lib" ]
89+
}

build/fuchsia/fidl/BUILD.gn

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
assert(is_fuchsia)
6+
import("//build/fuchsia/sdk.gni")
7+
8+
fuchsia_sdk("fidl") {
9+
meta = "$fuchsia_sdk_path/meta/manifest.json"
10+
enabled_parts = [ "fidl_library" ]
11+
}

build/fuchsia/fidl_gen_cpp.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2013 The Flutter Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
""" Generate C/C++ headers and source files from the set of FIDL files specified
8+
in the meta.json manifest.
9+
"""
10+
11+
12+
import argparse
13+
import collections
14+
import json
15+
import os
16+
import subprocess
17+
import sys
18+
19+
def GetFIDLFilesRecursive(libraries, sdk_base, path):
20+
with open(path) as json_file:
21+
parsed = json.load(json_file)
22+
result = []
23+
deps = parsed['deps']
24+
for dep in deps:
25+
dep_meta_json = os.path.abspath('%s/fidl/%s/meta.json' % (sdk_base, dep))
26+
GetFIDLFilesRecursive(libraries, sdk_base, dep_meta_json)
27+
libraries[parsed['name']] = result + parsed['sources']
28+
29+
def GetFIDLFilesByLibraryName(sdk_base, root):
30+
libraries = collections.OrderedDict()
31+
GetFIDLFilesRecursive(libraries, sdk_base, root)
32+
return libraries
33+
34+
def main():
35+
parser = argparse.ArgumentParser();
36+
37+
parser.add_argument('--fidlc-bin', dest='fidlc_bin', action='store', required=True)
38+
parser.add_argument('--fidlgen-bin', dest='fidlgen_bin', action='append', required=False)
39+
40+
parser.add_argument('--sdk-base', dest='sdk_base', action='store', required=True)
41+
parser.add_argument('--root', dest='root', action='store', required=True)
42+
parser.add_argument('--json', dest='json', action='store', required=True)
43+
parser.add_argument('--fidlgen-output-root', dest='fidlgen_output_root', action='store', required=False)
44+
parser.add_argument('--target-api-level', dest='target_api_level', action='store', required=False)
45+
46+
args = parser.parse_args()
47+
48+
assert os.path.exists(args.fidlc_bin)
49+
50+
fidl_files_by_name = GetFIDLFilesByLibraryName(args.sdk_base, args.root)
51+
52+
fidlc_command = [
53+
args.fidlc_bin,
54+
'--json',
55+
args.json
56+
]
57+
58+
if args.target_api_level:
59+
fidlc_command += [
60+
'--available',
61+
'fuchsia:{api_level}'.format(api_level=args.target_api_level),
62+
]
63+
64+
# Create an iterator that works on both python3 and python2
65+
try:
66+
fidl_files_by_name_iter = list(fidl_files_by_name.items())
67+
except AttributeError:
68+
fidl_files_by_name_iter = iter(fidl_files_by_name.items())
69+
70+
for _, fidl_files in fidl_files_by_name_iter:
71+
fidlc_command.append('--files')
72+
for fidl_file in fidl_files:
73+
fidl_abspath = os.path.abspath('%s/%s' % (args.sdk_base, fidl_file))
74+
fidlc_command.append(fidl_abspath)
75+
76+
subprocess.check_call(fidlc_command)
77+
78+
if args.fidlgen_output_root:
79+
assert os.path.exists(args.json)
80+
for fidlgen_bin in args.fidlgen_bin:
81+
assert os.path.exists(fidlgen_bin)
82+
83+
fidlgen_command = [
84+
fidlgen_bin,
85+
'-json',
86+
args.json,
87+
'-root',
88+
args.fidlgen_output_root
89+
]
90+
91+
subprocess.check_call(fidlgen_command)
92+
else:
93+
# --fidlgen-bin and --fidlgen-output-root should be passed in together.
94+
assert not args.fidlgen_bin
95+
96+
return 0
97+
98+
if __name__ == '__main__':
99+
sys.exit(main())

build/fuchsia/pkg/BUILD.gn

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
assert(is_fuchsia)
6+
import("//build/fuchsia/sdk.gni")
7+
8+
fuchsia_sdk("pkg") {
9+
meta = "$fuchsia_sdk_path/meta/manifest.json"
10+
enabled_parts = [
11+
"cc_source_library",
12+
"cc_prebuilt_library",
13+
]
14+
}

0 commit comments

Comments
 (0)