-
Notifications
You must be signed in to change notification settings - Fork 528
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
Implement 32-bit widestrings for Linux/WSL #1874
Comments
I think we should also create an issue at https://github.com/microsoft/DirectXShaderCompiler to understand the intended API shape on Linux targets. This could very well just be a bug on their part, resulting in possibly no work to be done here. |
And just to set expectations again - grumpy Windows guy here 😉 - while I have no interest in putting up roadblocks for developers, the windows-rs project is squarely about targeting Windows and specifically not about targeting non-Windows platforms. So I don't want to get in your way, but it's going to be a hard sell to add code specifically to support non-Windows targets, such as the alternative allocators you alluded to. On the other hand, I don't think anything prevents you from linking in your own implementations of functions like So if this is something that you need to support the DirectX Shader Compiler, I suggest you reach out to that team to see how they want to support this further. Happy to work with them as needed. |
* yawn *. Do we need to settle this grudge over a beer or something? It is getting old by now. Bring back As noted previously this project is still fresh and has trouble getting accustomed to outside contributions. As you also know I'm just a lone contributor, trying to leave the open-source space in a better position than I found it in. This means that I can tackle small things such as this miniscule addition to
Allocators are no must, but as explained
Note again that this is just as simple as a
I can reach out and create an issue, that's no problem. There's also microsoft/DirectXShaderCompiler#3210 requesting to get rid of widestrings entirely which would solve my issue, but it hasn't gained any traction in ±1.5 years. But again, I'm just a lone contributor and it'd be very inefficient to serve as a bridge between Microsoft Rust and Microsoft DXC folks. |
I hope you're joking about a grudge. We've come a long way in a short amount of time with cross-compilation and cross-platform support thanks to everyone's help... for a crate that's all about Windows. 😁
Typically, that's done by prepending the size in a header. You could even implement it using |
I'm not. As you say we were gaining traction in i.e. #1863 only to fall flat on our faces again here by denying the "Windows"-on-Linux case again. It's extremely tiring as I have no idea whether my contributions are useless (not to you / this project, but to me). Granted, that's exactly how I typically contribute to open-source projects: make crates better despite not actively using them (anymore). But I'd be extremely disappointed to have contributed here to make this crate even better than it already is only to never be able to use it because three-or-so
Good suggestion, I hadn't thought of doing it that way despite implementing this for In other words, here's how I feel we can approach this:
|
Adding a 32-bit Some suggestions to increase the chance of success:
|
Unfortunately, I don't see this as a trivial accommodation. Cross-platform support tends to be a rabbit hole of problems. From experience, it's never as simple as merely conditionally defining |
This is not my project so you're free to choose the easy way out.
Saying that you are open to working with DXSC folks if they confirm utf-32 +
That's how any (software) project exists, isn't it? Either someone, or some company, needs a (software) project, for personal/internal use or to sell? Alas, this is literally explained in the first paragraph in the top post. What gives?
Again, I redirect you to the top post. Can you be more specific about what isn't clear? |
[I'm an unpaid volunteer so please don't shoot the messenger.] The My initial suggestions were an attempt to help you build up a better argument for why Microsoft should spend time/money on this and take on the change risk, support burden, complexity, etc. The current argument is not very compelling. I think it's missing key data, such as but not limited to:
My suggestion for your next step is to open a DXSC issue that points out this cross-platform pain point, with a C++/Rust reproducible example. It's very possible the DXSC team will want to smooth out this developer experience and fix the APIs. I hope you stick to your guns and keep working on this! Happy to help fight for you where I can. |
Randomly stumbled upon microsoft/DirectXShaderCompiler#4242, indicating that 32-bit As pointed out above I don't want to be the bridge between Microsoft's DXC and Rust team beyond sparking an issue over at DXSC, but haven't had any meaningful response from @kennykerr detailing how to proceed. |
@riverar @kennykerr: created an issue over at DXC to discuss this, including possible solutions: microsoft/DirectXShaderCompiler#4742 I very much appreciate it if both of you could actively participate in the discussion, so that we can find a resolution that suits everyone in the end 🤩 👍 |
I've responded to the DXC issue, but figured I'd at least comment here to ping the relevant folks: microsoft/DirectXShaderCompiler#4742 (comment). Chiming in as a second Linux-ported COM component, we explicitly chose to use the platform native wide character ( So, to address these:
|
@jenatali Thank you for your insights, and sharing the fact that there are at least two Windows APIs that intentionally use 32-bit wide chars on Linux! Allow me to expand on your points a bit:
Not only that, DXC is used to compile HLSL to SPIR-V for use with Vulkan on Linux.
Exactly that. I don't understand why this question even has to be asked after I've submitted multiple issues and PRs to resolve the issue. Is my explanation, or code to solve it, somehow a fairy tail or magic smoke, and do people insist on seeing a branch that fails until a patch to If so, here is an older minimal example I have been working on: https://github.com/MarijnS95/windows-rs/commits/dxc2 On Linux, drop the last patch that gets in early
Because the Note that this branch also demonstrates #1842 by shimming necessary functions that are not available outside of Windows. Works a treat 🥳!
According to the main DXC developer that brought Linux support, this is very much intended: microsoft/DirectXShaderCompiler#4742 (comment)
Yes indeed, they provide Linux testing and artifacts on every commit.
None of the thin wrapper crates are actively maintained. They don't build off of Unless someone suggests to fork all of windows-rs just to make the necessary modifications, and keep that up to date somehow (please, no).
Yes, thanks for backing me up on this. I wouldn't know of any other API either. |
I cloned the example you provided and rolled back 1 commit (to 1e01916) per instructions, and am getting (on WSLv2):
|
@riverar That may be a mistake on my side: DXC's error-return API isn't known to be exactly clear, and I presume the UTF-8 error string isn't containing a friendly error message for you (this codepath is only called when |
@riverar I force-pushed a fix (more like workaround, though) to MarijnS95@4c130136 - thanks in advance for trying! MarijnS95@4c130136#diff-b9b4f35dbc7dd25c832aa5a60cecb0c7d754caa74704f911d55a140940aac4a5R100-R102 |
For completeness the branch pointed out above has just been rebased on latest EDIT: FWIW it was also brought up in microsoft/DirectXShaderCompiler#4742 (comment) that In addition windows-rs now uses the platform-native |
With recent work we've finally enabled
windows-rs
to run on Linux, many thanks for opening up 🥳!However, for my specific use-case of wrapping DirectXShaderCompiler in Rust there's one more thing I need. Widestring types are prevalent in the
DirectXShaderCompiler
API, but don't currently work on Linux.Wide chars and strings are typically 32-bit, with Windows being the exception rather than the rule at 16-bit. That is also how they're implemented in
DXC
when compiled for non-Windows, making them incompatible (read: segfaults) with the current UTF-16 "assumption" insidewindows
.To support this format we can "simply" apply some
cfg()
changes that turn the anyway-customBSTR
/P*WSTR
into*mut u32
-carrying structures, with an API to match. In my experiment I have simply written a:Problem 1: converting to and from
str
/String
In a previous (unaccepted) contribution I opted to use
widestring
, since it implements everything we need. That was (understandably) frowned upon as thewindows
crate should be the base for many other things, not the other way around (and not have many dependencies in any case).The
widestring
implementation simply uses.chars()
to acquire an iterator overchar
which is a "Unicode code point" but exactly fits UTF-32 chars too. It works and makes sense, but I'm no Unicode expert and don't know if this is the right way to implement it.Problem 2: Allocations and length
Current implementations use
HeapAlloc
+GetProcessHeap
+HeapFree
to store owned strings. As per #1842 we can leave it up to the users on non-Windows machines to provide fallbacks for these. However, it's probably more efficient and friendly to provide direct fallbacks behind acfg()
inwindows
(i.e. insideheap_alloc
andheap_free
, or inside the string implementations even).Regardless, this API is annoying/impossible to use correctly since most (all) Rust allocation APIs need to know the size of the allocation they're freeing. This includes a theoretical
Box::<[WCHAR]>
(where the slice has a dynamic size), andstd::alloc::dealloc
requires the same. Setting it to0
seems to work (the underlying allocator used on my machine doesn't care about the size) but I don't think that's a fair assumption/workaround to apply.Perhaps
Param::Boxed
can and should store this length? The string types can also have a.len()
function to compute it at runtime based on a null-character (orBSTR
s length-prefix).The text was updated successfully, but these errors were encountered: