BUILD.gn 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. import("//build/config/locales.gni")
  2. import("//tools/grit/repack.gni")
  3. import("build/asar.gni")
  4. import("build/npm.gni")
  5. if (is_mac) {
  6. import("//build/config/mac/rules.gni")
  7. import("//third_party/icu/config.gni")
  8. import("//v8/gni/v8.gni")
  9. }
  10. if (is_linux) {
  11. import("//build/config/linux/pkg_config.gni")
  12. pkg_config("gio_unix") {
  13. packages = [ "gio-unix-2.0" ]
  14. }
  15. }
  16. declare_args() {
  17. electron_project_name = "electron"
  18. electron_product_name = "Electron"
  19. electron_company_name = "GitHub, Inc"
  20. electron_company_abbr = "github"
  21. electron_version = "0.0.0-dev"
  22. enable_desktop_capturer = true
  23. enable_run_as_node = true
  24. enable_osr = true
  25. # Provide a fake location provider for mocking
  26. # the geolocation responses. Disable it if you
  27. # need to test with chromium's location provider.
  28. # Should not be enabled for release build.
  29. enable_fake_location_provider = !is_official_build
  30. }
  31. filenames_gypi = exec_script(
  32. "//build/gypi_to_gn.py",
  33. [
  34. rebase_path("filenames.gypi"),
  35. "--replace=<(SHARED_INTERMEDIATE_DIR)=$target_gen_dir",
  36. ],
  37. "scope",
  38. [ "filenames.gypi" ]
  39. )
  40. config("branding") {
  41. defines = [
  42. "ATOM_PRODUCT_NAME=\"$electron_product_name\"",
  43. "ATOM_PROJECT_NAME=\"$electron_project_name\"",
  44. ]
  45. }
  46. config("features") {
  47. defines = []
  48. if (enable_desktop_capturer) {
  49. defines += [ "ENABLE_DESKTOP_CAPTURER=1" ]
  50. }
  51. if (enable_run_as_node) {
  52. defines += [ "ENABLE_RUN_AS_NODE=1" ]
  53. }
  54. if (enable_osr) {
  55. defines += [ "ENABLE_OSR=1" ]
  56. }
  57. }
  58. config("native_mate_config") {
  59. include_dirs = [
  60. "//third_party/native_mate",
  61. ]
  62. cflags_cc = [
  63. "-Wno-deprecated-declarations",
  64. ]
  65. cflags_objcc = cflags_cc
  66. }
  67. source_set("native_mate") {
  68. deps = [
  69. "//base",
  70. "//net",
  71. "//v8:v8_headers",
  72. "build/node",
  73. ]
  74. public_configs = [ ":native_mate_config" ]
  75. sources = [
  76. "//third_party/native_mate/native_mate/arguments.cc",
  77. "//third_party/native_mate/native_mate/arguments.h",
  78. "//third_party/native_mate/native_mate/compat.h",
  79. "//third_party/native_mate/native_mate/constructor.h",
  80. "//third_party/native_mate/native_mate/converter.cc",
  81. "//third_party/native_mate/native_mate/converter.h",
  82. "//third_party/native_mate/native_mate/dictionary.cc",
  83. "//third_party/native_mate/native_mate/dictionary.h",
  84. "//third_party/native_mate/native_mate/function_template.cc",
  85. "//third_party/native_mate/native_mate/function_template.h",
  86. "//third_party/native_mate/native_mate/handle.h",
  87. "//third_party/native_mate/native_mate/object_template_builder.cc",
  88. "//third_party/native_mate/native_mate/object_template_builder.h",
  89. "//third_party/native_mate/native_mate/persistent_dictionary.cc",
  90. "//third_party/native_mate/native_mate/persistent_dictionary.h",
  91. "//third_party/native_mate/native_mate/scoped_persistent.h",
  92. "//third_party/native_mate/native_mate/wrappable.cc",
  93. "//third_party/native_mate/native_mate/wrappable.h",
  94. "//third_party/native_mate/native_mate/wrappable_base.h",
  95. ]
  96. }
  97. npm_action("atom_browserify_sandbox") {
  98. deps = [ ":atom_js2c_copy" ]
  99. sandbox_args = [
  100. "lib/sandboxed_renderer/init.js",
  101. "-r", "./lib/sandboxed_renderer/api/exports/electron.js:electron",
  102. "-r", "./lib/sandboxed_renderer/api/exports/fs.js:fs",
  103. "-r", "./lib/sandboxed_renderer/api/exports/os.js:os",
  104. "-r", "./lib/sandboxed_renderer/api/exports/path.js:path",
  105. "-r", "./lib/sandboxed_renderer/api/exports/child_process.js:child_process",
  106. ]
  107. inputs = [
  108. "lib/sandboxed_renderer/init.js",
  109. "lib/sandboxed_renderer/api/exports/electron.js",
  110. "lib/sandboxed_renderer/api/exports/fs.js",
  111. "lib/sandboxed_renderer/api/exports/os.js",
  112. "lib/sandboxed_renderer/api/exports/path.js",
  113. "lib/sandboxed_renderer/api/exports/child_process.js",
  114. ]
  115. outputs = [ "$target_gen_dir/js2c/preload_bundle.js" ]
  116. script = "browserify"
  117. args = sandbox_args + [
  118. "-o", rebase_path(outputs[0])
  119. ]
  120. }
  121. npm_action("atom_browserify_isolated") {
  122. deps = [ ":atom_js2c_copy" ]
  123. inputs = [ "lib/isolated_renderer/init.js" ]
  124. outputs = [ "$target_gen_dir/js2c/isolated_bundle.js" ]
  125. script = "browserify"
  126. args = inputs + [
  127. "-o", rebase_path(outputs[0])
  128. ]
  129. }
  130. copy("atom_js2c_copy") {
  131. sources = [
  132. "lib/common/asar.js",
  133. "lib/common/asar_init.js",
  134. ]
  135. outputs = [ "$target_gen_dir/js2c/{{source_file_part}}" ]
  136. }
  137. action("atom_js2c") {
  138. deps = [
  139. ":atom_js2c_copy",
  140. ":atom_browserify_sandbox",
  141. ":atom_browserify_isolated",
  142. ]
  143. js2c_sources = filenames_gypi.js2c_sources
  144. browserify_sources = [
  145. "$target_gen_dir/js2c/isolated_bundle.js",
  146. "$target_gen_dir/js2c/preload_bundle.js",
  147. ]
  148. inputs = js2c_sources + browserify_sources
  149. outputs = [ "$target_gen_dir/atom_natives.h" ]
  150. script = "tools/js2c.py"
  151. args = [
  152. rebase_path("//third_party/electron_node")
  153. ] + rebase_path(outputs, root_build_dir) + [
  154. rebase_path("$target_gen_dir/js2c", root_build_dir)
  155. ]
  156. }
  157. asar("js2asar") {
  158. sources = filenames_gypi.js_sources
  159. outputs = [ "$root_out_dir/resources/electron.asar" ]
  160. root = "lib"
  161. }
  162. asar("app2asar") {
  163. sources = filenames_gypi.default_app_sources
  164. outputs = [ "$root_out_dir/resources/default_app.asar" ]
  165. root = "default_app"
  166. }
  167. group("electron") {
  168. deps = [ ":electron_lib" ]
  169. }
  170. static_library("electron_lib") {
  171. configs += [
  172. "//v8:external_startup_data",
  173. ]
  174. public_configs = [
  175. ":branding",
  176. ":features",
  177. ]
  178. deps = [
  179. "//chrome/common:constants",
  180. "//components/cdm/renderer",
  181. "//components/network_session_configurator/common",
  182. "//components/prefs",
  183. "//components/printing/common",
  184. "//components/security_state/content",
  185. "//content/public/browser",
  186. "//device/geolocation",
  187. "//gin",
  188. "//net:net_resources",
  189. "//ppapi/host",
  190. "//ppapi/proxy",
  191. "//ppapi/shared_impl",
  192. "//printing",
  193. "//services/device/wake_lock/power_save_blocker", # TODO: this requires a visibility patch to chromium src
  194. "//skia",
  195. "//third_party/WebKit/public:blink",
  196. "//third_party/boringssl",
  197. "//third_party/crashpad/crashpad/client",
  198. "//third_party/leveldatabase",
  199. "//third_party/libyuv",
  200. "//third_party/webrtc/modules/desktop_capture",
  201. "//third_party/webrtc/modules/desktop_capture:primitives",
  202. "//ui/events:dom_keycode_converter",
  203. "//ui/views",
  204. "//v8",
  205. ":atom_js2c",
  206. ":native_mate",
  207. "brightray",
  208. "build/node",
  209. ]
  210. if (is_mac) {
  211. deps += [
  212. "//ui/accelerated_widget_mac",
  213. "//base/allocator:features",
  214. ]
  215. }
  216. if (is_linux) {
  217. deps += [
  218. "//build/config/linux/gtk3",
  219. "//chrome/browser/ui/libgtkui",
  220. "//device/bluetooth",
  221. "//third_party/breakpad:client",
  222. "//ui/events/devices/x11",
  223. "//ui/events/platform/x11",
  224. "//ui/native_theme",
  225. "//ui/views/controls/webview",
  226. "//ui/wm",
  227. ]
  228. configs += [ ":gio_unix" ]
  229. }
  230. defines = [
  231. # This is defined in skia/skia_common.gypi.
  232. "SK_SUPPORT_LEGACY_GETTOPDEVICE",
  233. # Disable warnings for g_settings_list_schemas.
  234. "GLIB_DISABLE_DEPRECATION_WARNINGS",
  235. # Import V8 symbols from shared library (node.dll / libnode.so)
  236. "USING_V8_SHARED",
  237. "USING_V8_PLATFORM_SHARED",
  238. "USING_V8_BASE_SHARED",
  239. # Enables SkBitmap size 64 operations
  240. #"SK_SUPPORT_LEGACY_SAFESIZE64", # doesn't seem to be needed to build?
  241. ]
  242. include_dirs = [
  243. "chromium_src",
  244. ".",
  245. "$target_gen_dir",
  246. # TODO(nornagon): replace usage of SchemeRegistry by an actually exported
  247. # API of blink, then delete this include dir.
  248. "//third_party/WebKit/Source",
  249. # NOTE(nornagon): other chromium files use the full path to include
  250. # crashpad; this is just here for compatibility between GN and GYP, so that
  251. # the #includes can be agnostic about where crashpad is vendored.
  252. "//third_party/crashpad",
  253. ]
  254. if (is_linux) {
  255. include_dirs += [
  256. "//third_party/breakpad",
  257. ]
  258. }
  259. extra_source_filters = []
  260. if (!is_linux) {
  261. extra_source_filters += [
  262. "*\bx/*",
  263. "*_x11.h",
  264. "*_x11.cc",
  265. "*_gtk.h",
  266. "*_gtk.cc",
  267. ]
  268. }
  269. if (!is_win) {
  270. extra_source_filters += [
  271. "*\bwin_*.h",
  272. "*\bwin_*.cc",
  273. ]
  274. }
  275. if (is_mac) {
  276. extra_source_filters += [
  277. "*_views.cc",
  278. "*_views.h",
  279. "*\bviews/*",
  280. "*/autofill_popup.cc",
  281. "*/autofill_popup.h",
  282. ]
  283. }
  284. set_sources_assignment_filter(sources_assignment_filter + extra_source_filters)
  285. sources = filenames_gypi.lib_sources
  286. set_sources_assignment_filter(sources_assignment_filter)
  287. if (enable_fake_location_provider) {
  288. defines += [
  289. "OVERRIDE_LOCATION_PROVIDER"
  290. ]
  291. sources += filenames_gypi.lib_sources_location_provider
  292. }
  293. if (enable_run_as_node) {
  294. sources += [
  295. "atom/app/node_main.cc",
  296. "atom/app/node_main.h",
  297. ]
  298. }
  299. if (enable_osr) {
  300. sources += [
  301. "atom/browser/api/atom_api_web_contents_osr.cc",
  302. "atom/browser/osr/osr_output_device.cc",
  303. "atom/browser/osr/osr_output_device.h",
  304. "atom/browser/osr/osr_render_widget_host_view.cc",
  305. "atom/browser/osr/osr_render_widget_host_view.h",
  306. "atom/browser/osr/osr_render_widget_host_view_mac.mm",
  307. "atom/browser/osr/osr_view_proxy.cc",
  308. "atom/browser/osr/osr_view_proxy.h",
  309. "atom/browser/osr/osr_web_contents_view.cc",
  310. "atom/browser/osr/osr_web_contents_view.h",
  311. "atom/browser/osr/osr_web_contents_view_mac.mm",
  312. ]
  313. deps += [
  314. "//ui/compositor",
  315. "//components/viz/service",
  316. ]
  317. }
  318. if (enable_desktop_capturer) {
  319. sources += [
  320. "atom/browser/api/atom_api_desktop_capturer.cc",
  321. "atom/browser/api/atom_api_desktop_capturer.h",
  322. ]
  323. }
  324. if (is_mac) {
  325. libs = [
  326. "Squirrel.framework",
  327. "ReactiveCocoa.framework",
  328. "Mantle.framework",
  329. ]
  330. cflags_objcc = [
  331. "-F", rebase_path("external_binaries", root_build_dir)
  332. ]
  333. if (true) { # !is_mas_build
  334. # ReactiveCocoa which is used by Squirrel requires using __weak.
  335. cflags_objcc += [ "-fobjc-weak" ]
  336. }
  337. }
  338. if (is_linux) {
  339. sources += filenames_gypi.lib_sources_linux
  340. sources += filenames_gypi.lib_sources_nss
  341. }
  342. }
  343. if (is_mac) {
  344. electron_framework_name = electron_product_name + " Framework"
  345. electron_helper_name = electron_product_name + " Helper"
  346. electron_framework_version = "A"
  347. electron_mac_bundle_id = "com.$electron_company_abbr.$electron_project_name"
  348. mac_xib_bundle_data("electron_xibs") {
  349. sources = [ "atom/common/resources/mac/MainMenu.xib" ]
  350. }
  351. bundle_data("electron_framework_resources") {
  352. public_deps = [
  353. "//content/shell:pak",
  354. ":electron_locales",
  355. ]
  356. sources = [
  357. "$root_out_dir/content_shell.pak",
  358. ]
  359. if (icu_use_data_file) {
  360. sources += [ "$root_out_dir/icudtl.dat" ]
  361. public_deps += [ "//third_party/icu:icudata" ]
  362. }
  363. if (v8_use_external_startup_data) {
  364. sources += [
  365. "$root_out_dir/natives_blob.bin",
  366. "$root_out_dir/snapshot_blob.bin",
  367. ]
  368. public_deps += [ "//v8" ]
  369. }
  370. outputs = [
  371. "{{bundle_resources_dir}}/{{source_file_part}}",
  372. ]
  373. }
  374. bundle_data("electron_framework_libraries") {
  375. public_deps = [ "build/node" ]
  376. sources = [
  377. "$root_out_dir/libnode.dylib"
  378. ]
  379. outputs = [
  380. "{{bundle_contents_dir}}/Libraries/{{source_file_part}}"
  381. ]
  382. }
  383. bundle_data("electron_framework_helpers") {
  384. sources = [
  385. "$root_out_dir/crashpad_handler",
  386. ]
  387. outputs = [
  388. "{{bundle_resources_dir}}/{{source_file_part}}",
  389. ]
  390. public_deps = [
  391. "//third_party/crashpad/crashpad/handler:crashpad_handler",
  392. ]
  393. }
  394. mac_framework_bundle("electron_framework") {
  395. output_name = electron_framework_name
  396. framework_version = electron_framework_version
  397. framework_contents = [ "Resources" ]
  398. public_deps = [ ":electron_lib" ]
  399. deps = [
  400. "//base",
  401. "//base:i18n",
  402. ":electron_framework_helpers",
  403. ":electron_framework_libraries",
  404. ":electron_framework_resources",
  405. ":electron_xibs",
  406. ]
  407. info_plist = "atom/common/resources/mac/Info.plist"
  408. extra_substitutions = [
  409. "ATOM_BUNDLE_ID=$electron_mac_bundle_id.framework",
  410. ]
  411. include_dirs = [
  412. ".",
  413. ]
  414. sources = filenames_gypi.framework_sources
  415. libs = [
  416. "Carbon.framework",
  417. "QuartzCore.framework",
  418. "Quartz.framework",
  419. "Security.framework",
  420. "SecurityInterface.framework",
  421. "ServiceManagement.framework",
  422. "StoreKit.framework",
  423. ]
  424. ldflags = [
  425. "-F", rebase_path("external_binaries", root_build_dir),
  426. "-Wl,-install_name,@rpath/$output_name.framework/$output_name",
  427. "-rpath",
  428. "@loader_path/Libraries",
  429. ]
  430. if (is_component_build) {
  431. ldflags += [
  432. "-rpath",
  433. "@executable_path/../../../../../.."
  434. ]
  435. }
  436. }
  437. mac_app_bundle("electron_helper_app") {
  438. output_name = electron_helper_name
  439. deps = [ ":electron_framework+link" ]
  440. sources = filenames_gypi.app_sources
  441. include_dirs = [ "." ]
  442. info_plist = "atom/renderer/resources/mac/Info.plist"
  443. extra_substitutions = [
  444. "ATOM_BUNDLE_ID=$electron_mac_bundle_id.helper",
  445. ]
  446. ldflags = [
  447. "-rpath",
  448. "@executable_path/../../..",
  449. ]
  450. }
  451. bundle_data("electron_app_framework_bundle_data") {
  452. sources = [
  453. "$root_out_dir/$electron_framework_name.framework",
  454. "$root_out_dir/$electron_helper_name.app",
  455. "external_binaries/Squirrel.framework",
  456. "external_binaries/ReactiveCocoa.framework",
  457. "external_binaries/Mantle.framework",
  458. ]
  459. outputs = [
  460. "{{bundle_contents_dir}}/Frameworks/{{source_file_part}}",
  461. ]
  462. public_deps = [
  463. ":electron_framework+link",
  464. ":electron_helper_app",
  465. ]
  466. }
  467. bundle_data("electron_app_resources") {
  468. public_deps = [
  469. ":js2asar",
  470. ":app2asar",
  471. ]
  472. sources = [
  473. "$root_out_dir/resources/electron.asar",
  474. "$root_out_dir/resources/default_app.asar",
  475. ]
  476. outputs = [
  477. "{{bundle_resources_dir}}/{{source_file_part}}"
  478. ]
  479. }
  480. repack_locales("electron_locales") {
  481. source_patterns = [
  482. "${root_gen_dir}/content/app/strings/content_strings_",
  483. ]
  484. deps = [
  485. "//content/app/strings",
  486. ]
  487. input_locales = locales
  488. if (is_mac) {
  489. output_locales = locales_as_mac_outputs
  490. } else {
  491. output_locales = locales
  492. }
  493. if (is_mac) {
  494. output_dir = "$root_gen_dir/repack"
  495. copy_data_to_bundle = true
  496. } else {
  497. output_dir = root_out_dir
  498. }
  499. }
  500. mac_app_bundle("electron_app") {
  501. output_name = electron_product_name
  502. sources = filenames_gypi.app_sources
  503. include_dirs = [ "." ]
  504. deps = [
  505. ":electron_app_framework_bundle_data",
  506. ":electron_app_resources",
  507. ]
  508. info_plist = "atom/browser/resources/mac/Info.plist"
  509. extra_substitutions = [
  510. "ATOM_BUNDLE_ID=$electron_mac_bundle_id",
  511. ]
  512. ldflags = [
  513. "-rpath",
  514. "@executable_path/../Frameworks",
  515. ]
  516. }
  517. }
  518. if (is_linux) {
  519. executable("electron_app") {
  520. output_name = electron_project_name
  521. sources = filenames_gypi.app_sources
  522. include_dirs = [ "." ]
  523. deps = [
  524. ":app2asar",
  525. ":electron_lib",
  526. ":js2asar",
  527. "//build/config:exe_and_shlib_deps",
  528. "//chrome:packed_resources",
  529. "//content/shell:copy_shell_resources",
  530. "//content/shell:pak",
  531. "//third_party/WebKit/public:image_resources",
  532. "//ui/strings",
  533. ]
  534. }
  535. }