diff --git a/installation.md b/installation.md index 0034e73c8cac149d9decf436d22c98308f08ba16..3e04dccfbd080b61afc39566a759f0d3d991b9ab 100644 --- a/installation.md +++ b/installation.md @@ -17,20 +17,20 @@ sansfont: Sans Serif - Installation de la chaîne de compilation: - ~~~~{#mycode .bash .numberLines} + <pre><code data-trim="hljs sh"> curl https://sh.rustup.rs -sSf | sh - ~~~~~~~~~~~~~~~~~~~~~~~~~~ + </code></pre> - Quelques commandes importantes - ~~~~{#mycode .bash .numberLines} + <pre><code data-trim="hljs sh"> $ rustup install stable # installation de la chaine stable $ rustup default stable # chaine par défaut $ rustup self uninstall # désinstallation $ rustup install nightly # installation de la chaine en développement - ~~~ + </code></pre> -## Contentenu de la chaîne de compilation of the Toolchain +## Contentenu de la chaîne de compilation - `rustc`{.sh}: compilateur et éditeur de lien - `cargo`{.sh}: outil pour la compilation et gestion de dépendances @@ -42,48 +42,67 @@ $ rustup install nightly # installation de la chaine en développement - `rustc` est écrit en Rust (en grande partie). - Pour terster l'installation - ~~~{.bash} + <pre><code data-trim="hljs sh"> rustc --help - ~~~ + </code></pre> ## Mon premier `Hello World!`{.rust} - Dans un fichier `hello_world.rs`{.bash}. <pre><code class=lang-rust" data-trim="hljs rust"> - fn main() { - println!("Hello, World!"); - } +fn main() { // présent dans tout programme Rust + println!("Hello, World!"); // macro d'affichage +} </code></pre> - Pour compiler, éditer les liens et exécuter - ~~~{.bash} - $ rustc hello_world.rs - $ ./hello_world - Hello, World! - ~~~ + <pre><code data-trim="hljs sh"> +$ rustc hello_world.rs +$ ./hello_world +Hello, World! + </code></pre> ## Cargo -<pre><code data-source="chapters/shared/code/installation/6.sh" data-trim="hljs sh"></code></pre> - -Cargo is Rusts build and package management tool. - -Cargo is installed along with `rustc`, but is not tightly bound to a `rustc` version. +- La documentation [Cargo Manifest docs](http://doc.crates.io/manifest.html). +- Cargo est l'outil de compilation et gestion de dépendaces de Rust. +- Indépendant de la version de `rustc`{.sh}. +- Permet l'installation d'outil -## Once more with Cargo - -<pre><code data-source="chapters/shared/code/installation/7.sh" data-trim="hljs sh"></code></pre> - -## A Little Look Around - -- What is in Cargo.toml? -- What is in Cargo.lock? - -For details, check the [Cargo Manifest docs](http://doc.crates.io/manifest.html). - -## Cargo Also Manages Tools + <pre><code data-trim="hljs sh"> +$ cargo +nightly install clippy # conseil de "beauté du code" +$ cargo +nightly install rustfmt # formattage automatique du code + </code></pre> -<pre><code data-source="chapters/shared/code/installation/8.sh" data-trim="hljs sh"></code></pre> +## Exemple d'utilisation + +<pre><code data-trim="hljs sh"> +$ cargo new hello_world --bin # création projet +$ cd hello_world +$ cargo build # cargo check + Compiling hello_world v0.1.0 (file:///home/malaspor/hello_world) + Finished dev [unoptimized + debuginfo] target(s) in 1.33s +$ cargo run + Finished dev [unoptimized + debuginfo] target(s) in 0.05s + Running `target/debug/hello_world` +Hello, world! +$ ./target/debug/hello_world +Hello, world! +$ cargo build --release # compilation avec optimisations + Compiling hello_world v0.1.0 (file:///home/malaspor/Downloads/hello_world) + Finished release [optimized] target(s) in 0.35s +</code></pre> + +- Le fichier `Cargo.toml`{.sh}: + +<pre><code data-trim="hljs sh"> +[package] +name = "hello_world" +version = "0.1.0" +authors = ["Your Name you@example.com"] + +[dependencies] +</code></pre>