gn编译webrtc介绍
时间:2022-09-11 15:30:00
说明:因为需要通过gn编译webrtc在此介绍源代码和自研代码的添加gn命令和格式。
概述:我们通过gclient实现webrtc下载源代码后使用gn此时,生成相应平台的文件(.ninja)。
gn参考:https://www.chromium.org/developers/gn-build-configuration
gn介绍:(generate ninja )顾名思义就是生成ninja文件是编译工具GYP(Generate Your Project)替代工具,由google开源c 实现编写,主要实现交叉编译,可指定输出平台目标和多个目标平台。
gn gen out/Default --args='target_os="linux" target_cpu="x64"
既然是解释器,就会有相应的语法。windows以平台为例.gn语法介绍。
BUILD.gn截取一段文件分析如下:
1:首先import.gni该文件通常定义为公共功能。
2.编译器将找到相应的目标进行编译。目标的意思是我们的模块需要编译什么,如静态库、动态库或操作程序。只有指定的目标编译器才能生成。主要类型如下:
executable:生成exe程序。group:包含多个目标虚拟节点。shared_library:生成静态库lib或.a。loadable_module:动态库或者.so。source_set:轻量级静态库(常用)。app:用于mac/ios。android_apk:生成andorid平台apk.
3:依赖每个目标deps包括。此时将涉及路径问题,当地相同路径的开头为冒号:。如果是根目录,则为//开头。
4:通过一些变量gn的args传递。
# Copyright (c) 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # This is the root build file for GN. GN will start processing by loading this # file, and recursively load all dependencies until all dependencies are either # resolved or known not to exist (which will cause the build to fail). So if # you add a new build file, there must be some path of dependencies from this # file to your new one or GN won't know about it. import("//build/config/compiler/compiler.gni") ... if (is_android) { import("//build/config/android/config.gni") } # This file defines the following two main targets: # # "gn_all" is used to create explicit dependencies from the root BUILD.gn to # each top-level component that we wish to include when building everything via # "all". This is required since the set of targets built by "all" is determined # automatically based on reachability from the root BUILD.gn (for details, see # crbug.com/503241). Builders should typically use "all", or list targets # explicitly, rather than relying on "gn_all". # # "gn_visibility": targets that are normally not visible to top-level targets, # but are built anyway by "all". Since we don't want any such targets, we have # this placeholder to make sure hidden targets that aren't otherwise depended # on yet are accounted for. group("gn_all") { testonly = true deps = [ ":gn_visibility", "//base:base_perftests", "//base:base_unittests", "//base/util:base_util_unittests", "//chrome/installer", "//chrome/updater", "//components:components_unittests", "//components/gwp_asan:gwp_asan_unittests", "//net:net_unittests", "//services:services_unittests", "//services/service_manager/public/cpp", "//skia:skia_unittests", "//sql:sql_unittests", "//third_party/flatbuffers:flatbuffers_unittests", "//tools/binary_size:binary_size_trybot_py", "//tools/ipc_fuzzer:ipc_fuzzer_all", "//tools/metrics:metrics_metadata", "//ui/base:ui_base_unittests", "//ui/color:color_unittests", "//ui/gfx:gfx_unittests", "//url:url_unittests", ] if (!is_component_build) { deps = [ "//third_party/abseil-cpp:absl_tests" ] } if (!is_component_build) { deps = [ "//third_party/abseil-cpp:absl_tests" ] } if (!is_android && !is_chromecast) { deps = [ "//crypto:crypto_unittests", "//google_apis/gcm:gcm_unit_tests", ] } if (enable_js_type_check) { deps = [ ":webui_closure_compile" ] } if (!is_ios && !is_ios && !is_android && !is_chromecast && !is_fuchsia) { deps = [ "//chrome", "//chrome/browser/ui/color:dump_colors", "//chrome/test:browser_tests", "//chrome/test:interactive_ui_tests", "//chrome/test:sync_integration_tests", "//chrome/test/chromedriver:chromedriver_unittests", "//components/subresource_filter/tools:subresource_filter_tools", "//components/zucchini:zucchini", "//components/zucchini:zucchini_unittests", "//gpu/gles2_conform_support:gles2_conform_test", "//gpu/khronos_glcts_support:khronos_glcts_test", "//jingle:jingle_unittests", "//net:hpack_example_generator", "//ppapi:ppapi_unittests", "//ppapi/examples/2d", "//ppapi/examples/audio", "//ppapi/examples/audio_input", "//ppapi/examples/crxfs", "//ppapi/examples/enumerate_devices", "//ppapi/examples/file_chooser", "//ppapi/examples/flash_topmost", "//ppapi/examples/font", "//ppapi/examples/gamepad", "//ppapi/examples/gles2", "//ppapi/examples/gles2_spinning_cube", "//ppapi/examples/ime", "//ppapi/examples/input", "//ppapi/examples/media_stream_audio", "//ppapi/examples/media_stream_video", "//ppapi/examples/mouse_cursor", "//ppapi/examples/mouse_lock", "//ppapi/examples/printing", "//ppapi/examples/scalin",
"//ppapi/examples/scripting",
"//ppapi/examples/stub",
"//ppapi/examples/threading",
"//ppapi/examples/url_loader",
"//ppapi/examples/video_capture",
"//ppapi/examples/video_decode",
"//ppapi/examples/video_encode",
"//printing:printing_unittests",
"//third_party/SPIRV-Tools/src:SPIRV-Tools",
"//third_party/SPIRV-Tools/src/test/fuzzers",
"//third_party/pdfium/samples:pdfium_test",
"//tools/perf/clear_system_cache",
"//tools/polymer:polymer_tools_python_unittests",
"//ui/accessibility:accessibility_perftests",
"//ui/accessibility:accessibility_unittests",
"//ui/accessibility/extensions:extension_tests",
"//ui/accessibility/extensions:extensions",
]
}
if (!is_ios) {
deps += [
"//cc:cc_unittests",
"//components/policy:policy_templates",
"//components/ui_devtools/viz",
"//components/url_formatter/tools:format_url",
"//components/viz:viz_perftests",
"//components/viz:viz_unittests",
"//content/shell:content_shell",
"//content/test:content_browsertests",
"//content/test:content_perftests",
"//content/test:content_unittests",
"//gpu:gpu_benchmark",
"//gpu:gpu_unittests",
"//ipc:ipc_tests",
"//media:media_unittests",
"//media/midi:midi_unittests",
"//media/mojo:media_mojo_unittests",
"//mojo",
"//mojo:mojo_unittests",
"//net:net_perftests",
"//storage:storage_unittests",
"//third_party/angle/src/tests:angle_end2end_tests",
"//third_party/angle/src/tests:angle_unittests",
"//third_party/blink/common:blink_common_unittests",
"//third_party/blink/renderer/controller:blink_unittests",
"//third_party/blink/renderer/platform:blink_platform_unittests",
"//third_party/blink/renderer/platform/heap:blink_heap_unittests",
"//third_party/blink/renderer/platform/wtf:wtf_unittests",
"//tools/imagediff",
"//ui/display:display_unittests",
"//ui/events:events_unittests",
"//ui/gl:gl_unittests",
"//ui/latency:latency_unittests",
"//ui/native_theme:native_theme_unittests",
"//ui/touch_selection:ui_touch_selection_unittests",
"//url/ipc:url_ipc_unittests",
"//v8:gn_all",
]
}
if (is_win || (is_linux && !is_chromeos) || is_android) {
deps += [
"//weblayer/shell:weblayer_shell",
"//weblayer/test:weblayer_browsertests",
"//weblayer/test:weblayer_unittests",
]
if (is_android) {
deps += [ "//weblayer/browser/android/javatests:weblayer_instrumentation_test_apk" ]
}
}
if (!is_ios && !is_android) {
deps += [
"//components/cronet:cronet_tests",
"//components/cronet:cronet_unittests",
"//components/viz/demo:viz_demo",
]
}
if (enable_openscreen) {
deps += [ "//chrome/browser/media/router:openscreen_unittests" ]
}
if (!is_ios && !is_fuchsia) {
deps += [
"//chrome/test:telemetry_perf_unittests",
"//chrome/test:unit_tests",
"//components:components_browsertests",
"//device:device_unittests",
"//google_apis/gcm:mcs_probe",
"//media/capture:capture_unittests",
"//media/cast:cast_unittests",
"//third_party/angle/src/tests:angle_white_box_tests",
"//third_party/catapult/telemetry:bitmaptools($host_toolchain)",
]
} else if (is_ios) {
deps += [
"//ios:all",
"//third_party/crashpad/crashpad:crashpad_tests",
]
} else if (is_fuchsia) {
deps += [
":d8_fuchsia",
"//fuchsia:gn_all",
"//headless:headless_non_renderer",
]
}
deps += root_extra_deps
if (enable_extensions) {
deps += [
"//extensions:extensions_browsertests",
"//extensions:extensions_unittests",
"//extensions/shell:app_shell_unittests",
]
# TODO(crbug.com/981112): This target is failing to compile consistently in
# coverage build, remove this condition when the bug is fixed.
if (!use_clang_coverage) {
deps += [ "//extensions/browser/api/declarative_net_request/filter_list_converter" ]
}
}
if (enable_remoting) {
deps += [ "//remoting:remoting_all" ]
}
if (toolkit_views) {
deps += [
"//ui/views:views_unittests",
"//ui/views/examples:views_examples",
"//ui/views/examples:views_examples_unittests",
"//ui/views/examples:views_examples_with_content",
]
}
if (use_aura) {
deps += [
"//ui/aura:aura_demo",
"//ui/aura:aura_unittests",
"//ui/wm:wm_unittests",
]
}
if (use_ozone) {
deps += [
"//ui/ozone",
"//ui/ozone:ozone_unittests",
"//ui/ozone/demo",
"//ui/ozone/gl:ozone_gl_unittests",
]
if (ozone_platform_x11) {
deps += [ "//ui/ozone:ozone_x11_unittests" ]
}
}
...
比如meida模块中audio的模块BUILD.gn文件中具体某个静态库的编译,可以看出一个模块指定生成静态库后,会将其包含的源文件以及依赖库都进行加载中,其中依赖库包含本地模块的静态库,也包含一些第三方库。不同的类型库不同的加载方式。
source_set("audio") {
sources = [
"agc_audio_stream.h",
"alive_checker.cc",
"alive_checker.h",
"audio_debug_file_writer.cc",
"audio_debug_file_writer.h",
"audio_debug_recording_helper.cc",
"audio_debug_recording_helper.h",
"audio_debug_recording_manager.cc",
"audio_debug_recording_manager.h",
"audio_debug_recording_session.h",
"audio_debug_recording_session_impl.cc",
"audio_debug_recording_session_impl.h",
"audio_device_description.cc",
"audio_device_description.h",
]
if (is_win) {
sources += [
"win/audio_device_listener_win.cc",
"win/audio_device_listener_win.h",
"win/audio_low_latency_input_win.cc",
"win/audio_low_latency_input_win.h",
"win/audio_low_latency_output_win.cc",
"win/audio_low_latency_output_win.h",
"win/audio_manager_win.cc",
"win/audio_manager_win.h",
]
deps += [
":aaudio_stubs",
"//media/base/android:media_jni_headers",
]
libs += [
"dxguid.lib",
"setupapi.lib",
"winmm.lib",
]
所以如果我们需要减少编译生成模块大小,和添加自己实现的模块,都可以通过修改gn文件进行。