日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

WebRTC编译系统之GYP,gn和ninja

發(fā)布時(shí)間:2024/2/28 windows 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WebRTC编译系统之GYP,gn和ninja 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
GN(Generate Ninja)來(lái)生成構(gòu)建腳本,使用 ninja 來(lái)構(gòu)建。 gn 的介紹在這里:https://www.chromium.org/developers/gn-build-configuration 使用 gn 生成 ninja 構(gòu)建文件的常用命令: // 生成 debug 版本的構(gòu)建文件,默認(rèn)配置 gn gen out/Debug // 生成 release 版本的構(gòu)建文件 gn gen out/Release --args="is_debug=false" 注意,通過(guò)?--args?可以傳遞參數(shù)給 gn ,具體參數(shù)的含義,由 WebRTC 的構(gòu)建系統(tǒng)來(lái)解釋。比如 is_debug 選項(xiàng),決定構(gòu)建 debug 還是 release 版本。 如果你已經(jīng)使用 gn gen 生成過(guò)構(gòu)建文件,想看看這個(gè)版本的構(gòu)建文件都指定了什么參數(shù),可以使用下面命令: gn args out/Release --list 它會(huì)列出所有的 build arguments 和對(duì)應(yīng)的文檔,以及當(dāng)前值。
ninja 的官網(wǎng)在這里:https://ninja-build.org/ 后綴為 ninja(*.ninja) 的文件是 ninja 的 構(gòu)建文件。對(duì) WebRTC 來(lái)講,執(zhí)行完 gn gen 之后,會(huì)在 out/Release 下生成 build.ninja 文件,可以把這個(gè)文件看做是整個(gè) WebRTC 的“ Makefile ”。它里面調(diào)用了各個(gè)模塊的 ninja 文件。 要完整編譯 WebRTC ,只要在 src 目錄執(zhí)行下列命令: ninja -C out/Release -C 選項(xiàng)告訴 ninja ,進(jìn)入 out/Release 目錄來(lái)編譯。所以,它等同于: cd out/Release ninja 要編譯某個(gè)模塊,可以在 ninja 命令后跟模塊名字(build.ninja文件中定義的構(gòu)建目標(biāo),就像 Makefile 中的構(gòu)建目標(biāo)一樣)。比如: // 構(gòu)建 webrtc/pc ninja pc // 構(gòu)建 webrtc/media ninja media 看看 gn 用到的項(xiàng)目文件 .gn 、 .gni 和 DEPS ,它們指導(dǎo)了如何生成 ninja 構(gòu)建文件。 如果把 gn 看成一個(gè)編譯系統(tǒng), .gn 就是源文件, .gni 就是頭文件。我們姑且這么理解就好了(其實(shí) gni 里做的事情, gn 都可以做)。DEPS 主要用來(lái)設(shè)定包含路徑。 gn 和 gni 文件都在源碼樹(shù)中,比如 src 目錄。當(dāng)執(zhí)行 gn gen 時(shí),gn 工具根據(jù) gn 和 gni 生成 ninja 文件并將這些 ninja 文件放到指定的構(gòu)建目錄中。 .gn 文件是 GN build 的 “源文件”,在這里可以做各種條件判斷和配置,gn 會(huì)根據(jù)這些配置生成特定的 ninja 文件。 .gn 文件中可以使用預(yù)定義的參數(shù),比如 is_debug , target_os , rtc_use_h264 等。 .gn 中可以 import .gni 文件。 .gn 和 .gni 文件中用到各種指令,都在這里有說(shuō)明:GN Reference import("webrtc/webrtc.gni") group("default") { testonly = true deps = [ "//webrtc", "//webrtc/examples", "//webrtc/tools", ] if (rtc_include_tests) { deps += [ "//webrtc:webrtc_tests" ] } } group 指令聲明了一個(gè) default 目標(biāo),這個(gè)目標(biāo)依賴(lài) webrtc 、 webrtc/examples 和 webrtc/tools ,你可以在 webrtc 、 webrtc/examples 、 webrtc/tools 目錄下找到對(duì)應(yīng)的 BUILD.gn 。你可以把 group 當(dāng)做 VS 的 solution gn 文件中也可以通過(guò) defines 來(lái)定義宏,通過(guò) cflags 來(lái)指定傳遞給編譯器的標(biāo)記,通過(guò) ldflags 指定傳遞給鏈接器的標(biāo)記,還可以使用 sources 指定源文件。下面是 webrtc/BUILD.gn 文件的部分內(nèi)容: if (is_win) { defines += [ "WEBRTC_WIN", "_CRT_SECURE_NO_WARNINGS", # Suppress warnings about _vsnprinf ] } if (is_android) { defines += [ "WEBRTC_LINUX", "WEBRTC_ANDROID", ] } if (is_chromeos) { defines += [ "CHROMEOS" ] } if (rtc_sanitize_coverage != "") { assert(is_clang, "sanitizer coverage requires clang") cflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ] ldflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ] } gni 文件是 GN build 使用的頭文件,它里面可以做各種事情,比如定義變量、宏、定義配置、定義模板等。 webrtc.gni 是一個(gè)比較特殊的 gni 文件,你可以把它看做全局配置文件 webrtc.gni 定義了 WebRTC 項(xiàng)目用到的一些標(biāo)記,比如 rtc_build_libvpx、rtc_build_ssl、rtc_use_h264 等。 還使用 template 語(yǔ)句定義了幾個(gè)模板,比如 rtc_executable 、 rtc_static_library 、 rtc_shared_library ,這幾個(gè)模板定義了生成可執(zhí)行文件、靜態(tài)庫(kù)、動(dòng)態(tài)庫(kù)的規(guī)則。在 webrtc/examples/BUILD.gn 中就有用到這些模板,用它們來(lái)指導(dǎo)如何生成可執(zhí)行文件、靜態(tài)庫(kù)等。 你也可以直接使用 gn 內(nèi)置的 shared_library 和 static_library 來(lái)聲明目標(biāo),比如 third_party/ffmpeg/BUILD.gn 就使用 shared_library 來(lái)生成動(dòng)態(tài)庫(kù)。 DEPS 文件 webrtc/examples/DEPS : include_rules = [ "+WebRTC", "+webrtc/api", "+webrtc/base", "+webrtc/media", "+webrtc/modules/audio_device", "+webrtc/modules/video_capture", "+webrtc/p2p", "+webrtc/pc", ] include_rules 定義了包含路徑。 了解 .gn 和 .gni 文件的目的是修改它們。比如你想打開(kāi) WebRTC 對(duì) H264 的支持,就可以修改 webrtc/webrtc.gni ,直接把 rtc_use_h264 設(shè)置為 true 。 比如你想為某個(gè)模塊加一些文件,就可以修改 .gn 文件,修改 sources 變量,直接把你的源文件加進(jìn)去。 GYP是一個(gè)在不同平臺(tái)構(gòu)建項(xiàng)目的工具,GNGYP的升級(jí)版 GYPGenerate Your Projects的縮寫(xiě),GYP的目的是為了支持更大的項(xiàng)目編譯在不同的平臺(tái),比如MacWindowsLinux,它可以生成Xcode工程,Visual Studio工程,Ninja編譯文件和Mackefiles。 GYP的輸入是.gyp.gypi文件,.gypi文件是用于.gyp文件include使用的。.gyp文件就是符合特定格式的json文件。 gn gen指定在out/目錄里面生成ninja。
1gn gen out
再執(zhí)行ninja來(lái)build code
1ninja -C out

