Skip to content

Commit 74d576f

Browse files
authored
fix(toolchain): symlink all toolchain files for the host toolchain (#1745)
Previously we would only symlink the interpreter binary itself when creating the hermetic host toolchain used in setting up the `whl_library` repositories. This works on UNIX platforms and Windows if they have the following in their `.bazelrc`: ``` startup --windows_enable_symlinks ``` In our CI we had the same lines but the users did not need to add them until the `0.29.0` forced them to have them because we actually started using symlinks on Windows. If the symlinks are not enabled on the host platform `bazel` tries to be helpful and copies the files over instead of making the links. We are leveraging this to just symlink all of the contents of the python interpreter repository for the host platform to the `_host` toolchain repository. Fixes #1723
1 parent 10580d6 commit 74d576f

15 files changed

Lines changed: 77 additions & 23 deletions

File tree

.bazelrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, execute
66
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
7-
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
8-
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
7+
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
8+
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
99

1010
test --test_output=errors
1111

@@ -19,7 +19,6 @@ build --incompatible_default_to_explicit_init_py
1919

2020
# Windows makes use of runfiles for some rules
2121
build --enable_runfiles
22-
startup --windows_enable_symlinks
2322

2423
# Make Bazel 6 use bzlmod by default
2524
common --enable_bzlmod

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ A brief description of the categories of changes:
3636
### Fixed
3737

3838
* (bzlmod) pip.parse now does not fail with an empty `requirements.txt`.
39+
3940
* (py_wheel) Wheels generated by `py_wheel` now preserve executable bits when
4041
being extracted by `installer` and/or `pip`.
42+
4143
* (coverage) During the running of lcov, the stdout/stderr was causing test
4244
failures. By default, suppress output when generating lcov. This can be
4345
overridden by setting 'VERBOSE_COVERAGE'. This change only affect bazel
4446
7.x.x and above.
4547

48+
* (toolchain) Changed the `host_toolchain` to symlink all files to support
49+
Windows host environments without symlink support.
50+
4651
### Added
4752

4853
* (py_wheel) Added `requires_file` and `extra_requires_files` attributes.

docs/sphinx/pypi-dependencies.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ use_repo(pip, "my_deps")
2727
For more documentation, including how the rules can update/create a requirements
2828
file, see the bzlmod examples under the {gh-path}`examples` folder.
2929

30+
We are using a host-platform compatible toolchain by default to setup pip dependencies.
31+
During the setup phase, we create some symlinks, which may be inefficient on Windows
32+
by default. In that case use the following `.bazelrc` options to improve performance if
33+
you have admin privileges:
34+
```
35+
startup --windows_enable_symlinks
36+
```
37+
38+
This will enable symlinks on Windows and help with bootstrap performance of setting up the
39+
hermetic host python interpreter on this platform. Linux and OSX users should see no
40+
difference.
41+
3042
### Using a WORKSPACE file
3143

3244
To add pip dependencies to your `WORKSPACE`, load the `pip_parse` function and

examples/build_file_generation/.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ test --test_output=errors --enable_runfiles
22

33
# Windows requires these for multi-python support:
44
build --enable_runfiles
5-
startup --windows_enable_symlinks
65

76
# The bzlmod version of this example is in examples/bzlmod_build_file_generation
87
# Once WORKSPACE support is dropped, this example can be entirely deleted.

examples/bzlmod/.bazelrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ test --test_output=errors --enable_runfiles
66

77
# Windows requires these for multi-python support:
88
build --enable_runfiles
9-
10-
startup --windows_enable_symlinks

examples/bzlmod_build_file_generation/.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ test --test_output=errors --enable_runfiles
22

33
# Windows requires these for multi-python support:
44
build --enable_runfiles
5-
startup --windows_enable_symlinks
65

76
common --experimental_enable_bzlmod
87

examples/multi_python_versions/.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ test --test_output=errors
22

33
# Windows requires these for multi-python support:
44
build --enable_runfiles
5-
startup --windows_enable_symlinks
65

76
coverage --java_runtime_version=remotejdk_11

examples/pip_parse_vendored/.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ test --test_output=errors
22

33
# Windows requires these for multi-python support:
44
build --enable_runfiles
5-
startup --windows_enable_symlinks
65

76
# Vendoring requirements.bzl files isn't necessary under bzlmod
87
# When workspace support is dropped, this example can be removed.

gazelle/.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ build --incompatible_default_to_explicit_init_py
1010

1111
# Windows makes use of runfiles for some rules
1212
build --enable_runfiles
13-
startup --windows_enable_symlinks
1413

1514
# Do NOT implicitly create empty __init__.py files in the runfiles tree.
1615
# By default, these are created in every directory containing Python source code

python/private/repo_utils.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _outputs_to_str(result):
223223
repo_utils = struct(
224224
execute_checked = _execute_checked,
225225
execute_unchecked = _execute_unchecked,
226-
execute_check_stdout = _execute_checked_stdout,
226+
execute_checked_stdout = _execute_checked_stdout,
227227
is_repo_debug_enabled = _is_repo_debug_enabled,
228228
debug_print = _debug_print,
229229
which_checked = _which_checked,

0 commit comments

Comments
 (0)