Skip to content
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

feat(bzlmod): cross-platform builds without experimental_index_url #2325

Merged
merged 42 commits into from
Nov 7, 2024

Conversation

aignas
Copy link
Collaborator

@aignas aignas commented Oct 22, 2024

With this change we finally generate the same lock file within the
legacy code pip.parse code path and it allows to slowly transition to
using the new code path as much as possible without user doing anything.

This moves the selection of the host-compatible lock file from the
extension evaluation to the build phase - note, we will generate extra
repositories here which might not work on the host platform, however, if
the users are consuming the whl_library repos through the hub repo
only, then everything should work. A known issue is that it may break
bazel query and in these usecases it is advisable to use cquery
until we have sdist cross-building from source fully working.

Summary:

  • feat: reuse the render_pkg_aliases for when filename is not known
    but platform is known
  • feat: support generating the extra config settings required
  • feat: get_whl_flag_versions now generates extra args for the rules
  • feat: make lock file generation the same irrespective of the host
    platform
  • test: add an extra test with multiple requirements files
  • feat: support cross-platform builds using download_only = True in
    legacy setups

Note, that users depending on the naming of the whl libraries will need
to start using extra_hub_aliases attribute instead to keep their
setups not relying on this implementation detail.

Fixes #2268
Work towards #260

@aignas aignas marked this pull request as draft October 22, 2024 02:49
@aignas aignas marked this pull request as ready for review October 22, 2024 02:56
@aignas
Copy link
Collaborator Author

aignas commented Oct 22, 2024

@keith, could you please check to see if this is fixing the issues you were seeing previously? The CI is not fully green, but the examples and unit tests are passing, so I think this might be ready for a spin.

"repo": "pypi_315",
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
},
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy that my selection of the mock ctx.os values was already validating the bug in question.

@keith
Copy link
Member

keith commented Oct 22, 2024

it's possible it's just fighting getting the lockfile updated, but with this i see:

% bz mod graph --lockfile_mode=update
ERROR: module extension "pip" from "@@rules_python~//python/extensions:pip.bzl" does not generate repository "pip_deps_311_torch", yet it is imported as "pip_deps_311_torch" in the usage at .../MODULE.bazel:237:20 (did you mean 'pip_deps_311_munch'?). Type 'bazel help mod' for syntax and help.

