From 14053a50b9795ef11cecf7139e5b75c772c25dc1 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Wed, 1 Oct 2025 08:16:41 +0200 Subject: [PATCH 1/2] improve --- .../2025-10-10-how-rust-compiles/index.html | 128 +++++++++++------- 1 file changed, 81 insertions(+), 47 deletions(-) diff --git a/slides/2025-10-10-how-rust-compiles/index.html b/slides/2025-10-10-how-rust-compiles/index.html index 6823e24..38ca7e7 100644 --- a/slides/2025-10-10-how-rust-compiles/index.html +++ b/slides/2025-10-10-how-rust-compiles/index.html @@ -54,35 +54,22 @@ +
+ +

behind cargo build

cargo vs rustc

-
-

-                    $ cargo build -v
-                
-
cargo
-
-
rustc (clap)
-
rustc (tokio)
-
rustc (tracing)
-
rustc (yourcrate)
-
+
+ asciinema of cargo build -v

what does rustc like, do?

a quick overview of the compilation phases

-
-

it all starts at the source

-

-              #[no_mangle]
-              pub fn add(a: u8, b: u8) -> u8 {
-                a.wrapping_add(b)
-              }
-            
-

the frontend and the backend

@@ -98,36 +85,35 @@
-

lex, parse, resolve, typecheck, all these fancy things

-
-
-              %%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true, 'fontSize': '25px' }}}%%
-              flowchart TB
-                function --> return
-                function --> params
-                params --> a_def[a]
-                params --> b_def[b]
-                function --> body
-                body --> cl["method call"]
-                cl --> a_use[a]
-                cl --> wrapping_add
-                cl --> b_use[b]
-            
-
+

it all starts at the source

+

+              pub fn add(a: u8, b: u8) -> u8 {
+                a.wrapping_add(b)
+              }
+            
-

so you want to compile a crate

+

it gets processed

+

+            #[attr = MacroUse {arguments: UseAll}]
+            extern crate std;
+            #[prelude_import]
+            use std::prelude::rust_2024::*;
+            fn add(a: u8, b: u8) -> u8 { a.wrapping_add(b) }
+            
+
+
+

until it doesn't even look like Rust anymore

MIR

@@ -161,6 +144,29 @@ - the how, what, and when of invoking LLVM
+
+

a crate - the compilation unit

+

quite big

+

in C it's just a single file

+
+
+

a codegen unit

+

LLVM is single-threaded

+

rustc: hi LLVM, look we are like a C file, now be fast

+

~1-256 depending on size and configuration (βš™οΈ)

+
+
+              %%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true, 'fontSize': '25px' }}}%%
+              flowchart LR
+                crate
+
+                crate --> cgu1["Codegen-Unit 1"]
+                crate --> cgu2["Codegen-Unit 2"]
+                crate --> cgu3["Codegen-Unit 3"]
+                crate --> cgu4["Codegen-Unit 4"]
+            
+
+

codegen units


@@ -267,6 +273,13 @@ fn main() { math::add() }
             
+
+ +
+
+
+ +
@@ -591,6 +617,14 @@ fn main() { math::add() } - ThinLTO across different codegen units by default
+
+ +
@@ -371,16 +372,16 @@ fn main() { math::add() }
-
-
-
-
@@ -500,16 +501,28 @@ fn main() { math::add() }
+
+
+
@@ -612,28 +625,40 @@ fn main() { math::add() }
+
+
+