BUILD.gn 14 KB

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