Skip to content

Commit 4d48a36

Browse files
committed
configure_make: provide (DY)LD_LIBRARY_PATH based on the dependencies
1 parent 2eca712 commit 4d48a36

File tree

7 files changed

+76
-1
lines changed

7 files changed

+76
-1
lines changed

foreign_cc/private/configure_script.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# buildifier: disable=module-docstring
22
load(":make_env_vars.bzl", "get_ldflags_make_vars", "get_make_env_vars")
3-
load(":make_script.bzl", "pkgconfig_script")
3+
load(":make_script.bzl", "pkgconfig_script", "ldpath_script")
44

55
# buildifier: disable=function-docstring
66
def create_configure_script(
@@ -33,6 +33,7 @@ def create_configure_script(
3333
ext_build_dirs = inputs.ext_build_dirs
3434

3535
script = pkgconfig_script(ext_build_dirs)
36+
script.extend(ldpath_script())
3637

3738
root_path = "$$EXT_BUILD_ROOT$$/{}".format(root)
3839
configure_path = "{}/{}".format(root_path, configure_command)

foreign_cc/private/framework/toolchains/commands.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ PLATFORM_COMMANDS = {
113113
arguments = [],
114114
doc = "Print all environment variables",
115115
),
116+
"export_ld_library_path_var": _command_info(
117+
arguments = [],
118+
doc = "Export the dynamic linked additional paths env variable",
119+
),
116120
"export_var": _command_info(
117121
arguments = [
118122
_argument_info(name = "name", data_type = type(""), doc = "Variable name"),
@@ -128,6 +132,17 @@ PLATFORM_COMMANDS = {
128132
_argument_info(name = "else_text", data_type = type(""), doc = "Else block text"),
129133
],
130134
),
135+
"increment_ld_library_path": _command_info(
136+
arguments = [
137+
_argument_info(
138+
name = "source",
139+
data_type = type(""),
140+
doc = "Source directory",
141+
),
142+
],
143+
doc = "Find shared libraries under the provided source directory and add them " +
144+
"to (DY)LD_LIBRARY_PATH",
145+
),
131146
"increment_pkg_config_path": _command_info(
132147
arguments = [
133148
_argument_info(

foreign_cc/private/framework/toolchains/freebsd_commands.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def pwd():
2323
def echo(text):
2424
return "echo {text}".format(text = text)
2525

26+
def export_ld_library_path_var():
27+
return "LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH:-}\"; export LD_LIBRARY_PATH"
28+
2629
def export_var(name, value):
2730
return "{name}={value}; export {name}".format(name = name, value = value)
2831

@@ -191,6 +194,16 @@ fi
191194
def script_prelude():
192195
return "set -euo pipefail"
193196

197+
def increment_ld_library_path(_source):
198+
text = """\
199+
local children=$(find "$1" -name '*.so')
200+
LD_LIBRARY_PATH=""
201+
for child in $children; do
202+
export LD_LIBRARY_PATH="$${LD_LIBRARY_PATH:-}$$:$(dirname $child)"
203+
done
204+
"""
205+
return FunctionAndCallInfo(text = text)
206+
194207
def increment_pkg_config_path(_source):
195208
text = """\
196209
local children=$(find "$1/" -mindepth 1 -name '*.pc')
@@ -284,8 +297,10 @@ commands = struct(
284297
echo = echo,
285298
enable_tracing = enable_tracing,
286299
env = env,
300+
export_ld_library_path_var = export_ld_library_path_var,
287301
export_var = export_var,
288302
if_else = if_else,
303+
increment_ld_library_path = increment_ld_library_path,
289304
increment_pkg_config_path = increment_pkg_config_path,
290305
local_var = local_var,
291306
mkdirs = mkdirs,

foreign_cc/private/framework/toolchains/linux_commands.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def echo(text):
1717
def export_var(name, value):
1818
return "{name}={value}; export {name}".format(name = name, value = value)
1919

20+
def export_ld_library_path_var():
21+
return "LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH:-}\"; export LD_LIBRARY_PATH"
22+
2023
def local_var(name, value):
2124
return "local {name}={value}".format(name = name, value = value)
2225

@@ -173,6 +176,16 @@ fi
173176
def script_prelude():
174177
return "set -euo pipefail"
175178

179+
def increment_ld_library_path(_source):
180+
text = """\
181+
local children=$(find "$1" -name '*.so')
182+
LD_LIBRARY_PATH=""
183+
for child in $children; do
184+
export LD_LIBRARY_PATH="$${LD_LIBRARY_PATH:-}$$:$(dirname $child)"
185+
done
186+
"""
187+
return FunctionAndCallInfo(text = text)
188+
176189
def increment_pkg_config_path(_source):
177190
text = """\
178191
local children=$(find "$1" -mindepth 1 -name '*.pc')
@@ -266,8 +279,10 @@ commands = struct(
266279
echo = echo,
267280
enable_tracing = enable_tracing,
268281
env = env,
282+
export_ld_library_path_var = export_ld_library_path_var,
269283
export_var = export_var,
270284
if_else = if_else,
285+
increment_ld_library_path = increment_ld_library_path,
271286
increment_pkg_config_path = increment_pkg_config_path,
272287
local_var = local_var,
273288
mkdirs = mkdirs,

foreign_cc/private/framework/toolchains/macos_commands.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def echo(text):
1717
def export_var(name, value):
1818
return "{name}={value}; export {name}".format(name = name, value = value)
1919

20+
def export_ld_library_path_var():
21+
return "DYLD_LIBRARY_PATH=\"${DYLD_LIBRARY_PATH:-}\"; export DYLD_LIBRARY_PATH"
22+
2023
def local_var(name, value):
2124
return "local {name}={value}".format(name = name, value = value)
2225

@@ -182,6 +185,15 @@ fi
182185
def script_prelude():
183186
return "set -euo pipefail"
184187

188+
def increment_ld_library_path(_source):
189+
text = """\
190+
local children=$(find "$1" -name '*.dylib')
191+
for child in $children; do
192+
export DYLD_LIBRARY_PATH="$${DYLD_LIBRARY_PATH:-}$$:$(dirname $child)"
193+
done
194+
"""
195+
return FunctionAndCallInfo(text = text)
196+
185197
def increment_pkg_config_path(_source):
186198
text = """\
187199
local children=$(find "$1/" -mindepth 1 -name '*.pc')
@@ -279,8 +291,10 @@ commands = struct(
279291
echo = echo,
280292
enable_tracing = enable_tracing,
281293
env = env,
294+
export_ld_library_path_var = export_ld_library_path_var,
282295
export_var = export_var,
283296
if_else = if_else,
297+
increment_ld_library_path = increment_ld_library_path,
284298
increment_pkg_config_path = increment_pkg_config_path,
285299
local_var = local_var,
286300
mkdirs = mkdirs,

foreign_cc/private/framework/toolchains/windows_commands.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def pwd():
1414
def echo(text):
1515
return "echo {text}".format(text = text)
1616

17+
def export_ld_library_path_var():
18+
return ""
19+
1720
def export_var(name, value):
1821
return "{name}={value}; export {name}".format(name = name, value = value)
1922

@@ -205,6 +208,9 @@ export MSYS2_ARG_CONV_EXCL="*"
205208
export SYSTEMDRIVE="C:"
206209
"""
207210

211+
def increment_ld_library_path(_source):
212+
return ""
213+
208214
def increment_pkg_config_path(_source):
209215
text = """\
210216
local children=$($REAL_FIND "$1" -mindepth 1 -name '*.pc')
@@ -301,8 +307,10 @@ commands = struct(
301307
echo = echo,
302308
enable_tracing = enable_tracing,
303309
env = env,
310+
export_ld_library_path_var = export_ld_library_path_var,
304311
export_var = export_var,
305312
if_else = if_else,
313+
increment_ld_library_path = increment_ld_library_path,
306314
increment_pkg_config_path = increment_pkg_config_path,
307315
local_var = local_var,
308316
mkdirs = mkdirs,

foreign_cc/private/make_script.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def create_make_script(
4949
script.append("##disable_tracing##")
5050
return script
5151

52+
def ldpath_script():
53+
script = []
54+
script.append("##increment_ld_library_path## $$EXT_BUILD_DEPS$$/")
55+
script.append("##export_ld_library_path_var##")
56+
return script
57+
58+
5259
def pkgconfig_script(ext_build_dirs):
5360
"""Create a script fragment to configure pkg-config
5461

0 commit comments

Comments
 (0)