-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevcontainer_readme.txt
More file actions
148 lines (99 loc) · 5.66 KB
/
devcontainer_readme.txt
File metadata and controls
148 lines (99 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
1. Install Docker Desktop.
2. Install VS Code.
3. Install following Extensions :
Execute following commands from terminal on Ubuntu or from Powershell on Windows
code --install-extension ms-azuretools.vscode-docker
code --install-extension ms-vscode-remote.vscode-remote-extensionpack
code --install-extension ms-vscode-remote.remote-containers
code --install-extension redhat.vscode-yaml
Verify installation.
code --list-extensions # List all installed extensions
code --list-extensions | wc -l # Count the number of installed extensions (should be 9)
-----------------------------------------------------------------------------------------------
Create a folder 'rustprograms'. I am creating folder with this name. You can give any other name.
Clone the repo to the rustprograms folder and proceed with devcontainer set-up.
-----------------------------------------------------------------------------------------------
Setting Up the Development Container:
1. Run the Initialization Script:
Execute the init.sh script before building the Docker image.
This script performs essential setup tasks within the container.
# Note : Take back-up of previous history and rust_programs directory before building new image.
1.1. Open a terminal window in .devcontainer directory.
1.2. Make the init.sh and post-create.sh scripts executable using the following commands:
chmod +x init.sh
chmod +x post-create.sh
1.3 Run the initialization script:
./init.sh
2. Open VS Code and the Project Folder:
Open VS Code.
Open the rustprograms folder from within VS Code.
3. Open the Development Container:
Press F1 to open the VS Code command palette.
Select the command "Dev Containers: Open Folder in Container...".
This command will build docker image and spin-up the container.
4. Run the Post-Creation Script (Optional):
Open new ZSH Shell terminal window of VS-Code.
Execute post-create.sh script.
➜ workspace cd .devcontainer
➜ .devcontainer ./post-create.sh
** Rebuilding the Development Container:
If you modify the dockerfile, docker-compose.yml, or devcontainer.json files, follow these steps to rebuild the container:
Stop and remove container, remove previous image.
Take back-up of previous history and rust_programs directory before building new image.
In VS Code, open the command palette (press F1).
select DevContainers: Dev Containers: Open Folder in Container...""
Select rustprograms folder or folder containing '.devcontainer' folder, from folder browser dialogue.
---------------------------------------------------------------------------------------------------------------------------
## Debugging with Visual Studio Code
The `.vscode/launch.json` file contains debugger configurations. You can customize these configurations to match your specific debugging needs. Here's how to get started:
1. **Update Executable Path:**
- Open the `.vscode/launch.json` file.
- Locate the `"program"` property within the launch configuration you want to use.
- Update the path specified by `"program"` to point to the exact executable file (e.g., `.out' file) you want to debug.
e.g.
// Executable which you want to debug.
"program": "${workspaceFolder}/rust_programs/hello_world/target/debug/hello_world",
//**** Here each time for new project hello_world is replaced by project name.
-----------------------------------------------
2. **Configure Rust Analyzer:**
- The `.rust-project.json` file provides settings for the Rust analyzer extension.
- To enable code completion and other language features, edit the `"root_module"` property within the `.rust-project.json` file.
- Set `"root_module"` to the path of your project's `main.rs` file.
e.g.
{
"crates": [
{
"root_module": "./rust_programs/hello_world/src/main.rs",
"edition": "2021",
"deps": []
}
]
}
//**** Here each time for new project hello_world is replaced by project name.
-----------------------
- If rust-analyzer fails with Error as
Failed to discover workspace. Consider adding the Cargo.toml of the workspace to the linkedProjects setting.
Then, in VS-Code select File -> Preferences -> Settings Search for linkedProjects -> Edit in settings.json
settings.json will be opened, there add path for projects Cargo.toml
e.g.
{
"rust-analyzer.linkedProjects": [
"rust_programs/hello_world/Cargo.toml"
]
}
//**** Here each time for new project hello_world is replaced by project name.
-------------------------
**Additional Tips:**
- Consult the official VS Code documentation for more advanced debugging configurations:
https://code.visualstudio.com/docs/editor/debugging
- Refer to the Rust analyzer documentation for detailed information on configuration options:
https://rust-analyzer.github.io/manual.html
https://rust-analyzer.github.io/manual.html#vs-code
------------------------------------------------------------------------------------------------------------------------------
To uninstall vscode extensions execute uninstall-vscode-extensions.sh inside vscode terminal.
# First add execute permission to this file and then execute.
# chmod +x uninstall-vscode-extensions.sh
# ./uninstall-vscode-extensions.sh
----------------------------------------------------------------------------------------------------------------------------
Note : folders whose name start with '.' are hidden by default. So, ensure that you have checked the option show hiden files.
-----------------------------------------------------------------------------------------------------------------------------