[HN Gopher] Rust9x: Compile Rust code for Windows 95, NT and above
       ___________________________________________________________________
        
       Rust9x: Compile Rust code for Windows 95, NT and above
        
       Author : seritools
       Score  : 139 points
       Date   : 2022-04-21 17:14 UTC (5 hours ago)
        
 (HTM) web link (seri.tools)
 (TXT) w3m dump (seri.tools)
        
       | Dwedit wrote:
       | This looks really neat!
       | 
       | I wonder if it has been tested on Win32s or HXDOS. HXDOS is very
       | friendly about that kinds of program it accepts, for example, the
       | console version of 7-zip will run fine on HXDOS.
        
         | seritools wrote:
         | If you go `no_std` I'm confident both would work - I think the
         | current windows stdlib implementation still might be too much
         | for those.
        
       | melony wrote:
       | How did you generate the Visual Rust cover image? I love it.
        
         | seritools wrote:
         | Vector graphics tool and manually changed the kerning on each
         | letter to match the OG Visual Studio covers. The background
         | effect is just the regular rust logo copied twice :)
        
       | algesten wrote:
       | I approve of ureq being used on Windows 95 :)
       | 
       | (I'm the original author)
        
         | seritools wrote:
         | Heck yeah! Thanks for writing it!
        
       | YakBizzarro wrote:
       | Next step: Windows 3.11 using the win32s API :)
        
         | seritools wrote:
         | Oh trust me I've thought about that :)
         | 
         | It depends on two things:
         | 
         | - is the supported API surface big enough?
         | 
         | - is there an msvc runtime that can be linked with a somewhat
         | modern linker (so that rust/llvm don't get angry) but that
         | still works under Win32s. I'm not sure that exists, though :c
        
           | Dwedit wrote:
           | I know that Win32s requires that the EXE have a RELOC
           | section, so it must be built with relocation enabled.
           | 
           | I hope you don't need to go all the way to /NODEFAULTLIB
           | though, that kind of configuration is a big headache to build
           | on.
           | 
           | Is there a .lib file for "msvcrt.dll" that will work with
           | /NODEFAULTLIB? If so, I wonder if there is a Win32s
           | compatible binary for that.
        
             | seritools wrote:
             | > that kind of configuration is a big headache to build on
             | 
             | Not really, I've done just that (though in the end I didn't
             | need full /NODEFAULTLIB):
             | 
             | https://github.com/rust9x/rust9x-sample/blob/main/.cargo/co
             | n...
             | 
             | With older msvcrt libraries you only need to link
             | `libcmt.lib`/`msvcrt.lib`, that's it. Visual C++ 4.0 is
             | apparently the last version to support Win32s, so if you
             | can make it link to its libraries you might have a chance!
        
           | userbinator wrote:
           | Biggest difference would probably be the complete lack of
           | multithreading.
        
             | zozbot234 wrote:
             | Win32s applications (like Win16 applications more
             | generally) run in a shared address space with cooperative
             | multitasking. They're basically async applications within
             | an OS-provided runtime.
        
             | seritools wrote:
             | Oh right, that's also a thing :v
        
       | pavon wrote:
       | I wonder if this might be even more useful for ReactOS, which is
       | still actively supporting 32-bit x86, while Windows 11 no longer
       | does.
        
         | seritools wrote:
         | Just grabbed the latest ISO to test it out :) -
         | rust9x_sample.exe sadly only works in 98/Me compatibility mode.
         | https://i.imgur.com/nWCfTtV.png
         | 
         | In regular mode it seems there's a problem with the system not
         | setting the file pointer to the end when OpenOptions::append is
         | used: https://i.imgur.com/vvbEnWh.png https://doc.rust-
         | lang.org/std/fs/struct.OpenOptions.html#met...
        
           | jeroenhd wrote:
           | This sounds like you've found a bug in either the Rust
           | standard library or the ReactOS API implementation. It might
           | be worth looking into this!
        
             | seritools wrote:
             | To clarify, it works in 98/Me mode because I added a
             | fallback implementation to Rust9x for these systems, as the
             | flag in question is not supported.
             | 
             | AFAICT it is supported since NT 3.1, though, and it worked
             | fine on all NT-based systems I've tested so far, so my
             | guess would be a ReactOS API bug.
             | 
             | The commit adding the 9x/Me fallback implementation:
             | 
             | https://github.com/rust9x/rust/commit/3a3eddb0044c6d03357a7
             | 5...
        
         | nazgulsenpai wrote:
         | I commend you for finding a use-case for this because I'm
         | scratching my head over if this is a toy project or filling
         | some necessity.
         | 
         | Still a very awesome project!
        
           | seritools wrote:
           | Can confirm, toy project. But hey, if it helps someone who
           | might actually need this, even better!
        
         | andai wrote:
         | You spooked me that Win11 had dropped support for 32-bit
         | applications, but it seems they still work fine. There's no
         | 32-bit version of the OS though.
        
           | drbawb wrote:
           | Rather confusingly the death of the 32-bit version of Windows
           | in practice just means they are dropping support for 16-bit
           | DOS applications.
           | 
           | There is a WoW (windows on windows) subsystem which permitted
           | you to either run 16-bit binaries on your 32-bit system, or
           | 32-bit binaries on your 64-bit system; but there's no
           | 16-on-64 or 16-on-32-on-64.
           | 
           | If you have a 64-bit version of Windows the compatibility
           | layer[1] lives at `%SYSTEMROOT%\SysWoW64`.
           | 
           | [1]: https://en.wikipedia.org/wiki/Windows_on_Windows
        
             | simcop2387 wrote:
             | You can use winevdm for this though,
             | https://github.com/otya128/winevdm
        
               | sidewndr46 wrote:
               | I'm waiting for the day when people run Linux on windows
               | via a hypervisor to run old programs under wine. This is
               | pretty close.
        
               | amalcon wrote:
               | I actually have already done this -- or, rather, helped
               | someone else to do this. The individual in question was
               | an academic with a license for a rather old version of a
               | particular piece of domain-specific software, which would
               | only run on Windows 95/98/ME. As he taught at a small
               | school, his budget wasn't exactly infinite, so he kept an
               | old Windows 98 machine around to run that software.
               | 
               | Turned out, it ran great on Wine. Actually, the
               | performance even improved because the hardware was so
               | much newer.
        
               | Tuna-Fish wrote:
               | People already do this. There is a very old strategy game
               | (Stars!) that still (barely) has an active community. As
               | it's a 16-bit windows app, the standard advice on how to
               | run it on modern systems is to run it under wine in a VM.
        
           | dataflow wrote:
           | Yeah they worded that confusingly. That said, I feel like the
           | writing is probably on the wall for 32-bit. My guess is this
           | might be the real reason why they pushed for making Visual
           | Studio 64-bit.
        
       | zozbot234 wrote:
       | Hopefully we'll get support within Rust/Cargo for easily
       | rebuilding the rust-std from source with custom features as part
       | of compiling a project. Then this legacy system support could
       | simply become part of the official Rust distribution.
        
       | Snitch-Thursday wrote:
       | Very cool, I love the idea of feeding some rust code to my
       | retirement community of old PCs, native PEs that I don't have to
       | use Win32 and C to use.
        
       ___________________________________________________________________
       (page generated 2022-04-21 23:01 UTC)