-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update LibrariesToLinkCollector.java for .dll suffix stripping #21404
Closed
vvviktor
wants to merge
2
commits into
bazelbuild:master
from
vvviktor:feature/dll-stripping-support
Closed
Update LibrariesToLinkCollector.java for .dll suffix stripping #21404
vvviktor
wants to merge
2
commits into
bazelbuild:master
from
vvviktor:feature/dll-stripping-support
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fmeum
approved these changes
Feb 28, 2024
meteorcloudy
approved these changes
Feb 28, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
@bazel-io fork 7.1.0 |
bazel-io
pushed a commit
to bazel-io/bazel
that referenced
this pull request
Feb 29, 2024
Fixes bazelbuild#19696 Allow automatic linkage of DLL libraries when GNU toolchain used in Windows. .dll suffix has to be stripped before passing library name to `ld.exe` with `-l` option. This [case](https://github.com/vvviktor/bazel_sandbox.git) was successfully tested : Workspace structure: ``` D:. │ .bazelrc │ BUILD │ MODULE.bazel │ MODULE.bazel.lock │ WORKSPACE │ ├───Main │ BUILD │ main.cpp │ math.cpp │ math.h │ math_dll_interface.cpp │ math_dll_interface.h │ math_import_defs.h │ └───toolchain BUILD toolchain_config.bzl ``` BUILD file: ``` # //Main/BUILD DLL_HDRS = ["math_import_defs.h", "math_dll_interface.h"] cc_binary( name = "sum_numbers_mingw", srcs = ["main.cpp"], deps = [":math_d_shared"] ) cc_import( name = "math_d_shared", hdrs = DLL_HDRS, shared_library = ":libmath_d.dll" ) cc_binary( name = "libmath_d.dll", srcs = ["math_dll_interface.cpp"] + DLL_HDRS, deps = [":math"], defines = ["MATH_DLL"], linkshared = 1 ) cc_library( name = "math", srcs = ["math.cpp"], hdrs = ["math.h"], copts = ["-std=c++17"] ) ``` Without patch applied `bazel build //main:sum_numbers_mingw --verbose_failures` fails with error: `C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmath_d.dll: No such file or directory` Then after patch was applied it builds all targets as expected. This approach also works fine with patch applied: ``` # //Main/BUILD DLL_HDRS = ["math_import_defs.h", "math_dll_interface.h"] cc_binary( name = "sum_numbers_mingw", srcs = ["main.cpp"] + DLL_HDRS, dynamic_deps = [":math_d_shared"] ) cc_shared_library( name = "math_d_shared", shared_lib_name = "libmath_d.dll", deps = [":math_dll_interface"] ) cc_library( name = "math_dll_interface", srcs = ["math_dll_interface.cpp"], hdrs = DLL_HDRS, deps = [":math"], defines = ["MATH_DLL"] ) cc_library( name = "math", srcs = ["math.cpp"], hdrs = ["math.h"], copts = ["-std=c++17"] ) ``` Closes bazelbuild#21404. PiperOrigin-RevId: 611401823 Change-Id: I98fbfb245acdd2dac41d6a56b5f74059dc53a082
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 4, 2024
#21524) Fixes #19696 Allow automatic linkage of DLL libraries when GNU toolchain used in Windows. .dll suffix has to be stripped before passing library name to `ld.exe` with `-l` option. This [case](https://github.com/vvviktor/bazel_sandbox.git) was successfully tested : Workspace structure: ``` D:. │ .bazelrc │ BUILD │ MODULE.bazel │ MODULE.bazel.lock │ WORKSPACE │ ├───Main │ BUILD │ main.cpp │ math.cpp │ math.h │ math_dll_interface.cpp │ math_dll_interface.h │ math_import_defs.h │ └───toolchain BUILD toolchain_config.bzl ``` BUILD file: ``` # //Main/BUILD DLL_HDRS = ["math_import_defs.h", "math_dll_interface.h"] cc_binary( name = "sum_numbers_mingw", srcs = ["main.cpp"], deps = [":math_d_shared"] ) cc_import( name = "math_d_shared", hdrs = DLL_HDRS, shared_library = ":libmath_d.dll" ) cc_binary( name = "libmath_d.dll", srcs = ["math_dll_interface.cpp"] + DLL_HDRS, deps = [":math"], defines = ["MATH_DLL"], linkshared = 1 ) cc_library( name = "math", srcs = ["math.cpp"], hdrs = ["math.h"], copts = ["-std=c++17"] ) ``` Without patch applied `bazel build //main:sum_numbers_mingw --verbose_failures` fails with error: `C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmath_d.dll: No such file or directory` Then after patch was applied it builds all targets as expected. This approach also works fine with patch applied: ``` # //Main/BUILD DLL_HDRS = ["math_import_defs.h", "math_dll_interface.h"] cc_binary( name = "sum_numbers_mingw", srcs = ["main.cpp"] + DLL_HDRS, dynamic_deps = [":math_d_shared"] ) cc_shared_library( name = "math_d_shared", shared_lib_name = "libmath_d.dll", deps = [":math_dll_interface"] ) cc_library( name = "math_dll_interface", srcs = ["math_dll_interface.cpp"], hdrs = DLL_HDRS, deps = [":math"], defines = ["MATH_DLL"] ) cc_library( name = "math", srcs = ["math.cpp"], hdrs = ["math.h"], copts = ["-std=c++17"] ) ``` Closes #21404. Commit e2837db PiperOrigin-RevId: 611401823 Change-Id: I98fbfb245acdd2dac41d6a56b5f74059dc53a082 Co-authored-by: Viktor Kustov <[email protected]> Co-authored-by: Yun Peng <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #19696
Allow automatic linkage of DLL libraries when GNU toolchain used in Windows. .dll suffix has to be stripped before passing library name to
ld.exe
with-l
option.This case was successfully tested :
Workspace structure:
BUILD file:
Without patch applied
bazel build //main:sum_numbers_mingw --verbose_failures
fails with error:C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmath_d.dll: No such file or directory
Then after patch was applied it builds all targets as expected.
This approach also works fine with patch applied: