msvc: fix make var for windows deps (#1324)
This commit is contained in:
parent
aaedbc0a65
commit
bcd0ec409f
|
@ -2,6 +2,7 @@
|
||||||
build tool
|
build tool
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||||
load(
|
load(
|
||||||
"//foreign_cc/private:cc_toolchain_util.bzl",
|
"//foreign_cc/private:cc_toolchain_util.bzl",
|
||||||
"get_flags_info",
|
"get_flags_info",
|
||||||
|
@ -82,6 +83,9 @@ def _create_configure_script(configureParameters):
|
||||||
if xcompile_options:
|
if xcompile_options:
|
||||||
configure_options.extend(xcompile_options)
|
configure_options.extend(xcompile_options)
|
||||||
|
|
||||||
|
cc_toolchain = find_cpp_toolchain(ctx)
|
||||||
|
is_msvc = cc_toolchain.compiler == "msvc-cl"
|
||||||
|
|
||||||
configure = create_configure_script(
|
configure = create_configure_script(
|
||||||
workspace_name = ctx.workspace_name,
|
workspace_name = ctx.workspace_name,
|
||||||
tools = tools,
|
tools = tools,
|
||||||
|
@ -108,6 +112,7 @@ def _create_configure_script(configureParameters):
|
||||||
make_args = args,
|
make_args = args,
|
||||||
executable_ldflags_vars = ctx.attr.executable_ldflags_vars,
|
executable_ldflags_vars = ctx.attr.executable_ldflags_vars,
|
||||||
shared_ldflags_vars = ctx.attr.shared_ldflags_vars,
|
shared_ldflags_vars = ctx.attr.shared_ldflags_vars,
|
||||||
|
is_msvc = is_msvc,
|
||||||
)
|
)
|
||||||
return define_install_prefix + configure
|
return define_install_prefix + configure
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""A rule for building projects using the [GNU Make](https://www.gnu.org/software/make/) build tool"""
|
"""A rule for building projects using the [GNU Make](https://www.gnu.org/software/make/) build tool"""
|
||||||
|
|
||||||
|
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||||
load(
|
load(
|
||||||
"//foreign_cc/private:cc_toolchain_util.bzl",
|
"//foreign_cc/private:cc_toolchain_util.bzl",
|
||||||
"get_flags_info",
|
"get_flags_info",
|
||||||
|
@ -66,6 +67,9 @@ def _create_make_script(configureParameters):
|
||||||
install_prefix = ctx.attr.install_prefix,
|
install_prefix = ctx.attr.install_prefix,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
cc_toolchain = find_cpp_toolchain(ctx)
|
||||||
|
is_msvc = cc_toolchain.compiler == "msvc-cl"
|
||||||
|
|
||||||
return create_make_script(
|
return create_make_script(
|
||||||
workspace_name = ctx.workspace_name,
|
workspace_name = ctx.workspace_name,
|
||||||
tools = tools,
|
tools = tools,
|
||||||
|
@ -81,6 +85,7 @@ def _create_make_script(configureParameters):
|
||||||
make_install_prefix = ctx.attr.install_prefix,
|
make_install_prefix = ctx.attr.install_prefix,
|
||||||
executable_ldflags_vars = ctx.attr.executable_ldflags_vars,
|
executable_ldflags_vars = ctx.attr.executable_ldflags_vars,
|
||||||
shared_ldflags_vars = ctx.attr.shared_ldflags_vars,
|
shared_ldflags_vars = ctx.attr.shared_ldflags_vars,
|
||||||
|
is_msvc = is_msvc,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _attrs():
|
def _attrs():
|
||||||
|
|
|
@ -28,7 +28,8 @@ def create_configure_script(
|
||||||
make_targets,
|
make_targets,
|
||||||
make_args,
|
make_args,
|
||||||
executable_ldflags_vars,
|
executable_ldflags_vars,
|
||||||
shared_ldflags_vars):
|
shared_ldflags_vars,
|
||||||
|
is_msvc):
|
||||||
ext_build_dirs = inputs.ext_build_dirs
|
ext_build_dirs = inputs.ext_build_dirs
|
||||||
|
|
||||||
script = pkgconfig_script(ext_build_dirs)
|
script = pkgconfig_script(ext_build_dirs)
|
||||||
|
@ -73,15 +74,17 @@ def create_configure_script(
|
||||||
).lstrip())
|
).lstrip())
|
||||||
|
|
||||||
script.append("##mkdirs## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$")
|
script.append("##mkdirs## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$")
|
||||||
|
|
||||||
|
make_commands = []
|
||||||
script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
|
script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
|
||||||
env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs),
|
env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs, is_msvc, make_commands),
|
||||||
prefix = configure_prefix,
|
prefix = configure_prefix,
|
||||||
configure = configure_path,
|
configure = configure_path,
|
||||||
prefix_flag = prefix_flag,
|
prefix_flag = prefix_flag,
|
||||||
user_options = " ".join(user_options),
|
user_options = " ".join(user_options),
|
||||||
))
|
))
|
||||||
|
|
||||||
ldflags_make_vars = get_ldflags_make_vars(executable_ldflags_vars, shared_ldflags_vars, workspace_name, flags, env_vars, deps, inputs)
|
ldflags_make_vars = get_ldflags_make_vars(executable_ldflags_vars, shared_ldflags_vars, workspace_name, flags, env_vars, deps, inputs, is_msvc)
|
||||||
|
|
||||||
make_commands = []
|
make_commands = []
|
||||||
for target in make_targets:
|
for target in make_targets:
|
||||||
|
|
|
@ -11,9 +11,10 @@ def get_make_env_vars(
|
||||||
user_vars,
|
user_vars,
|
||||||
deps,
|
deps,
|
||||||
inputs,
|
inputs,
|
||||||
make_commands = []):
|
is_msvc,
|
||||||
|
make_commands):
|
||||||
vars = _get_make_variables(workspace_name, tools, flags, user_vars, make_commands)
|
vars = _get_make_variables(workspace_name, tools, flags, user_vars, make_commands)
|
||||||
deps_flags = _define_deps_flags(deps, inputs)
|
deps_flags = _define_deps_flags(deps, inputs, is_msvc)
|
||||||
|
|
||||||
# For cross-compilation.
|
# For cross-compilation.
|
||||||
if "RANLIB" not in vars.keys():
|
if "RANLIB" not in vars.keys():
|
||||||
|
@ -42,27 +43,31 @@ def get_ldflags_make_vars(
|
||||||
flags,
|
flags,
|
||||||
user_vars,
|
user_vars,
|
||||||
deps,
|
deps,
|
||||||
inputs):
|
inputs,
|
||||||
|
is_msvc):
|
||||||
vars = _get_ldflags_vars(executable_ldflags_vars, shared_ldflags_vars, flags, user_vars)
|
vars = _get_ldflags_vars(executable_ldflags_vars, shared_ldflags_vars, flags, user_vars)
|
||||||
|
|
||||||
deps_flags = _define_deps_flags(deps, inputs)
|
deps_flags = _define_deps_flags(deps, inputs, is_msvc)
|
||||||
for key in vars.keys():
|
for key in vars.keys():
|
||||||
vars[key] = vars[key] + deps_flags.libs
|
vars[key] = vars[key] + deps_flags.libs
|
||||||
|
|
||||||
return " ".join(["{}=\"{}\""
|
return " ".join(["{}=\"{}\""
|
||||||
.format(key, _join_flags_list(workspace_name, vars[key])) for key in vars])
|
.format(key, _join_flags_list(workspace_name, vars[key])) for key in vars])
|
||||||
|
|
||||||
def _define_deps_flags(deps, inputs):
|
def _define_deps_flags(deps, inputs, is_msvc):
|
||||||
# It is very important to keep the order for the linker => put them into list
|
# It is very important to keep the order for the linker => put them into list
|
||||||
lib_dirs = []
|
lib_dirs = []
|
||||||
|
|
||||||
|
# msvc compiler uses -LIBPATH instead of -L
|
||||||
|
lib_flag = "-LIBPATH:" if is_msvc else "-L"
|
||||||
|
|
||||||
# Here go libraries built with Bazel
|
# Here go libraries built with Bazel
|
||||||
gen_dirs_set = {}
|
gen_dirs_set = {}
|
||||||
for lib in inputs.libs:
|
for lib in inputs.libs:
|
||||||
dir_ = lib.dirname
|
dir_ = lib.dirname
|
||||||
if not gen_dirs_set.get(dir_):
|
if not gen_dirs_set.get(dir_):
|
||||||
gen_dirs_set[dir_] = 1
|
gen_dirs_set[dir_] = 1
|
||||||
lib_dirs.append("-L$$EXT_BUILD_ROOT$$/" + dir_)
|
lib_dirs.append(lib_flag + "$$EXT_BUILD_ROOT$$/" + dir_)
|
||||||
|
|
||||||
include_dirs_set = {}
|
include_dirs_set = {}
|
||||||
for include_dir in inputs.include_dirs:
|
for include_dir in inputs.include_dirs:
|
||||||
|
@ -89,7 +94,7 @@ def _define_deps_flags(deps, inputs):
|
||||||
|
|
||||||
dir_name = artifact.gen_dir.basename
|
dir_name = artifact.gen_dir.basename
|
||||||
include_dirs.append("-I$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.include_dir_name))
|
include_dirs.append("-I$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.include_dir_name))
|
||||||
lib_dirs.append("-L$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.lib_dir_name))
|
lib_dirs.append(lib_flag + "$$EXT_BUILD_DEPS$$/{}/{}".format(dir_name, artifact.lib_dir_name))
|
||||||
|
|
||||||
return struct(
|
return struct(
|
||||||
libs = lib_dirs,
|
libs = lib_dirs,
|
||||||
|
|
|
@ -17,7 +17,8 @@ def create_make_script(
|
||||||
make_args,
|
make_args,
|
||||||
make_install_prefix,
|
make_install_prefix,
|
||||||
executable_ldflags_vars,
|
executable_ldflags_vars,
|
||||||
shared_ldflags_vars):
|
shared_ldflags_vars,
|
||||||
|
is_msvc):
|
||||||
ext_build_dirs = inputs.ext_build_dirs
|
ext_build_dirs = inputs.ext_build_dirs
|
||||||
|
|
||||||
script = pkgconfig_script(ext_build_dirs)
|
script = pkgconfig_script(ext_build_dirs)
|
||||||
|
@ -26,7 +27,7 @@ def create_make_script(
|
||||||
|
|
||||||
script.append("##enable_tracing##")
|
script.append("##enable_tracing##")
|
||||||
|
|
||||||
ldflags_make_vars = get_ldflags_make_vars(executable_ldflags_vars, shared_ldflags_vars, workspace_name, flags, env_vars, deps, inputs)
|
ldflags_make_vars = get_ldflags_make_vars(executable_ldflags_vars, shared_ldflags_vars, workspace_name, flags, env_vars, deps, inputs, is_msvc)
|
||||||
|
|
||||||
make_commands = []
|
make_commands = []
|
||||||
for target in make_targets:
|
for target in make_targets:
|
||||||
|
@ -39,7 +40,7 @@ def create_make_script(
|
||||||
install_prefix = make_install_prefix,
|
install_prefix = make_install_prefix,
|
||||||
))
|
))
|
||||||
|
|
||||||
configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs, make_commands)
|
configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs, is_msvc, make_commands)
|
||||||
|
|
||||||
script.extend(["{env_vars} {command}".format(
|
script.extend(["{env_vars} {command}".format(
|
||||||
env_vars = configure_vars,
|
env_vars = configure_vars,
|
||||||
|
|
Loading…
Reference in New Issue