# Compiling Rust binaries for Windows 98 SE and more: a journey

**URL:** <https://users.rust-lang.org/t/compiling-rust-binaries-for-windows-98-se-and-more-a-journey/43283>\
**Category:** announcements\
**Created:** [May 26, 2020, 5:08pm UTC](https://users.rust-lang.org/t/compiling-rust-binaries-for-windows-98-se-and-more-a-journey/43283 "2020-05-26T17:08:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seri](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/seri/32/15741_2.png) [@seri](https://users.rust-lang.org/u/seri)\
**Post date:** [May 26, 2020, 5:08pm UTC](https://users.rust-lang.org/t/compiling-rust-binaries-for-windows-98-se-and-more-a-journey/43283/1 "2020-05-26T17:08:44Z")

</div>

A journey through PE files, linkers, and the Rust source!

[https://seri.tools/blog/compiling-rust-for-legacy-windows/](https://seri.tools/blog/compiling-rust-for-legacy-windows/)

---

<div class="post-metadata">

**Author:** ![ZiCog](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/zicog/32/12216_2.png) [@ZiCog](https://users.rust-lang.org/u/ZiCog)\
**Post date:** [May 26, 2020, 5:21pm UTC](https://users.rust-lang.org/t/compiling-rust-binaries-for-windows-98-se-and-more-a-journey/43283/2 "2020-05-26T17:21:57Z")

</div>

My hat is off to you sir. That is craziness above and beyond the call of duty.

---

<div class="post-metadata">

**Author:** ![notriddle](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/notriddle/32/51307_2.png) [@notriddle](https://users.rust-lang.org/u/notriddle)\
**Post date:** [May 26, 2020, 5:55pm UTC](https://users.rust-lang.org/t/compiling-rust-binaries-for-windows-98-se-and-more-a-journey/43283/3 "2020-05-26T17:55:47Z")

</div>

> Implement an ANSI/Codepage based version of `OsStr` / `OsString` for Windows 9x systems, removing the need for `unicows`

Good luck with that.

There's an API implementation of [`AsRef<OsStr> for str`](https://doc.rust-lang.org/stable/std/primitive.str.html#implementations), which means that you have to write a function with the signature `fn (&'a str) -> &'a OsStr`; take a reference to a UTF-8 string, and return an OsStr reference with the same lifetime. About the only way that seems possible\* is if OsStr's byte representation is a superset of str's.

Are you're wondering how this works on Windows NT, where str is UTF-8 and the native wide strings are UTF-16? Rust's OsStr doesn't use the same byte-for-byte representation as native wide strings on Windows. Rust uses an encoding called WTF-8, which is a superset of UTF-8 that is also isomorphic with Windows wide string\*\*. This means that every time you pass an `OsString` to a Windows API, it performs an allocation.

I guess you could basically reimplement unicows yourself, keeping the OsString representation as WTF-8 but calling the A windows functions instead of the W variants and performing the conversion within libstd. But that sounds like a lot of boring drudgery to implement it, and you wouldn't really learn much about Win32 or Rust that way.

\* Short of degenerate implementations like panicking or returning the empty `&'static OsStr`, which would satisfy the function signature but not actually work.  
\*\* Windows wide strings are allowed content that isn't valid Unicode. WTF-8 allows the same content, because [that's actually the whole point](https://simonsapin.github.io/wtf-8/).

---

<div class="post-metadata">

**Author:** ![seri](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/seri/32/15741_2.png) [@seri](https://users.rust-lang.org/u/seri)\
**Post date:** [May 26, 2020, 6:04pm UTC](https://users.rust-lang.org/t/compiling-rust-binaries-for-windows-98-se-and-more-a-journey/43283/4 "2020-05-26T18:04:32Z")

</div>

Yeah, I've looked into how wide support is implemented, and upon reading about WTF-8 I've steered clear of digging deeper and followed the `unicows` way only, mostly to keep myself from going crazy and losing fun with this little project 🙂

> [@notriddle](#):
>
> I guess you could basically reimplement unicows yourself, keeping the OsString representation as WTF-8 but calling the A windows functions instead of the W variants and performing the conversion within libstd. But that sounds like a lot of boring drudgery to implement it, and you wouldn't really learn much about Win32 or Rust that way.

That seems like a viable strategy if someone were to do that, yeah!

Thanks for the insight! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [August 24, 2020, 6:04pm UTC](https://users.rust-lang.org/t/compiling-rust-binaries-for-windows-98-se-and-more-a-journey/43283/5 "2020-08-24T18:04:37Z")

</div>

Closed on August 24, 2020, 6:04pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
