Skip to content

Commit 4344de4

Browse files
authored
Merge pull request #8 from SystemEngineeringTeam/add/c-lang/beginner/setup
add: C 言語/基礎コース/環境構築
2 parents cfe99cf + a2bb538 commit 4344de4

15 files changed

Lines changed: 266 additions & 68 deletions

astro.config.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ export default defineConfig({
1414
integrations: [
1515
metaTags(),
1616
compress({
17-
HTML: {
18-
"html-minifier-terser": {
19-
removeAttributeQuotes: false,
20-
},
21-
},
17+
HTML: false,
2218
CSS: false,
2319
}),
2420
partytown({
@@ -36,6 +32,7 @@ export default defineConfig({
3632
lang: "ja",
3733
},
3834
},
35+
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 4 },
3936
logo: {
4037
src: "./src/assets/icons/logo/sym.svg",
4138
},
@@ -110,6 +107,16 @@ export default defineConfig({
110107
[remarkMermaid, { themes: ["dark", "neutral"] }],
111108
[wikiLinkPlugin, { markdownFolder: "src/content/docs" }],
112109
],
110+
rehypePlugins: [
111+
[
112+
rehypeExternalLinks,
113+
{
114+
target: "_blank",
115+
rel: ["noopener", "noreferrer"],
116+
content: { type: "text", value: " ↗" },
117+
},
118+
],
119+
],
113120
},
114121
vite: {
115122
plugins: [

bun.lockb

554 KB
Binary file not shown.

src/components/SyscatComment.astro

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
import { Image } from "astro:assets";
3+
4+
// ref: https://sysken.esa.io/posts/841
5+
const SYSCAT = {
6+
DEFAULT:
7+
"https://img.esa.io/uploads/production/attachments/19973/2024/02/14/138598/35cad701-0542-471f-b4ce-a09678edb673.PNG",
8+
/// チラッ
9+
EYES:
10+
"https://img.esa.io/uploads/production/attachments/19973/2024/06/06/138598/92239f09-18e6-4f48-854c-feaaa999f59b.PNG",
11+
/// わ~い!
12+
RAISEDHANDS:
13+
"https://img.esa.io/uploads/production/attachments/19973/2023/11/30/138598/d254a365-33e6-4ee3-8caf-4c20df402264.PNG",
14+
/// キラキラ :syscat-kirakira:
15+
SPARKLES:
16+
"https://img.esa.io/uploads/production/attachments/19973/2024/01/11/138598/d24414af-e785-4f6d-98cc-25685bc1f2e9.png",
17+
/// ドヤッ :syscat-doyaru:
18+
BRAGGING:
19+
"https://img.esa.io/uploads/production/attachments/19973/2024/03/06/138598/b74322eb-4eb6-4390-acfd-757233c1edf7.PNG",
20+
/// キュン :syscat_love:
21+
LOVE:
22+
"https://img.esa.io/uploads/production/attachments/19973/2024/02/06/138598/4857664f-5d49-4c5a-9f32-f2656045a5d7.PNG",
23+
/// これ!
24+
HERE:
25+
"https://img.esa.io/uploads/production/attachments/19973/2024/02/07/138598/c37aee0f-f8eb-47ce-81a3-2f9877769ec3.PNG",
26+
/// すやすや
27+
SLEEPING:
28+
"https://img.esa.io/uploads/production/attachments/19973/2024/02/14/138598/53e27e1f-9ccc-4e35-b92e-1da8c773fa38.PNG",
29+
/// グッ :syscat_ok:
30+
OK:
31+
"https://img.esa.io/uploads/production/attachments/19973/2024/06/06/138598/317b8911-8ad0-48ae-81d1-659e3ca90924.PNG",
32+
/// うわ~ん :syscat_cry:
33+
CRYING:
34+
"https://img.esa.io/uploads/production/attachments/19973/2024/06/06/138598/2c5bfd4f-8c07-41ef-8975-64a5109ef804.PNG",
35+
/// う~ん?
36+
CONFUSED:
37+
"https://img.esa.io/uploads/production/attachments/19973/2024/04/09/138598/8834cd16-2cfb-491d-aab9-bd273517355a.PNG",
38+
/// チラチラ
39+
PEEKING:
40+
"https://img.esa.io/uploads/production/attachments/19973/2024/04/09/138598/566a0b54-f603-4d42-b755-8287f17e6e2c.PNG",
41+
/// えっ :syscat_human:
42+
HUMAN:
43+
"https://img.esa.io/uploads/production/attachments/19973/2024/04/17/138598/add0a929-1711-4f32-b29f-14b310a0831e.PNG",
44+
/// ぱ~ん! :syscat_medetai:
45+
TADA:
46+
"https://img.esa.io/uploads/production/attachments/19973/2024/05/06/138598/cf2ce79a-3dfe-4041-bcf7-08ba3d866380.PNG",
47+
/// ストン
48+
SITTING:
49+
"https://img.esa.io/uploads/production/attachments/19973/2024/05/09/138598/5d9cf28b-685e-43ac-a197-d294dfd249f8.PNG",
50+
/// びっくり :syscat_bikkuri:
51+
SURPRISED:
52+
"https://img.esa.io/uploads/production/attachments/19973/2024/06/06/138598/ff9f29a8-f572-47b2-aa5b-f9df8ff86014.PNG",
53+
} as const;
54+
55+
type Props = {
56+
type?: keyof typeof SYSCAT;
57+
};
58+
59+
const { type } = Astro.props as Props;
60+
61+
---
62+
63+
<div class="syscat-comment">
64+
<div class="content-wrapper">
65+
<div><slot /></div>
66+
<div />
67+
</div>
68+
<Image
69+
alt=""
70+
inferSize
71+
src={SYSCAT[type ?? "DEFAULT"]}
72+
/>
73+
</div>
74+
75+
<style>
76+
77+
.syscat-comment {
78+
width: 100%;
79+
height: 100%;
80+
display: flex;
81+
align-items: flex-end;
82+
justify-content: space-between;
83+
container-type: inline-size;
84+
85+
& > .content-wrapper {
86+
width: 100%;
87+
display: flex;
88+
align-items: flex-end;
89+
90+
& :first-child {
91+
width: 100%;
92+
min-height: 5rem;
93+
border-radius: 0.5rem;
94+
background-color: var(--sl-color-hairline);
95+
padding: 1rem;
96+
display: grid;
97+
align-content: center;
98+
}
99+
100+
& :last-child {
101+
width: 1.25rem;
102+
height: 1.25rem;
103+
clip-path: polygon(100% 45%, 0 0, 0 100%);
104+
background-color: var(--sl-color-hairline);
105+
margin-block: 0 10px;
106+
margin-inline-start: -1px;
107+
}
108+
109+
}
110+
111+
& > img {
112+
height: 5rem;
113+
width: auto;
114+
margin-top: 0 !important;
115+
margin-inline-start: 0.5rem;
116+
117+
@container (max-width: 30rem) {
118+
height: 3rem;
119+
}
120+
}
121+
}
122+
123+
</style>

src/content/docs/textbook/c-lang/beginner/01--setup.mdx

Lines changed: 115 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,102 +3,154 @@ title: 環境構築
33
description: このチャプターでは、快適に XCode/VSCode で快適な C 言語を書くための秘訣を教えます。
44
---
55

6-
import { Aside } from "@astrojs/starlight/components";
6+
import { Aside, Steps, Tabs, TabItem, LinkCard } from '@astrojs/starlight/components'
7+
import SyscatComment from "@/components/SyscatComment.astro"
8+
export const CLI_OR_GUI_SYNC_KEY = 'c-lang/beginner::cli-or-gui';
9+
export const COMPILER_SYNC_KEY = 'c-lang/beginner::compiler';
10+
11+
## 私はどの環境で開発すれば?
12+
13+
過去の講義資料を基にしたゆる~い案内です。 確実に授業に即しているかは分からないけど、自分の PC などで試すときは参考にしてください。
14+
15+
- EE (電気学科/電気工学専攻)
16+
<LinkCard
17+
title="“VSBT 経由の MSVC” の節へ"
18+
href="#vsbt-経由の-msvcclexe"
19+
/>
20+
21+
- EV (電気学科/電子情報工学専攻)
22+
<LinkCard
23+
title="“w64devkit 経由の MinGW” の節へ"
24+
href="#w64devkit-経由の-mingw"
25+
/>
26+
- KK (情報科学科/コンピュータシステム専攻)
27+
<LinkCard
28+
title="“構築: エディター環境 - XCode” の節へ"
29+
href="#xcode"
30+
/>
31+
- KX (情報科学科/メディア情報専攻)
32+
<LinkCard
33+
title="“構築: エディター環境 - XCode” の節へ"
34+
href="#xcode"
35+
/>
36+
37+
38+
## 構築: コンパイラー環境
39+
40+
### Windows
41+
42+
<Aside type="tip" title="用語">
43+
44+
- VSBT(Visual Studio Build Tools)
45+
Visual C++ のコンパイラーを含む、プログラムのコンパイルをコマンドラインから行なうツールセット
46+
- Visual Studio Installer
47+
VSBT を構成する各種コンポーネントの インストール/アンインストール を行うツール
48+
- PowerShell
49+
Windows に標準でインストールされているコマンドラインツール
750

8-
<Aside type="caution">
51+
</Aside>
952

10-
前バージョンの Cook Zip をお使いの方へ
11-
バージョンアップが必要です! [下のセクション ↗](#前バージョンの%20Cook%20Zip%20をお使いの方へ) で確認してください。
53+
#### VSBT 経由の MSVC(`cl.exe`
1254

13-
</Aside>
55+
<Steps>
1456

15-
皆さん XCode には慣れましたか? C 言語とはお友達になれましたか?
57+
1. Visual Studio Installer をインストールする
1658

17-
VSCode で C 言語を快適に書くために..。
59+
<Tabs syncKey={CLI_OR_GUI_SYNC_KEY}>
60+
<TabItem label="CLI">
1861

19-
- F5 (Fn + F5) での自動コンパイル & 実行
20-
- 自動補完 (IntelliSense)
21-
- ブレークポイントでのデバッグ
22-
- エラーのインライン表示
23-
などなど多数の機能を簡単に使えるようにした zip を配布します。
62+
<kbd>Win</kbd> → `powershell` → <kbd>Enter</kbd> で PowerShell を起動します(ショートカット: <kbd>Win</kbd> + <kbd>X</kbd> → <kbd>I</kbd>)。
63+
その後、次のコマンドを実行して Visual Studio Installer をインストールします [^vsbt-winget]:
2464

25-
動作環境は macOS のみです. ご自由にお使いください。
26-
URL: https://assets.wappon28.dev/public/AIT/c-lang-base.zip
65+
```powershell
66+
winget install Microsoft.VisualStudio.2022.BuildTools
67+
```
2768

28-
<video controls width="480" alt="2024-05-23_0.03.33.mp4 (6.6 MB)" src="https://esa-storage-tokyo.s3-ap-northeast-1.amazonaws.com/uploads/production/attachments/19973/2024/06/12/163736/2e5af6a7-605d-4a78-b6d5-a369a813bdea.mp4"></video>
69+
インストールの完了後、自動的に Visual Studio Installer が起動します。
70+
もし起動しない場合は、スタートメニューから “Visual Studio Installer” を検索して起動してください。
2971

30-
あと、提出物 (ZIP) を作るちょっとしたプログラムを作りました! コンピューターリテラシーで導入したであろう HomeBrew を使ってインストールとアップデートができます. ターミナルや、VSCode 内のターミナルで
72+
</TabItem>
73+
<TabItem label="GUI">
74+
[Build Tools for Visual Studio 2022 - Microsoft](https://visualstudio.microsoft.com/ja/downloads/#build-tools-for-visual-studio-2022) にアクセスし、“ダウンロード” ボタンをクリックします。
75+
その後、ダウンロードされた `vs_BuildTools.exe` をクリックし、Visual Studio Installer を起動します。
76+
</TabItem>
77+
</Tabs>
3178

32-
```sh
33-
brew install wappon28dev/tap/cook-zip
34-
```
79+
2. VSBT をインストールする
3580

36-
をしたあと,
81+
“C++ によるデスクトップ開発” にチェックを入れ、
82+
- “MSVC v143 - VS 2022 C++ x64/x86 ビルド ツール(最新)”
83+
(バージョンは変動する可能性アリ)
84+
- “Windows 用 C++ CMake ツール”
3785

38-
```sh
39-
cook-zip
40-
```
86+
の 2 つにチェックを入れます。その後、“変更” をクリックします。
4187

42-
とすると、対話式のプログラムが起動するので、それに従うと提出物が作成されます! 次のコマンドはどこの作業ディレクトリーでも実行できます。
88+
![](./_images/202504050150.drawio.png)
4389

44-
<video controls width="480" alt="-5971937336374499908.mp4 (4.2 MB)" src="https://esa-storage-tokyo.s3-ap-northeast-1.amazonaws.com/uploads/production/attachments/19973/2024/06/16/163736/8a2f8169-9eaf-4061-a0d7-57a258d4905c.mp4"></video>
90+
インストールが完了するまで待機します。
91+
![](./_images/202504050211.png)
4592

46-
あと、書き出された zip は一時ディレクトリに保存されているので、内容物を確認後、自身でバックアップしてくださいね。
93+
<SyscatComment type="SLEEPING">PC やネットワークの速度によっては時間を要するから、お茶でも飲んでゆっくり待ってね。</SyscatComment>
4794

48-
また、提出物のフォーマットが変更される場合も考慮して、簡単にアップデートできるように,
95+
3. MSVC のバージョンを特定する
4996

50-
```sh
51-
brew upgrade cook-zip
52-
```
97+
<Tabs syncKey={CLI_OR_GUI_SYNC_KEY}>
98+
<TabItem label="CLI">
5399

54-
と打つとできるようにしました. 指示があった場合にすると良いと思います!
100+
PowerShell で次のコマンドを実行し、どのバージョンがインストールされているかを確認します:
55101

56-
### 前バージョンの Cook Zip をお使いの方へ
102+
```powershell
103+
ls -name "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
104+
```
57105

58-
> [!NOTE]
59-
> tl;dr
60-
>
61-
> 1. 数回前から提出物のフォーマットが変更された
62-
> 1. それに伴って、Cook Zip をアップデートする必要がある
63-
> 1. 既に存在する Cook Zip を削除し、新しいバージョンを `brew install wappon28dev/tap/cook-zip` でインストールする
106+
すると、次のような出力が得られます(例):
64107

65-
2 回前あたりから、課題、チャレンジ問題の提出物のフォーマットが変更されました.
66-
具体的には、学籍番号の `k` が大文字から小文字に変更されました。
108+
```powershell
109+
14.43.34808
110+
```
67111

68-
[第 6 回](https://cms.aitech.ac.jp/pluginfile.php/527782/mod_resource/content/3/issues06.md.html#提出するファイル構成-1) ... [第 8 回](https://cms.aitech.ac.jp/pluginfile.php/527790/mod_resource/content/3/issues08.md.html#提出するファイル構成-1) - 演習問題と課題の詳細資料 - Moodle (7 回目は課題なし)
112+
これが、MSVC のバージョン番号の一例です。 これをメモしておきます。
69113

70-
```diff
71-
- k2****_issues.zip
72-
- - 06_issue1_K20000.c
73-
- - 06_challenge1_K20000.c // 任意提出
74-
- k2****_issues.zip
75-
+ - 08_issue1_k20000.c
76-
+ - 08_challenge1_k20000.c // 任意提出
77-
```
114+
<Aside>
115+
Visual Studio Installer でインストールする際、“インストールの場所” を変更した際は、`ls` の引数のパスを変更する必要があります。
116+
</Aside>
78117

79-
それに伴い、Cook Zip のバージョンアップが必要です。
118+
</TabItem>
119+
<TabItem label="GUI">
80120

81-
第 8 回でケースの変更に私が気づくことができず、Cook Zip ユーザーのほとんどが大文字のまま提出されているかと思います. 確認の術はありませんが、減点されていた場合は申し訳ないです。
121+
エクスプローラーで、MSVC が含まれるフォルダー
122+
```text
123+
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC
124+
```
125+
に移動します。 (ショートカット: パスをコピー後、<kbd>Win</kbd> + <kbd>R</kbd> → <kbd>Ctrl</kbd> + <kbd>V</kbd> → <kbd>Enter</kbd>)
126+
127+
![](./_images/202504050344.drawio.png)
82128

83-
(一応、追加情報を入れておくと、macOS で使われているディスクフォーマットである APFS は、ファイル名の大文字小文字を区別しない[^1] ので、もしかしたら問題になっていないかもしれません.)
129+
作業フォルダー内にあるフォルダーの名前が MSVC のバージョン番号の一例です。 これをメモしておきます。
84130

85-
第 9 回の提出にはまだ時間があるので、次の手順で Cook Zip のバージョンアップを行ってください。
131+
<Aside>
132+
Visual Studio Installer でインストールする際、“インストールの場所” を変更した際は、“ファイル名を指定して実行” のパスを変更する必要があります。
133+
</Aside>
86134

87-
1. 旧バージョンの Cook Zip を削除 (Finder や VSCode 上から削除 または `rm ./cook-zip`)
88-
1. 新バージョンの Cook Zip をインストール
135+
</TabItem>
136+
</Tabs>
89137

90-
```sh
91-
brew install wappon28dev/tap/cook-zip
92-
```
93138

94-
1. 新しいバージョンで再度、提出物を作成
95-
次のコマンドはどこの作業ディレクトリーでも実行できます。
139+
4. 環境変数を設定する
140+
141+
MSVC のバージョンが特定できたら、次に示すパス中の緑の箇所を特定したバージョンに置き換え、クリップボードやメモ帳などにコピーしておきます [^vsbt-path]:
142+
```text ins="{MSVC ver.}"
143+
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\{MSVC ver.}\bin\Hostx64\x64
144+
```
96145

97-
```sh
98-
cook-zip
146+
e.g. `14.43.34808`:
147+
```text ins="14.43.34808"
148+
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64
99149
```
100150

101-
また今後のために、`brew upgrade cook-zip` でアップデートできるようにしてあります。
151+
パスの準備ができたら、 <kbd>Win</kbd> → `env` で “環境変数を編集” を起動します。
152+
その後、ユーザー環境変数セクションの `Path` (下図の赤枠) をダブルクリックします。
153+
![](./_images/202504050355.drawio.png)
102154

103155
[^1]: [Mac の大文字と小文字を区別するファイルシステムとの非互換性 - Steam サポート ↗](https://help.steampowered.com/ja/faqs/view/0395-A862-13F3-6E82#:~:text=%E3%80%8CJournaled%20HFS%E3%80%8D%E3%80%81%E3%80%8CAPFS,%E3%81%93%E3%81%A8%E3%82%92%E7%A4%BA%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82)
104156

460 KB
Loading
462 KB
Loading
70.4 KB
Loading
66.4 KB
Loading
111 KB
Loading
128 KB
Loading

0 commit comments

Comments
 (0)