在src目錄有一個(gè).gn的隱藏文件 import("//build/dotfile_settings.gni") # The location of the build configuration file. buildconfig = "//build/config/BUILDCONFIG.gn" # The secondary source root is a parallel directory tree where # GN build files are placed when they can not be placed directly # in the source tree, e.g. for third party source trees. secondary_source = "//build/secondary/" # These are the targets to check headers for by default. The files in targets # matching these patterns (see "gn help label_pattern" for format) will have # their includes checked for proper dependencies when you run either # "gn check" or "gn gen --check". check_targets = [ "//webrtc/*" ] # These are the list of GN files that run exec_script. This whitelist exists # to force additional review for new uses of exec_script, which is strongly # discouraged except for gypi_to_gn calls. exec_script_whitelist = build_dotfile_settings.exec_script_whitelist default_args = { # Webrtc does not support component builds because we are not using the # template "component" but we rely directly on "rtc_static_library" and # "rtc_shared_library". This means that we cannot use the chromium default # value for this argument. # This also means that the user can override this value using --args or # the args.gn file but this setting will be ignored because we don't support # component builds. is_component_build = false } .gn?檔所在的目錄會(huì)被 GN 工具認(rèn)定是 project 的?source root.gn?的內(nèi)容最基本就是用?buildconfig?來(lái)指定 build config 檔的位置,其中?//?開(kāi)頭的字串就是用來(lái)指定相對(duì)於 source root 的路徑。
  • args: Display or configure arguments declared by the build.
  • gen: Generate ninja files.
args命令應(yīng)該是產(chǎn)生args.gn文件的。 gen命令應(yīng)該是根據(jù)args.gn生成ninja文件的。 If specified, arguments from the --args command line flag are used. If that flag is not specified, args from previous builds in the build directory will be used (this is in the file args.gn in the build directory). gn gen out/FooBar --args="enable_doom_melon=true os=\"android\"" This will overwrite the build directory with the given arguments. build flow流程 1. Look for ".gn" file (see "gn help dotfile") in the current directory and walk up the directory tree until one is found. Set this directory to be the "source root" and interpret this file to find the name of the build config file. 2. Execute the build config file identified by .gn to set up the global variables and default toolchain name. Any arguments, variables, defaults, etc. set up in this file will be visible to all files in the build. 3. Load the //BUILD.gn (in the source root directory). 4. Recursively evaluate rules and load BUILD.gn in other directories as necessary to resolve dependencies. If a BUILD file isn't found in the specified location, GN will look in the corresponding location inside the secondary_source defined in the dotfile (see "gn help dotfile"). 5. When a target's dependencies are resolved, write out the `.ninja` file to disk. 6. When all targets are resolved, write out the root build.ninja file. ninja -t -t flag on the Ninja command line runs some tools that we have found useful during Ninja’s development. The current tools are: ninja -t clean remove built files. By default it removes all built files except for those created by the generator. Adding the -g flag also removes built files created by the generator 更多ninja -h 參考: http://blog.csdn.net/foruok/article/details/70050342 http://www.alonemonkey.com/2016/06/15/gn-gyp-ninja/ https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/reference.md https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/quick_start.md 超強(qiáng)干貨來(lái)襲 云風(fēng)專(zhuān)訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生

總結(jié)

以上是生活随笔為你收集整理的WebRTC编译系统之GYP,gn和ninja的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。