Skip to content

Commit ea763f3

Browse files
authored
Merge pull request #3122 from eli-schwartz/betterlinkage
meson: for internal linkage, link to both libzstd and a static copy of it
2 parents 86bd977 + 6548ec7 commit ea763f3

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

build/meson/lib/meson.build

+29
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,35 @@ libzstd = library('zstd',
126126
libzstd_dep = declare_dependency(link_with: libzstd,
127127
include_directories: libzstd_includes)
128128

129+
# we link to both:
130+
# - the shared library (for public symbols)
131+
# - the static library (for private symbols)
132+
#
133+
# this is needed because internally private symbols are used all the time, and
134+
# -fvisibility=hidden means those cannot be found
135+
if get_option('default_library') == 'static'
136+
libzstd_static = libzstd
137+
libzstd_internal_dep = libzstd_dep
138+
else
139+
if get_option('default_library') == 'shared'
140+
libzstd_static = static_library('zstd_objlib',
141+
objects: libzstd.extract_all_objects(recursive: true),
142+
build_by_default: false)
143+
else
144+
libzstd_static = libzstd.get_static_lib()
145+
endif
146+
147+
if cc_id == compiler_msvc
148+
# msvc does not actually support linking to both, but errors out with:
149+
# error LNK2005: ZSTD_<foo> already defined in zstd.lib(zstd-1.dll)
150+
libzstd_internal_dep = declare_dependency(link_with: libzstd_static)
151+
else
152+
libzstd_internal_dep = declare_dependency(link_with: libzstd,
153+
# the static library must be linked after the shared one
154+
dependencies: declare_dependency(link_with: libzstd_static))
155+
endif
156+
endif
157+
129158
pkgconfig.generate(libzstd,
130159
name: 'libzstd',
131160
filebase: 'libzstd',

build/meson/programs/meson.build

+5-13
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@ zstd_programs_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
1919
join_paths(zstd_rootdir, 'programs/benchzstd.c'),
2020
join_paths(zstd_rootdir, 'programs/datagen.c'),
2121
join_paths(zstd_rootdir, 'programs/dibio.c'),
22-
join_paths(zstd_rootdir, 'programs/zstdcli_trace.c'),
23-
# needed due to use of private symbol + -fvisibility=hidden
24-
join_paths(zstd_rootdir, 'lib/common/xxhash.c'),
25-
join_paths(zstd_rootdir, 'lib/common/pool.c'),
26-
join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
27-
join_paths(zstd_rootdir, 'lib/common/error_private.c')]
28-
29-
zstd_deps = [ libzstd_dep ]
22+
join_paths(zstd_rootdir, 'programs/zstdcli_trace.c')]
23+
24+
zstd_deps = [ libzstd_internal_dep ]
3025
zstd_c_args = libzstd_debug_cflags
3126

32-
zstd_frugal_deps = [ libzstd_dep ]
27+
zstd_frugal_deps = [ libzstd_internal_dep ]
3328
zstd_frugal_c_args = [ '-DZSTD_NOBENCH', '-DZSTD_NODICT', '-DZSTD_NOTRACE' ]
3429

3530
if use_multi_thread
@@ -82,10 +77,7 @@ zstd_frugal_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
8277
join_paths(zstd_rootdir, 'programs/timefn.c'),
8378
join_paths(zstd_rootdir, 'programs/util.c'),
8479
join_paths(zstd_rootdir, 'programs/fileio.c'),
85-
join_paths(zstd_rootdir, 'programs/fileio_asyncio.c'),
86-
join_paths(zstd_rootdir, 'lib/common/pool.c'),
87-
join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
88-
join_paths(zstd_rootdir, 'lib/common/error_private.c')]
80+
join_paths(zstd_rootdir, 'programs/fileio_asyncio.c')]
8981

9082
# Minimal target, with only zstd compression and decompression.
9183
# No bench. No legacy.

build/meson/tests/meson.build

+2-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ testcommon_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
3838
testcommon = static_library('testcommon',
3939
testcommon_sources,
4040
# needed due to use of private symbol + -fvisibility=hidden
41-
objects: libzstd.extract_all_objects(recursive: false))
41+
link_with: libzstd_static)
4242

4343
testcommon_dep = declare_dependency(link_with: testcommon,
4444
dependencies: libzstd_deps,
@@ -116,11 +116,7 @@ decodecorpus = executable('decodecorpus',
116116
dependencies: [ testcommon_dep, libm_dep ],
117117
install: false)
118118

119-
poolTests_sources = [join_paths(zstd_rootdir, 'tests/poolTests.c'),
120-
join_paths(zstd_rootdir, 'lib/common/pool.c'),
121-
join_paths(zstd_rootdir, 'lib/common/threading.c'),
122-
join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
123-
join_paths(zstd_rootdir, 'lib/common/error_private.c')]
119+
poolTests_sources = [join_paths(zstd_rootdir, 'tests/poolTests.c')]
124120
poolTests = executable('poolTests',
125121
poolTests_sources,
126122
include_directories: test_includes,

0 commit comments

Comments
 (0)