Skip to content

Add Windows build #893

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
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add Windows build #893

wants to merge 4 commits into from

Conversation

mtsokol
Copy link
Contributor

@mtsokol mtsokol commented Jun 3, 2025

Here's a PR with Windows build support, without array_record dependency.

Outdated:

  • I think it's worth considering to switch to setup-bazel and setup-python Actions for Bazel and Python setup for all environments, rather than downloading and installing them in the script.
    I couldn't make it work with the current pyenv and bazel installation on Windows - switching to GitHub Actions worked out of the box.
  • The Bazel setup complained about Module.bazel dependencies versions - I upgraded them.
  • It seems that as of now the wheel build is blocked by array-record - package: https://pypi.org/project/array-record/#history. The current setup requires 0.7.2 but Windows wheels for it are missing and the last one goes back to 0.4.1: https://github.com/mtsokol/grain/actions/runs/15418522140/job/43387085894.
    I think that first we need to make sure that all dependencies have Windows distributions.

📚 Documentation preview 📚: https://google-grain--893.org.readthedocs.build/

@iindyk
Copy link
Collaborator

iindyk commented Jun 9, 2025

thanks Mateusz!

I think it's worth considering to switch to setup-bazel and setup-python Actions for Bazel and Python setup for all environments, rather than downloading and installing them in the script.

Agree, would you be able to try this out? maybe in a separate PR to make things easier

The Bazel setup complained about Module.bazel dependencies versions - I upgraded them.

this part is tricky, especially the protobuf dependency version. Downstream users are very sensitive to it. In particular, TensorFlow has pretty old protobuf dependency and using the newer ones may result into a crash in the env with grain + tensorflow. We wouldn't want that ideally. Would it be possible to not upgrade the dependencies yet? were the complaints errors?

It seems that as of now the wheel build is blocked by array-record - package

yeah, there's an ongoing work to fix array-record build (it's broken at main), once that is in, or folks will add Windows build. For now, we shouldn't block on that (i.e. let the install fail, at least verify that we can build wheels).

@mtsokol
Copy link
Contributor Author

mtsokol commented Jun 9, 2025

Agree, would you be able to try this out? maybe in a separate PR to make things easier

Sure! I'll take care of it.

Would it be possible to not upgrade the dependencies yet? were the complaints errors?

I think I upgraded only those that otherwise gave a dependency resolve error. But I can rerun it and paste details here - maybe there's a workaround for it.

@mtsokol
Copy link
Contributor Author

mtsokol commented Jun 10, 2025

@iindyk some updates:

  • Opened refactor PR: Move Bazel and Python installation to GitHub Action #900 <- let's merge it first, then I'll rebase this one.
  • Indeed dependencies doesn't need to be updated. Once I figured out how to pin Bazel version on installation USE_BAZEL_VERSION: "7.1.1" the current setup is fine, so I reverted these changes.
  • About the array-record: Currently bazel build fails with missing array-record for Windows. BUILD file requires it, so letting it fail means, bazel build fails, so we can't build the wheel anyway (i.e. we rsync bazel-bin/grain outputs to the wheel build directory). Am I missing anything?

@mtsokol mtsokol force-pushed the windows-build branch 2 times, most recently from 0bf68ef to e205ea8 Compare June 10, 2025 18:34
@iindyk
Copy link
Collaborator

iindyk commented Jun 10, 2025

Am I missing anything?

no, you're right. Would you be able to fork our build and publish workflow (no need for nightly) with added windows support and send out a PR to array-record? I will be able to submit it from inside and add trusted publishing. We can submit this in Grain either way, and test after AR release with Windows.

here's the workflow I used for the last release: https://github.com/iindyk/array_record/blob/main/.github/workflows/build_and_publish.yml

@mtsokol mtsokol marked this pull request as ready for review July 3, 2025 10:21
@mtsokol mtsokol changed the title Windows build Add Windows build Jul 3, 2025
@@ -46,6 +46,9 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install rsync for Windows

This comment was marked as resolved.

@@ -21,7 +21,7 @@ bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "platforms", version = "0.0.9")
bazel_dep(name = "rules_python", version = "0.37.0")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "pybind11_bazel", version = "2.11.1")
bazel_dep(name = "pybind11_bazel", version = "2.11.1.bzl.3")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Building extension modules on Windows was fixed in that release: https://github.com/pybind/pybind11_bazel/releases/tag/v2.11.1.bzl.3

import threading
import time
import typing
from typing import Any, Generic, Optional, Protocol, SupportsIndex, TypeVar, Union

from absl import logging
import array_record.python.array_record_data_source as array_record
from etils import epath
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't use from etils import epy; epy.lazy_imports() as Union didn't allow epy's returned type.

