diff --git a/slides/2025-10-10-how-rust-compiles/index.html b/slides/2025-10-10-how-rust-compiles/index.html index 7f63237..6823e24 100644 --- a/slides/2025-10-10-how-rust-compiles/index.html +++ b/slides/2025-10-10-how-rust-compiles/index.html @@ -54,22 +54,35 @@ -
- -

behind cargo build

cargo vs rustc

-
- asciinema of cargo build -v +
+

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

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

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

it all starts at the source

-

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

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 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

+

so you want to compile a crate

MIR

@@ -144,29 +161,6 @@ - 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


@@ -273,14 +267,6 @@ fn main() { math::add() }
             
-
- -
-
-
- -
-
-
-
@@ -625,40 +586,20 @@ fn main() { math::add() }
-
-
- -
-
-