Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion foreign_cc/private/configure_script.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# buildifier: disable=module-docstring
load(":make_env_vars.bzl", "get_ldflags_make_vars", "get_make_env_vars")
load(":make_script.bzl", "pkgconfig_script")
load(":make_script.bzl", "ldpath_script", "pkgconfig_script")

# buildifier: disable=function-docstring
def create_configure_script(
Expand Down Expand Up @@ -33,6 +33,7 @@ def create_configure_script(
ext_build_dirs = inputs.ext_build_dirs

script = pkgconfig_script(ext_build_dirs)
script.extend(ldpath_script())

root_path = "$$EXT_BUILD_ROOT$$/{}".format(root)
configure_path = "{}/{}".format(root_path, configure_command)
Expand Down
15 changes: 15 additions & 0 deletions foreign_cc/private/framework/toolchains/commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ PLATFORM_COMMANDS = {
arguments = [],
doc = "Print all environment variables",
),
"export_ld_library_path_var": _command_info(
arguments = [],
doc = "Export the dynamic linked additional paths env variable",
),
"export_var": _command_info(
arguments = [
_argument_info(name = "name", data_type = type(""), doc = "Variable name"),
Expand All @@ -128,6 +132,17 @@ PLATFORM_COMMANDS = {
_argument_info(name = "else_text", data_type = type(""), doc = "Else block text"),
],
),
"increment_ld_library_path": _command_info(
arguments = [
_argument_info(
name = "source",
data_type = type(""),
doc = "Source directory",
),
],
doc = "Find shared libraries under the provided source directory and add them " +
"to (DY)LD_LIBRARY_PATH",
),
"increment_pkg_config_path": _command_info(
arguments = [
_argument_info(
Expand Down
15 changes: 15 additions & 0 deletions foreign_cc/private/framework/toolchains/freebsd_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def pwd():
def echo(text):
return "echo {text}".format(text = text)

def export_ld_library_path_var():
return "LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH:-}\"; export LD_LIBRARY_PATH"

def export_var(name, value):
return "{name}={value}; export {name}".format(name = name, value = value)

Expand Down Expand Up @@ -191,6 +194,16 @@ fi
def script_prelude():
return "set -euo pipefail"

def increment_ld_library_path(_source):
text = """\
local children=$(find "$1" -name '*.so')
LD_LIBRARY_PATH=""
for child in $children; do
export LD_LIBRARY_PATH="$${LD_LIBRARY_PATH:-}$$:$(dirname $child)"
done
"""
return FunctionAndCallInfo(text = text)

def increment_pkg_config_path(_source):
text = """\
local children=$(find "$1/" -mindepth 1 -name '*.pc')
Expand Down Expand Up @@ -284,8 +297,10 @@ commands = struct(
echo = echo,
enable_tracing = enable_tracing,
env = env,
export_ld_library_path_var = export_ld_library_path_var,
export_var = export_var,
if_else = if_else,
increment_ld_library_path = increment_ld_library_path,
increment_pkg_config_path = increment_pkg_config_path,
local_var = local_var,
mkdirs = mkdirs,
Expand Down
15 changes: 15 additions & 0 deletions foreign_cc/private/framework/toolchains/linux_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def echo(text):
def export_var(name, value):
return "{name}={value}; export {name}".format(name = name, value = value)

def export_ld_library_path_var():
return "LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH:-}\"; export LD_LIBRARY_PATH"

def local_var(name, value):
return "local {name}={value}".format(name = name, value = value)

Expand Down Expand Up @@ -173,6 +176,16 @@ fi
def script_prelude():
return "set -euo pipefail"

def increment_ld_library_path(_source):
text = """\
local children=$(find "$1" -name '*.so')
LD_LIBRARY_PATH=""
for child in $children; do
export LD_LIBRARY_PATH="$${LD_LIBRARY_PATH:-}$$:$(dirname $child)"
done
"""
return FunctionAndCallInfo(text = text)

def increment_pkg_config_path(_source):
text = """\
local children=$(find "$1" -mindepth 1 -name '*.pc')
Expand Down Expand Up @@ -266,8 +279,10 @@ commands = struct(
echo = echo,
enable_tracing = enable_tracing,
env = env,
export_ld_library_path_var = export_ld_library_path_var,
export_var = export_var,
if_else = if_else,
increment_ld_library_path = increment_ld_library_path,
increment_pkg_config_path = increment_pkg_config_path,
local_var = local_var,
mkdirs = mkdirs,
Expand Down
14 changes: 14 additions & 0 deletions foreign_cc/private/framework/toolchains/macos_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def echo(text):
def export_var(name, value):
return "{name}={value}; export {name}".format(name = name, value = value)

def export_ld_library_path_var():
return "DYLD_LIBRARY_PATH=\"${DYLD_LIBRARY_PATH:-}\"; export DYLD_LIBRARY_PATH"

def local_var(name, value):
return "local {name}={value}".format(name = name, value = value)

Expand Down Expand Up @@ -182,6 +185,15 @@ fi
def script_prelude():
return "set -euo pipefail"

def increment_ld_library_path(_source):
text = """\
local children=$(find "$1" -name '*.dylib')
for child in $children; do
export DYLD_LIBRARY_PATH="$${DYLD_LIBRARY_PATH:-}$$:$(dirname $child)"
done
"""
return FunctionAndCallInfo(text = text)

def increment_pkg_config_path(_source):
text = """\
local children=$(find "$1/" -mindepth 1 -name '*.pc')
Expand Down Expand Up @@ -279,8 +291,10 @@ commands = struct(
echo = echo,
enable_tracing = enable_tracing,
env = env,
export_ld_library_path_var = export_ld_library_path_var,
export_var = export_var,
if_else = if_else,
increment_ld_library_path = increment_ld_library_path,
increment_pkg_config_path = increment_pkg_config_path,
local_var = local_var,
mkdirs = mkdirs,
Expand Down
8 changes: 8 additions & 0 deletions foreign_cc/private/framework/toolchains/windows_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def pwd():
def echo(text):
return "echo {text}".format(text = text)

def export_ld_library_path_var():
return ""

def export_var(name, value):
return "{name}={value}; export {name}".format(name = name, value = value)

Expand Down Expand Up @@ -205,6 +208,9 @@ export MSYS2_ARG_CONV_EXCL="*"
export SYSTEMDRIVE="C:"
"""

def increment_ld_library_path(_source):
return ""

def increment_pkg_config_path(_source):
text = """\
local children=$($REAL_FIND "$1" -mindepth 1 -name '*.pc')
Expand Down Expand Up @@ -301,8 +307,10 @@ commands = struct(
echo = echo,
enable_tracing = enable_tracing,
env = env,
export_ld_library_path_var = export_ld_library_path_var,
export_var = export_var,
if_else = if_else,
increment_ld_library_path = increment_ld_library_path,
increment_pkg_config_path = increment_pkg_config_path,
local_var = local_var,
mkdirs = mkdirs,
Expand Down
6 changes: 6 additions & 0 deletions foreign_cc/private/make_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def create_make_script(
script.append("##disable_tracing##")
return script

def ldpath_script():
script = []
script.append("##increment_ld_library_path## $$EXT_BUILD_DEPS$$/")
script.append("##export_ld_library_path_var##")
return script

def pkgconfig_script(ext_build_dirs):
"""Create a script fragment to configure pkg-config

Expand Down