-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
BLD Reduce generated build file path lengths to avoid Windows path length limitation #31212
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
BLD Reduce generated build file path lengths to avoid Windows path length limitation #31212
Conversation
Weird failure in Ubuntu Atlas CI build doesn't seem related ? From failing build log. Merging
|
I haven't run into this before. I agree the generated paths look overly long, so perhaps that can be improved. @eli-schwartz may be able to confirm. The subfolder name repetition after |
Previously: mesonbuild/meson#10788 |
This may possibly be motivated by a desire to identify and disambiguate between the possibility of having a single target which compiles multiple source files:
They can't both be generated outright as build/mytarget.cpython-313-x86_64-linux-gnu.so.p/util.pyx.cpp And the "simplest" answer for how to distinguish them is "just add the original path in there, and people can also investigate the build by simply matching the source path with the generated path". At least in this case you don't have to deal with both path_max and filename_max... |
@lesteve as suggested in the comment. I created a "long path" |
Thanks @vitorpohlenz for taking the time to test this PR 🙏! I was rather confident the work-around in this PR would make it less likely to hit long path limitation on Windows, but it's definitely useful to have an external confirmation. |
@eli-schwartz thanks for your inputs, super useful! I indeed thought about something like this but my guess is that using two |
@eli-schwartz I had a quick and dirty attempt that seems to agree with my initial intuition that it isn't possible to have two This SO question seems to go towards the same direction although I have to admit I did not read everything in details 😅. Here is my quick and dirty attempt, I added the following to py.extension_module(
'combined',
['test1.pyx', 'test2.pyx'],
cython_args: cython_args,
subdir: 'sklearn/cluster',
install: true,
)
py.extension_module(
'test1',
['test1.pyx'],
cython_args: cython_args,
subdir: 'sklearn/cluster',
install: true,
)
py.extension_module(
'test2',
['test2.pyx'],
cython_args: cython_args,
subdir: 'sklearn/cluster',
install: true,
) Here is what I get when I try to import the built modules:
Traceback (most recent call last):
File "<string>", line 1, in <module>
from sklearn.cluster import combined
ImportError: dynamic module does not define module export function (PyInit_combined) The content of the # test1.pyx
def test1(): pass # test2.pyx
def test2(): pass |
Indeed, it's not possible to combine two |
Given that pxd exists I suppose having multiple pyx could be seen as rather redundant. The only actual potential for a distinction between the two would be the ability to parallel-compile the module unit in individual chunks.
... which appears to be about having a single final Because it (multiple source files per installable output artifact) is, however, very much allowed for say vala, which is a language meson supports similarly to cython, in that it is transpiled to C and then the C is compiled. Maybe it makes sense to only use the file basename, for cython specifically. That's entirely possible, and if this is changed directly in meson then you can take advantage of builtin cython support while still playing nice with the Windows tempdir etc.
... and e.g. vala handles this because in vala, you have to write your own main() entrypoint, thus it doesn't try to autogenerate one into every file and you don't end up with two entrypoints in one built installable artifact. |
That would indeed seem like a good option if it is feasible on the meson side.
I will be AFK for a few weeks, so it's definitely not going to happen short-term, but it did not seem like the automatic shortening of path from mesonbuild/meson#10788 actually was kicking in in the issues we saw on Windows in a scikit-learn context. Maybe the heuristics of for "filepaths with >5 components" was not met? Full disclosure: I did not read mesonbuild/meson#10788 in enough details, so I'll try to look at it in more details when I am back. |
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.
LGTM. +1 to go with this solution for now
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.
Would be nice for meson to fix this, but for now I guess this can do.
This should reduce the path length of our build files, making more likely to avoid the long path issues when building from source on Windows, see #31149 (comment) and #31123 (comment).
I feel this PR doesn't over-complicate the
meson.build
files while making it less likely that the long path limitation is reached on Windows.FWIW, scipy is using
generator
, maybe in part for historical reasons, since Cython was not supported by meson at the beginning.cc @rgommers in case you have heard of similar cases of meson generated files path length limitations on Windows. Also do you think it is worth opening a meson issue to ask if they would consider creating the generate
.c
or.cpp
files in a less nested folder (maybe there is a reason behind it, not sure ...)?How it works
Our longest generated file relative path is currently 201 characters , with this PR it would be 151 characters. What matters is the absolute path length and with the temporary build env created by pip you easily reach the long path limit (plus the default temp dir
%TMP
is quite long on WindowsC:\Users\<user_name>\AppData\Local\Temp
). The Windows long path limit is 260 characters (i.e. something likeC:\path-with-max-256-characeters<NULL_CHARACTER>
) according to the Windows doc.By using a meson generator to run
cython
rather than meson built-in cython functionality, the generated.c
or.cpp
file is created in a less nested folder. For example the longest generated file relative path right now is the following one (201 characters)With this PR it is 151 characters (notice the second
sklearn/metrics/_pairwise_distances_reduction
has been removed +.pyx.cpp -> .cpp
. In total, 50 characters has been removed):