*)
INCLUDE_EXT="*.so"
# Also reduce noise during build.
write_to_bazelrc "build --cxxopt=-Wno-deprecated-declarations --host_cxxopt=-Wno-deprecated-declarations"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I searched it and AFAIK There are no counterparts in MSVC.

@mtsokol
Copy link
Contributor Author

mtsokol commented Jul 3, 2025

Hi @iindyk,

The Windows build for Grain is ready for review. I made minimal changes that were required to make it work, incl. array_record as an optional dependency.

Here's a successful build in my fork: https://github.com/mtsokol/grain/actions/runs/16052901995

rsync -avm -L --exclude="__pycache__/*" grain "${TMPDIR}"
rsync -avm -L --include="*.so" --include="*_pb2.py" \

rsync -avm -L --exclude="__pycache__/*" grain tmp_folder
Copy link
Contributor Author

@mtsokol mtsokol Jul 3, 2025

Choose a reason for hiding this comment

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

This one was pretty tricky. Installed rsync (cygwin version) had a problem with absolute paths in Windows, namely for /tmp folder, as on Windows it's c:\users\runner~1\appdata\local\temp\, causing:

ssh: Could not resolve hostname c: Name or service not known

thinking that Windows C:\... path means some server C. So I'm using an intermediate folder, and then copy to the desired one (doesn't matter on Linux/MacOS).

Here's the same issue on SO:
https://stackoverflow.com/questions/51536762/rsync-does-not-recognize-windows-path

Copy link
Collaborator

Choose a reason for hiding this comment

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

could you pls add a comment about the intermediate folder here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@mtsokol mtsokol force-pushed the windows-build branch 6 times, most recently from 8193c75 to 6255902 Compare July 3, 2025 14:12
if: runner.os == 'Windows'
run: |
echo "TEMP_DIR=${PWD}" >> $GITHUB_ENV
echo "WHL_DIR=." >> $GITHUB_ENV
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had an issue with missing wheel files, looks like absolute paths on Windows aren't supported in actions/upload-artifact: actions/upload-artifact#519 (comment)

Comment on lines +33 to +36
data = select({
"@platforms//os:windows": ["//grain/_src/python/experimental/index_shuffle/python:index_shuffle_module.pyd"],
"//conditions:default": ["//grain/_src/python/experimental/index_shuffle/python:index_shuffle_module.so"],
}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does Bazel allow to do it in a more concise manner? (Move path to a variable an glue the extension separately?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure, I think this is ok

Copy link
Collaborator

@iindyk iindyk left a comment

Choose a reason for hiding this comment

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

thanks Mateusz!

Comment on lines +33 to +36
data = select({
"@platforms//os:windows": ["//grain/_src/python/experimental/index_shuffle/python:index_shuffle_module.pyd"],
"//conditions:default": ["//grain/_src/python/experimental/index_shuffle/python:index_shuffle_module.so"],
}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure, I think this is ok

from grain._src.python.experimental.index_shuffle.python import index_shuffle_module as index_shuffle

with epy.lazy_imports():
from grain._src.python.experimental.index_shuffle.python import index_shuffle_module as index_shuffle
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this import not work on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right - this doesn't import array_record and works on Windows, reverted.

rsync -avm -L --exclude="__pycache__/*" grain "${TMPDIR}"
rsync -avm -L --include="*.so" --include="*_pb2.py" \

rsync -avm -L --exclude="__pycache__/*" grain tmp_folder
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you pls add a comment about the intermediate folder here?

@mtsokol mtsokol requested a review from iindyk July 18, 2025 09:44
@mtsokol
Copy link
Contributor Author

mtsokol commented Jul 18, 2025

@iindyk I addressed your comments. In the follow-up I will add skips for 10 tests that fail on windows (e.g. due to unix-like paths in assert strings or compile_pip_requirements tests that check for array_record) and move JAX tests to pytest, so that CI with "Run unit tests" option will pass.

copybara-service bot pushed a commit that referenced this pull request Jul 18, 2025
PORTED FROM #893

PiperOrigin-RevId: 784697196
@copybara-service copybara-service bot mentioned this pull request Jul 18, 2025
copybara-service bot pushed a commit that referenced this pull request Jul 18, 2025
PORTED FROM #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 18, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 18, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 18, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 18, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 21, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 21, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 21, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 21, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 21, 2025
Ported from #893

PiperOrigin-RevId: 784697196
copybara-service bot pushed a commit that referenced this pull request Jul 21, 2025
Ported from #893

PiperOrigin-RevId: 785285748
@mtsokol
Copy link
Contributor Author

mtsokol commented Jul 22, 2025

Should we close this PR?

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.

2 participants