Skip to content

Commit 5d4743f

Browse files
codebytereaduh95
authored andcommitted
build: allow linking shared dependencies in the GN build
The GN build always compiles the bundled copies of brotli, c-ares, HdrHistogram, llhttp, libuv, nghttp2, SQLite and zstd, so anyone packaging a GN-built Node.js for a Linux distribution has no counterpart to configure's --shared-* options. Add node_shared_* args named after the GYP variables. When one is set, that dependency's GN template defines its target as a group carrying a pkg-config config instead of the bundled sources, so every existing "deps/<name>" reference picks up the system library without further changes, and config.gypi reports the choice like a GYP build does. Refs: #55903 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: #65797 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 36f0fd9 commit 5d4743f

10 files changed

Lines changed: 432 additions & 306 deletions

File tree

deps/brotli/unofficial.gni

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,49 @@
44

55
# The actual configurations are put inside a template in unofficial.gni to
66
# prevent accidental edits from contributors.
7-
template("brotli_gn_build") {
8-
config("brotli_config") {
9-
include_dirs = [ "c/include" ]
10-
}
7+
import("../../node.gni")
118

12-
gypi_values = exec_script("../../tools/gypi_to_gn.py",
13-
[ rebase_path("brotli.gyp") ],
14-
"scope",
15-
[ "brotli.gyp" ])
16-
17-
source_set(target_name) {
18-
forward_variables_from(invoker, "*")
19-
public_configs = [ ":brotli_config" ]
20-
sources = gypi_values.brotli_sources
21-
if (is_linux) {
22-
defines = [ "OS_LINUX" ]
23-
} else if (is_mac) {
24-
defines = [ "OS_MACOSX" ]
25-
} else if (target_os == "freebsd") {
26-
defines = [ "OS_FREEBSD" ]
9+
template("brotli_gn_build") {
10+
if (node_shared_brotli) {
11+
import("//build/config/linux/pkg_config.gni")
12+
pkg_config("brotli_config") {
13+
packages = [ "libbrotlidec", "libbrotlienc" ]
2714
}
28-
if (is_linux) {
29-
libs = [ "m" ]
15+
group(target_name) {
16+
forward_variables_from(invoker, "*")
17+
public_configs = [ ":brotli_config" ]
3018
}
31-
if (is_clang || !is_win) {
32-
cflags_c = [
33-
"-Wno-implicit-fallthrough",
34-
"-Wno-unreachable-code",
35-
"-Wno-unreachable-code-return",
36-
]
19+
} else {
20+
config("brotli_config") {
21+
include_dirs = [ "c/include" ]
22+
}
23+
24+
gypi_values = exec_script("../../tools/gypi_to_gn.py",
25+
[ rebase_path("brotli.gyp") ],
26+
"scope",
27+
[ "brotli.gyp" ])
28+
29+
source_set(target_name) {
30+
forward_variables_from(invoker, "*")
31+
public_configs = [ ":brotli_config" ]
32+
sources = gypi_values.brotli_sources
33+
if (is_linux) {
34+
defines = [ "OS_LINUX" ]
35+
} else if (is_mac) {
36+
defines = [ "OS_MACOSX" ]
37+
} else if (target_os == "freebsd") {
38+
defines = [ "OS_FREEBSD" ]
39+
}
40+
if (is_linux) {
41+
libs = [ "m" ]
42+
}
43+
if (is_clang || !is_win) {
44+
cflags_c = [
45+
"-Wno-implicit-fallthrough",
46+
"-Wno-unreachable-code",
47+
"-Wno-unreachable-code-return",
48+
]
49+
}
3750
}
3851
}
3952
}

deps/cares/unofficial.gni

Lines changed: 74 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,91 @@
44

55
# The actual configurations are put inside a template in unofficial.gni to
66
# prevent accidental edits from contributors.
7-
template("cares_gn_build") {
8-
config("cares_config") {
9-
include_dirs = [ "include" ]
10-
if (!is_component_build) {
11-
defines = [ "CARES_STATICLIB" ]
12-
}
13-
}
14-
15-
gypi_values = exec_script("../../tools/gypi_to_gn.py",
16-
[ rebase_path("cares.gyp") ],
17-
"scope",
18-
[ "cares.gyp" ])
7+
import("../../node.gni")
198

20-
component(target_name) {
21-
forward_variables_from(invoker, "*")
22-
public_configs = [ ":cares_config" ]
23-
if (is_component_build) {
24-
defines = [ "CARES_BUILDING_LIBRARY" ]
25-
} else {
26-
defines = []
9+
template("cares_gn_build") {
10+
if (node_shared_cares) {
11+
import("//build/config/linux/pkg_config.gni")
12+
pkg_config("cares_config") {
13+
packages = [ "libcares" ]
2714
}
28-
if (is_win) {
29-
defines += [ "CARES_PULL_WS2TCPIP_H=1" ]
15+
group(target_name) {
16+
forward_variables_from(invoker, "*")
17+
public_configs = [ ":cares_config" ]
3018
}
31-
if (is_posix) {
32-
defines += [
33-
"_DARWIN_USE_64_BIT_INODE=1",
34-
"_LARGEFILE_SOURCE",
35-
"_FILE_OFFSET_BITS=64",
36-
"_GNU_SOURCE",
37-
"HAVE_CONFIG_H",
38-
]
19+
} else {
20+
config("cares_config") {
21+
include_dirs = [ "include" ]
22+
if (!is_component_build) {
23+
defines = [ "CARES_STATICLIB" ]
24+
}
3925
}
4026

41-
include_dirs = [
42-
"src/lib",
43-
"src/lib/include",
44-
]
45-
if (is_win) {
46-
include_dirs += [ "config/win32" ]
47-
} else if (is_linux) {
48-
include_dirs += [ "config/linux" ]
49-
} else if (is_mac) {
50-
include_dirs += [ "config/darwin" ]
51-
}
27+
gypi_values = exec_script("../../tools/gypi_to_gn.py",
28+
[ rebase_path("cares.gyp") ],
29+
"scope",
30+
[ "cares.gyp" ])
5231

53-
if (is_win) {
54-
libs = [
55-
"ws2_32.lib",
56-
"iphlpapi.lib",
57-
]
58-
}
32+
component(target_name) {
33+
forward_variables_from(invoker, "*")
34+
public_configs = [ ":cares_config" ]
35+
if (is_component_build) {
36+
defines = [ "CARES_BUILDING_LIBRARY" ]
37+
} else {
38+
defines = []
39+
}
40+
if (is_win) {
41+
defines += [ "CARES_PULL_WS2TCPIP_H=1" ]
42+
}
43+
if (is_posix) {
44+
defines += [
45+
"_DARWIN_USE_64_BIT_INODE=1",
46+
"_LARGEFILE_SOURCE",
47+
"_FILE_OFFSET_BITS=64",
48+
"_GNU_SOURCE",
49+
"HAVE_CONFIG_H",
50+
]
51+
}
5952

60-
sources = gypi_values.cares_sources_common
61-
if (is_linux) {
62-
sources += [ "config/linux/ares_config.h" ]
63-
}
64-
if (is_mac) {
65-
sources += gypi_values.cares_sources_mac
66-
}
53+
include_dirs = [
54+
"src/lib",
55+
"src/lib/include",
56+
]
57+
if (is_win) {
58+
include_dirs += [ "config/win32" ]
59+
} else if (is_linux) {
60+
include_dirs += [ "config/linux" ]
61+
} else if (is_mac) {
62+
include_dirs += [ "config/darwin" ]
63+
}
6764

68-
if (is_clang) {
6965
if (is_win) {
70-
cflags_c = [
71-
"-Wno-macro-redefined",
72-
]
73-
} else {
74-
cflags_c = [
75-
"-Wno-implicit-fallthrough",
76-
"-Wno-unreachable-code",
66+
libs = [
67+
"ws2_32.lib",
68+
"iphlpapi.lib",
7769
]
7870
}
71+
72+
sources = gypi_values.cares_sources_common
73+
if (is_linux) {
74+
sources += [ "config/linux/ares_config.h" ]
75+
}
76+
if (is_mac) {
77+
sources += gypi_values.cares_sources_mac
78+
}
79+
80+
if (is_clang) {
81+
if (is_win) {
82+
cflags_c = [
83+
"-Wno-macro-redefined",
84+
]
85+
} else {
86+
cflags_c = [
87+
"-Wno-implicit-fallthrough",
88+
"-Wno-unreachable-code",
89+
]
90+
}
91+
}
7992
}
8093
}
8194
}

deps/histogram/unofficial.gni

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,42 @@
44

55
# The actual configurations are put inside a template in unofficial.gni to
66
# prevent accidental edits from contributors.
7+
import("../../node.gni")
8+
79
template("histogram_gn_build") {
8-
config("histogram_config") {
9-
include_dirs = [ "include" ]
10-
}
10+
if (node_shared_hdr_histogram) {
11+
import("//build/config/linux/pkg_config.gni")
12+
pkg_config("histogram_config") {
13+
packages = [ "hdr_histogram" ]
14+
}
15+
group(target_name) {
16+
forward_variables_from(invoker, "*")
17+
public_configs = [ ":histogram_config" ]
18+
}
19+
} else {
20+
config("histogram_config") {
21+
include_dirs = [ "include" ]
22+
}
1123

12-
gypi_values = exec_script("../../tools/gypi_to_gn.py",
13-
[ rebase_path("histogram.gyp") ],
14-
"scope",
15-
[ "histogram.gyp" ])
24+
gypi_values = exec_script("../../tools/gypi_to_gn.py",
25+
[ rebase_path("histogram.gyp") ],
26+
"scope",
27+
[ "histogram.gyp" ])
1628

17-
source_set(target_name) {
18-
forward_variables_from(invoker, "*")
19-
public_configs = [ ":histogram_config" ]
20-
sources = gypi_values.histogram_sources
21-
if (is_clang || !is_win) {
22-
cflags_c = [
23-
"-Wno-atomic-alignment",
24-
"-Wno-incompatible-pointer-types",
25-
"-Wno-unused-function",
26-
]
27-
}
28-
if (is_linux) {
29-
libs = [ "atomic" ]
29+
source_set(target_name) {
30+
forward_variables_from(invoker, "*")
31+
public_configs = [ ":histogram_config" ]
32+
sources = gypi_values.histogram_sources
33+
if (is_clang || !is_win) {
34+
cflags_c = [
35+
"-Wno-atomic-alignment",
36+
"-Wno-incompatible-pointer-types",
37+
"-Wno-unused-function",
38+
]
39+
}
40+
if (is_linux) {
41+
libs = [ "atomic" ]
42+
}
3043
}
3144
}
3245
}

deps/llhttp/unofficial.gni

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,39 @@
44

55
# The actual configurations are put inside a template in unofficial.gni to
66
# prevent accidental edits from contributors.
7+
import("../../node.gni")
8+
79
template("llhttp_gn_build") {
8-
config("llhttp_config") {
9-
include_dirs = [ "include" ]
10-
}
10+
if (node_shared_http_parser) {
11+
import("//build/config/linux/pkg_config.gni")
12+
pkg_config("llhttp_config") {
13+
packages = [ "libllhttp" ]
14+
}
15+
group(target_name) {
16+
forward_variables_from(invoker, "*")
17+
public_configs = [ ":llhttp_config" ]
18+
}
19+
} else {
20+
config("llhttp_config") {
21+
include_dirs = [ "include" ]
22+
}
1123

12-
gypi_values = exec_script("../../tools/gypi_to_gn.py",
13-
[ rebase_path("llhttp.gyp") ],
14-
"scope",
15-
[ "llhttp.gyp" ])
24+
gypi_values = exec_script("../../tools/gypi_to_gn.py",
25+
[ rebase_path("llhttp.gyp") ],
26+
"scope",
27+
[ "llhttp.gyp" ])
1628

17-
source_set(target_name) {
18-
forward_variables_from(invoker, "*")
19-
public_configs = [ ":llhttp_config" ]
20-
include_dirs = [ "include" ]
21-
sources = gypi_values.llhttp_sources
22-
if (is_clang || !is_win) {
23-
cflags_c = [
24-
"-Wno-implicit-fallthrough",
25-
"-Wno-unreachable-code",
26-
]
29+
source_set(target_name) {
30+
forward_variables_from(invoker, "*")
31+
public_configs = [ ":llhttp_config" ]
32+
include_dirs = [ "include" ]
33+
sources = gypi_values.llhttp_sources
34+
if (is_clang || !is_win) {
35+
cflags_c = [
36+
"-Wno-implicit-fallthrough",
37+
"-Wno-unreachable-code",
38+
]
39+
}
2740
}
2841
}
2942
}

0 commit comments

Comments
 (0)