{"componentChunkName":"component---src-templates-post-template-js","path":"/rust-setup-on-wsl-en","result":{"data":{"markdownRemark":{"id":"92b3a10f-d670-586e-88af-ebc5827cba62","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/rust-setup-on-wsl\">original page</a>.</p>\n</blockquote>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of Contents</h2>\n<ul>\n<li><a href=\"#environment\">Environment</a></li>\n<li>\n<p><a href=\"#setting-up-the-rust-environment\">Setting Up the Rust Environment</a></p>\n<ul>\n<li><a href=\"#installing-rust\">Installing Rust</a></li>\n<li><a href=\"#hello-world\">Hello, World</a></li>\n</ul>\n</li>\n<li><a href=\"#summary\">Summary</a></li>\n</ul>\n<h2 id=\"environment\" style=\"position:relative;\"><a href=\"#environment\" aria-label=\"environment permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Environment</h2>\n<p>This time, I’ll build an environment with the following setup so I can enjoy competitive programming in Rust.</p>\n<ul>\n<li>Windows 10</li>\n<li>WSL Ubuntu 20.04</li>\n</ul>\n<h2 id=\"setting-up-the-rust-environment\" style=\"position:relative;\"><a href=\"#setting-up-the-rust-environment\" aria-label=\"setting up the rust environment permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setting Up the Rust Environment</h2>\n<h3 id=\"installing-rust\" style=\"position:relative;\"><a href=\"#installing-rust\" aria-label=\"installing rust permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Installing Rust</h3>\n<p>According to the <a href=\"https://www.rust-lang.org/ja/tools/install\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">official documentation</a>, WSL users can easily install Rust with the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">curl</span> --proto <span class=\"token string\">'=https'</span> --tlsv1.2 -sSf https://sh.rustup.rs <span class=\"token operator\">|</span> <span class=\"token function\">sh</span></code></pre></div>\n<p>During the installation, you will be asked something like the following. I selected “Proceed with installation.”</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> Proceed with installation <span class=\"token punctuation\">(</span>default<span class=\"token punctuation\">)</span>\n<span class=\"token number\">2</span><span class=\"token punctuation\">)</span> Customize installation\n<span class=\"token number\">3</span><span class=\"token punctuation\">)</span> Cancel installation</code></pre></div>\n<p>Once the installation is complete, all tools are placed in <code class=\"language-text\">~/.cargo/bin</code>, so add this directory to PATH.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">export</span> <span class=\"token assign-left variable\"><span class=\"token environment constant\">PATH</span></span><span class=\"token operator\">=</span><span class=\"token environment constant\">$PATH</span><span class=\"token builtin class-name\">:</span><span class=\"token environment constant\">$HOME</span>/.cargo/bin\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'export PATH=$PATH:$HOME/.cargo/bin'</span> <span class=\"token operator\">>></span> ~/.bashrc</code></pre></div>\n<p>After adding it to PATH, use the following commands to confirm that the toolchain has been installed.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">rustup --version\nrustc --version\ncargo --version</code></pre></div>\n<h3 id=\"hello-world\" style=\"position:relative;\"><a href=\"#hello-world\" aria-label=\"hello world permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Hello, World</h3>\n<p>For now, let’s create a Hello, World project.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">cargo new hello_world</code></pre></div>\n<p>At this point, the following project directory is created.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ tree hello_world/\nhello_world/\n├── Cargo.toml\n└── src\n    └── main.rs\n\n<span class=\"token number\">1</span> directory, <span class=\"token number\">2</span> files</code></pre></div>\n<p>Next, compile <code class=\"language-text\">main.rs</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">cd</span> hello_world\ncargo run <span class=\"token comment\"># or cargo build</span></code></pre></div>\n<p>Then, the <code class=\"language-text\">target</code> directory is created, and the structure looks like this.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ tree hello_world/\nhello_world/\n├── Cargo.lock\n├── Cargo.toml\n├── src\n│   └── main.rs\n└── target\n    ├── CACHEDIR.TAG\n    └── debug\n        ├── build\n        ├── deps\n        │   ├── hello_world-dcff91f54b10472a\n        │   └── hello_world-dcff91f54b10472a.d\n        ├── examples\n        ├── hello_world\n        ├── hello_world.d\n        └── incremental\n            └── hello_world-2x2zxxntihjma\n                ├── s-g16k84pkgw-1kx1yoj-1r8cowopde7m7\n                │   ├── 18w4g3z43hvkcb89.o\n                │   ├── 2195c5i0j9yy401g.o\n                │   ├── 2d4qpr6fn1o2oy47.o\n                │   ├── 3n8l6lb07r0z64tp.o\n                │   ├── 4ltafe1k1v50rxij.o\n                │   ├── dep-graph.bin\n                │   ├── g7uy5q5v1tqa9ua.o\n                │   ├── osa6u353jylok1z.o\n                │   ├── query-cache.bin\n                │   ├── work-products.bin\n                │   └── wzcdn60lipjlwrg.o\n                └── s-g16k84pkgw-1kx1yoj.lock\n\n<span class=\"token number\">9</span> directories, <span class=\"token number\">20</span> files</code></pre></div>\n<p>The <code class=\"language-text\">hello_world</code> file directly under this <code class=\"language-text\">debug</code> directory is the compiled ELF binary itself.</p>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>I originally wanted to continue from here and configure VSCode so that Rust debugging would work,\nbut unfortunately I still could not find any VSCode extension that supported Rust debugging.</p>\n<p>I’ll add an update if there are any developments.</p>","fields":{"slug":"/rust-setup-on-wsl-en","tagSlugs":["/tag/rust/","/tag/wsl/","/tag/備忘録/","/tag/english/"]},"frontmatter":{"date":"2021-08-07","description":"I’ll set up an environment for enjoying competitive programming in Rust.","tags":["Rust","WSL","備忘録","English"],"title":"Notes on Setting Up a Rust Environment on WSL","socialImage":{"publicURL":"/static/dc4d8b7f8795f3c3d3489d9957d155f2/no-image.png"}}}},"pageContext":{"slug":"/rust-setup-on-wsl-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}