Closed hutm closed 10 months ago
Yeah, you should be able to do this by tweaking the system_cxx_toolchain
rule. I'll put up a change for this internally, but this is what you need:
diff --git a/fbcode/buck2/prelude/toolchains/cxx.bzl b/fbcode/buck2/prelude/toolchains/cxx.bzl
--- a/fbcode/buck2/prelude/toolchains/cxx.bzl
+++ b/fbcode/buck2/prelude/toolchains/cxx.bzl
@@ -18,7 +18,7 @@
)
load("@prelude//cxx:headers.bzl", "HeaderMode")
load("@prelude//cxx:linker.bzl", "is_pdb_generated")
-load("@prelude//linking:link_info.bzl", "LinkStyle")
+load("@prelude//linking:link_info.bzl", "LinkOrdering", "LinkStyle")
load("@prelude//linking:lto.bzl", "LtoMode")
load("@prelude//toolchains/msvc:tools.bzl", "VisualStudio")
load("@prelude//utils:cmd_script.bzl", "ScriptOs", "cmd_script")
@@ -111,6 +111,7 @@
force_full_hybrid_if_capable = False,
is_pdb_generated = is_pdb_generated(linker_type, ctx.attrs.link_flags),
produce_interface_from_stub_shared_library = True,
+ link_ordering = ctx.attrs.link_ordering,
),
bolt_enabled = False,
binary_utilities_info = BinaryUtilitiesInfo(
@@ -182,6 +183,7 @@
"cxx_compiler": attrs.string(default = "cl.exe" if host_info().os.is_windows else "clang++"),
"cxx_flags": attrs.list(attrs.string(), default = []),
"link_flags": attrs.list(attrs.string(), default = []),
+ "link_ordering": attrs.option(attrs.enum(LinkOrdering.values()), default = None),
"link_style": attrs.string(default = "shared"),
"linker": attrs.string(default = "link.exe" if host_info().os.is_windows else "clang++"),
"linker_wrapper": attrs.default_only(attrs.exec_dep(providers = [RunInfo], default = "prelude//cxx/tools:linker_wrapper")),
Then when you instantiate it (in toolchains/BUCK
), add link_ordering = "topological"
to the attrs.
thanks @krallin , that indeed resolved the issue. Closing this
Liker fails with
undefined symbols
. Target c++ binary depends on libcurl, which depends on libssl.//common:init
depends on libfolly, which also depends on libssl.inspecting argfile for linker suggests that dependency graph is not respected: libssl appears before libcurl and causes linker error.
Buck1 handles dependency graph correctly and the binary can be linked successfully;
Is there a configuration parameter in cxx toolchain to resolve the issue?