Adding new target (uwp) to rustc

Hi!

I'm trying to add an architecture to rustc (namely, Windows UWP platform) and am having trouble with it.
Full disclosure, I'm extremely new to rust, its tools, so I might be missing something rather obvious.

I added my platform description in src/librustc_target/spec/, and am able to build everything (using ./x.py build up to the point where /build/x86_64-unknown-linux-gnu/stage2/bin/rustc --print target-list shows my target.
However, when I try to build a basic hello world target, here's the output:

chouquette@nibbler ./build/x86_64-unknown-linux-gnu/stage2/bin/rustc --target=i686-pc-uwp-gnu /tmp/test.rs                                                                                             ~/dev/rust
error[E0463]: can't find crate for `std`
  |
  = note: the `i686-pc-uwp-gnu` target may not be installed

error: aborting due to previous error

I tried to explicitely build std/libstd using ./x.py build src/libstd, which succeeds, but then running rustc outputs: error: couldn't load codegen backend "/home/chouquette/dev/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so": "librustc_codegen_ssa-ae35f6596ec04cfb.so: cannot open shared object file: No such file or directory"

This is fixed by re-running ./x.py build, but then it gets me the "can't find std crate" error.

To put it mildly, I feel very lost :slight_smile: Any help would be highly appreciated!

What I'm aiming at is to be able to build a small shared library for this specific target. Once I can just edit the target file to adjust linkage for that platform, I'll be happy :smiley:

Thanks a lot in advance!

I might be wrong, but I think if you are working on the compiler itself, the internals forum might be a better place to ask. :slightly_smiling_face:

The internals forum (IRLO) is used primarily to propose process, language and compiler extensions/changes. Most discussion of targets, including new targets, occurs in this users forum (URLO). Most compiler enhancements to support new targets occur in the LLVM and/or GCC compiler backends that Rust uses but does not really control.

1 Like

Isn't UWP a framework/set of APIs designed for creating applications which can run across various different platforms? When you add a new target to rustc, what you are doing is defining a new architecture (e.g. x86) and operating system (e.g. Linux), which doesn't really sound like what you're looking for...

There is a thread on reddit which mentions you might be able to generate bindings for all the UWP APIs and then use them just like any other C library. It looks like there's also been at least one attempt to do this in the past.

Hi, thanks a lot for your replies!

Isn’t UWP a framework/set of APIs designed for creating applications which can run across various different platforms?

It mostly is, but there can be quite a few differences with i686-w64-mingw32/i686-pc-windows-gnu:

  • when compiling C/C++ the C(XX)FLAGS must be changed (at least to specify the API subset that are allowed and possibly to specify a different windows version than the default)
  • If some libraries are using some forbidden symbols, a compatibility library (libwinstorecompat) might be needed to avoid reimplementing the same function in various libraries
  • While kernel32 or some flavor of the CRT might be available on a desktop Windows, they aren't available when using some of the devices targeted by UWP (Xbox one for sure, and I wouldn't be surprised than hololens doesn't ship some DLLs)
  • During early testing, it seems the unwinding is using forbidden symbols, which can be "easily" fixed by using llvm's libunwind, but that's a type of change I'd like to restrict to the UWP platform, at first at least.

I've been done the "use the same triplet for Desktop & UWP" rabbit hole, and in hindsight, it was a mistake, therefor I'm trying to add a specific triplet this time.
That being said, you are perfectly correct, and compiling for XXX-pc-windows-gnu will compile & work on UWP. The resulting binaries won't be able to be validated by the WACK (Windows Application Certification Toolkit) and can't be submitted to the store though.

I've been able to make some progress, it seems all I needed to do to move forward was to have a json file describing my architecture in order to build a stage 0/1 compiler that understand my target, rather than specifying it as a rust file in src/librustc_target/spec/
Now the issue is that uwp is not recognized as a windows platform in various crates, but that's something that can be patched as I go!

1 Like

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