Repository navigation
fix(cc): link one CPython import library for py_extension on Windows #4427
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
Open
TrapsterDK
wants to merge
2
commits into
bazel-contrib:main
Choose a base branch
from
TrapsterDK:fix-win-single-import-lib
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| (cc) {obj}`py_extension` on Windows now links one CPython import library: the | ||
| stable ABI one (`python3.lib`) for limited API modules, else the versioned one. | ||
| Before, it passed both to the linker as a single argument | ||
| ([#4426](https://github.com/bazel-contrib/rules_python/issues/4426)). |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| load(":win_libs_tests.bzl", "win_libs_test_suite") | ||
|
|
||
| package( | ||
| default_testonly = True, | ||
| default_visibility = ["//visibility:private"], | ||
| ) | ||
|
|
||
| licenses(["notice"]) | ||
|
|
||
| win_libs_test_suite( | ||
| name = "win_libs_tests", | ||
| ) |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Tests for the CPython import library that py_extension links on Windows.""" | ||
|
|
||
| load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") | ||
| load("//python/cc:py_extension.bzl", "py_extension") | ||
| load("//tests/support:support.bzl", "CC_TOOLCHAIN") | ||
|
|
||
| # The Windows py_cc_toolchain goes last, since later extra_toolchains win: | ||
| # the one in CC_TOOLCHAIN has no target constraints. | ||
| def _config_settings(py_cc_toolchain): | ||
| return { | ||
| "//command_line_option:extra_toolchains": [ | ||
| CC_TOOLCHAIN, | ||
| str(Label("//tests/support/cc_toolchains:" + py_cc_toolchain)), | ||
| ], | ||
| "//command_line_option:platforms": [str(Label("//tests/support/platforms:windows_x86_64"))], | ||
| } | ||
|
|
||
| _CONFIG_SETTINGS = _config_settings("fake_py_cc_toolchain_windows") | ||
|
|
||
| def _test_limited_api(name): | ||
| py_extension( | ||
| name = name + "_pyext", | ||
| py_limited_api = "3.8", | ||
| tags = ["manual"], | ||
| ) | ||
| analysis_test( | ||
| name = name, | ||
| target = "_" + name + "_pyext_win_libs", | ||
| impl = _test_limited_api_impl, | ||
| config_settings = _CONFIG_SETTINGS, | ||
| ) | ||
|
|
||
| def _test_limited_api_impl(env, target): | ||
| env.expect.that_collection( | ||
| [f.basename for f in target[DefaultInfo].files.to_list()], | ||
| ).contains_exactly(["python3.lib"]) | ||
|
|
||
| def _test_no_limited_api(name): | ||
| py_extension( | ||
| name = name + "_pyext", | ||
| tags = ["manual"], | ||
| ) | ||
| analysis_test( | ||
| name = name, | ||
| target = "_" + name + "_pyext_win_libs", | ||
| impl = _test_no_limited_api_impl, | ||
| config_settings = _CONFIG_SETTINGS, | ||
| ) | ||
|
|
||
| def _test_no_limited_api_impl(env, target): | ||
| env.expect.that_collection( | ||
| [f.basename for f in target[DefaultInfo].files.to_list()], | ||
| ).contains_exactly(["python312.lib"]) | ||
|
|
||
| def _test_limited_api_versioned_only(name): | ||
| py_extension( | ||
| name = name + "_pyext", | ||
| py_limited_api = "3.8", | ||
| tags = ["manual"], | ||
| ) | ||
| analysis_test( | ||
| name = name, | ||
| target = "_" + name + "_pyext_win_libs", | ||
| impl = _test_limited_api_versioned_only_impl, | ||
| config_settings = _config_settings("fake_py_cc_toolchain_windows_versioned_only"), | ||
| ) | ||
|
|
||
| def _test_limited_api_versioned_only_impl(env, target): | ||
| env.expect.that_collection( | ||
| [f.basename for f in target[DefaultInfo].files.to_list()], | ||
| ).contains_exactly(["python312.lib"]) | ||
|
|
||
| def _test_no_limited_api_abi3_only(name): | ||
| py_extension( | ||
| name = name + "_pyext", | ||
| tags = ["manual"], | ||
| ) | ||
| analysis_test( | ||
| name = name, | ||
| target = "_" + name + "_pyext_win_libs", | ||
| impl = _test_no_limited_api_abi3_only_impl, | ||
| config_settings = _config_settings("fake_py_cc_toolchain_windows_abi3_only"), | ||
| ) | ||
|
|
||
| def _test_no_limited_api_abi3_only_impl(env, target): | ||
| env.expect.that_collection( | ||
| [f.basename for f in target[DefaultInfo].files.to_list()], | ||
| ).contains_exactly(["python3.lib"]) | ||
|
|
||
| def win_libs_test_suite(name): | ||
| test_suite( | ||
| name = name, | ||
| tests = [ | ||
| _test_limited_api, | ||
| _test_no_limited_api, | ||
| _test_limited_api_versioned_only, | ||
| _test_no_limited_api_abi3_only, | ||
| ], | ||
| ) |
This file contains hidden or 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
Oops, something went wrong.
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.
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.
Added
test_limited_api_versioned_onlyandtest_no_limited_api_abi3_only, using new single-library fake Windows toolchains in tests/support/cc_toolchains. Each checks that the sole library is kept.Assisted by Claude.