How can I fetch git repository of Rust and statically compile it

I want to support Rust on the operating system kernel I have written (risc-v arch).
I found rust in alpine linux (Alpine Linux packages), but i can't manage to fetch the source code from that website.
How can I fetch the whole git repository and statically compile it? So that I can run try to run the executable file on my toy kernel

Rust's source code is available as a git repository on GitHub:

rustc-dev-guide explains how to build Rust in detail. Feel free to ask more if you are stuck.

I can't find the statically linked option in building Rustc. How to specify the option?

You should be able to specify x86_64-unknown-linux-musl as the compilation target (./ build --target x86_64-unknown-linux-musl). That'll give you a statically compiled Linux build.

You can't statically compile rustc itself. It loads dynamic libraries at runtime (proc macros and if you use them (currently unstable) custom codegen backends) and as such has to be dynamically linked too. Statically linked programs can't use dlopen on any libc impl that I know of.

I want to cross-compile it for risc-v target on my x86 host platform. What command should I run?

You can use ./ dist --host <riscv_triple> --target <riscv_triple> I believe where <riscv_triple> is the correct target triple for your riscv system.

Why do I specify riscv as host?

In Rust build system, "host" means where your compiled compiler will run. As I understand, you are trying to run your compiled compiler on RISC-V, so your host is RISC-V.

"But my host is x86!" you scream. As in, you are doing this build on x86. Sorry for the confusion, but in Rust build system, that is called "build". That is, your build arch is x86, your host arch is RISC-V, and your target arch is also RISC-V (this is where your compiled program compiled by compiled compiler will run).

Thanks! I'll try it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.