looks like i hit that with or without experimental_index_url

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
file irrespective if `experimental_index_url` is set by any module or not.
Fixes [#2268](https://github.com/bazelbuild/rules_python/issues/2268). A known
issue is that it may break `bazel query` and in these usecases it is advisable
to use `cquery` until we have `sdist` cross-building from source fully working.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

download_only=True is also an option, right? Assuming one is OK with not having sdists

Copy link
Collaborator Author

@aignas aignas Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be, but I haven't tested with regular requirements files, let me add a unit test to see how that would get wired through.

EDIT: With a few extra modifications, I think we can actually support that. This means that we can resolve #260 and have the stabilization for experimental_index_url done as a separate ticket. I've added extra docs on this, please check. :)

python/private/pypi/extension.bzl Outdated Show resolved Hide resolved
@aignas
Copy link
Collaborator Author

aignas commented Oct 22, 2024

it's possible it's just fighting getting the lockfile updated, but with this i see:

% bz mod graph --lockfile_mode=update
ERROR: module extension "pip" from "@@rules_python~//python/extensions:pip.bzl" does not generate repository "pip_deps_311_torch", yet it is imported as "pip_deps_311_torch" in the usage at .../MODULE.bazel:237:20 (did you mean 'pip_deps_311_munch'?). Type 'bazel help mod' for syntax and help.

looks like i hit that with or without experimental_index_url

@keith, I should have explained better in the PR message/changelog, that with this change you will have multiple torch variants registered and they will be pip_deps_311_torch__{'_'.join(target_platforms)}. The spoke repository naming is an implementation and should not be relied on too much. What are you using from the spoke repository? Some headers? In this case the best option would be to use @pip_deps//torch and whl_filegroup or similar to do that, what do you think?

aignas and others added 9 commits October 23, 2024 08:48
Co-authored-by: Richard Levasseur <richardlev@gmail.com>
We won't have correct dependencies when parsing the METADATA
files because we need to pass the target platforms there. I
think I got too happy too soon about the possibility of having
correct builds with just 'download_only = True'.
@rickeylev
Copy link
Collaborator

That is only needed if cc_library is unhappy with an empty file.

cc_library is OK with empty srcs

@aignas aignas marked this pull request as draft November 1, 2024 14:24
@aignas
Copy link
Collaborator Author

aignas commented Nov 4, 2024

OK, quick status update - once #2369 is merged, I will update this PR to be
backwards compatible (i.e. users will have to opt into the new behaviour on
0.38.0) and then merge this PR. Then we can cut a release. Once that is done,
we can have our 1.0 I think.

@aignas aignas mentioned this pull request Nov 4, 2024
10 tasks
github-merge-queue bot pushed a commit that referenced this pull request Nov 5, 2024
…repos (#2369)

Before this change, it was impossible for users to use the targets
created with `additive_build_content` whl annotation unless they relied
on the implementation detail of the naming of the spoke repositories and
had `use_repo` statements in their `MODULE.bazel` files importing the
spoke repos.

With #2325 in the works, users will have to change their `use_repo`
statements, which is going to be disruptive. In order to offer them an
alternative for not relying on the names of the spokes, there has to be
a way to expose the extra targets created and this PR implements a
method. Incidentally, the same would have happened if we wanted to
stabilize the #260 work and mark `experimental_index_url` as
non-experimental anymore.

I was hoping we could autodetect them by parsing the build content
ourselves in the `pip` extension, but it turned out to be extremely
tricky and I figured that it was better to have an API rather than not
have it.

Whilst at it, also relax the naming requirements for the
`whl_modifications` attribute.

Fixes #2187
@aignas aignas marked this pull request as ready for review November 5, 2024 13:57
@aignas
Copy link
Collaborator Author

aignas commented Nov 5, 2024

@keith, could you please check this PR again? I think it should work for your usecase now.

@keith
Copy link
Member

keith commented Nov 5, 2024

Yes sorry I'm OOO but I will as soon as I'm back next week

@aignas
Copy link
Collaborator Author

aignas commented Nov 7, 2024

Since the behaviour is opt-in, I'll merge the PR now and we can make further fixes later, but I am still looking forward to feedback next week.

@aignas aignas added this pull request to the merge queue Nov 7, 2024
Merged via the queue into bazelbuild:main with commit d66e55c Nov 7, 2024
4 checks passed
@keith
Copy link
Member

keith commented Nov 20, 2024

I think I could probably make whl_filegroup work, but it definitely breaks some use cases we're using today. For example today in my additive_build_content_file I do this:

_LIBS = [
    lib
    for lib in glob(
        [
            "site-packages/torch/lib/*.so*",
            "site-packages/torch.libs/*.so*",
            "site-packages/torch/lib/*.dylib",
        ],
        allow_empty = True,
        exclude = [
            "site-packages/torch/lib/*libgomp*",  # Handled below
            # Intel only, seem to be unnecessary for our use case
            "**/libtorchbind_test*",
            "**/libbackend_with_compiler*",
            "**/libjitbackend_test*",
        ],
    )
]

And then I expand multiple targets based on the _LIBS list below using list comprehensions. I don't think this has a clear 1:1 since if I had these as a filegroup it would not be the same

@keith
Copy link
Member

keith commented Nov 20, 2024

seems like one option is this:

    extra_hub_aliases = {
        "torch": [
            "stock-torch",
            "stock-torch-headers",
            "stock-torch-api",
            "torchlib",
        ],
        "torchvision": ["torchvisionpy"],
    },

which pretty much gets me back to what i had before, is that one not recommended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

experimental_index_url in dependency tree breaks other pip.parse includes
3 participants