Compare commits
15 Commits
9c2227c992
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a29828e8d5 | |||
| 3169f32e4f | |||
| 9da2086018 | |||
| 040d521395 | |||
| 51a04207ab | |||
| 1d411cefb5 | |||
|
|
d3cb2a9843 | ||
|
|
5ced9d3eca | ||
|
|
f5b2a7931c | ||
|
|
f964546f58 | ||
|
|
916aa267ca | ||
|
|
cbed25c41b | ||
|
|
da61e6e12c | ||
|
|
228542aad9 | ||
|
|
31a0115e26 |
@@ -1,8 +0,0 @@
|
||||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/rust/.devcontainer/base.Dockerfile
|
||||
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
|
||||
ARG VARIANT="bullseye"
|
||||
FROM mcr.microsoft.com/devcontainers/rust:1-${VARIANT}
|
||||
|
||||
# [Optional] Uncomment this section to install additional packages.
|
||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
||||
@@ -1,48 +1,57 @@
|
||||
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/rust
|
||||
{
|
||||
"name": "Rust Sample",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
"args": {
|
||||
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
|
||||
// Use bullseye when on local on arm64/Apple Silicon.
|
||||
"VARIANT": "bullseye"
|
||||
}
|
||||
},
|
||||
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
|
||||
|
||||
// Configure tool-specific properties.
|
||||
"name": "Rust",
|
||||
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",
|
||||
|
||||
// 先构建项目,但不自动运行
|
||||
"postStartCommand": "cargo build && clear",
|
||||
|
||||
"customizations": {
|
||||
// Configure properties specific to VS Code.
|
||||
"vscode": {
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"lldb.executable": "/usr/bin/lldb",
|
||||
// VS Code don't watch files under ./target
|
||||
"files.watcherExclude": {
|
||||
"**/target/**": true
|
||||
},
|
||||
"rust-analyzer.checkOnSave.command": "clippy"
|
||||
"settings": {},
|
||||
"extensions": [
|
||||
"streetsidesoftware.code-spell-checker",
|
||||
"rust-lang.rust-analyzer", // 添加 Rust 语言支持
|
||||
"vadimcn.vscode-lldb" // 添加 LLDB 调试器支持
|
||||
],
|
||||
|
||||
// 添加调试配置
|
||||
"debug": {
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug Rust Application",
|
||||
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"preLaunchTask": "cargo-build"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"vadimcn.vscode-lldb",
|
||||
"mutantdino.resourcemonitor",
|
||||
"matklad.rust-analyzer",
|
||||
"tamasfe.even-better-toml",
|
||||
"serayuzgur.crates"
|
||||
]
|
||||
// 添加构建任务
|
||||
"tasks": {
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cargo",
|
||||
"command": "build",
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": "build",
|
||||
"label": "cargo-build"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "rustc --version",
|
||||
|
||||
// Comment out to run as root instead.
|
||||
"remoteUser": "vscode"
|
||||
}
|
||||
|
||||
// 转发应用端口(根据你的实际端口修改)
|
||||
"forwardPorts": [8080],
|
||||
"portsAttributes": {
|
||||
"8080": {
|
||||
"label": "Rust Application",
|
||||
"onAutoForward": "notify"
|
||||
}
|
||||
}
|
||||
}
|
||||
41
.gitea/workflows/ci.yaml
Normal file
41
.gitea/workflows/ci.yaml
Normal file
@@ -0,0 +1,41 @@
|
||||
name: Rust CI Pipeline
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test-and-build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/rust-lang/rust:latest
|
||||
steps:
|
||||
# 1. 检出代码 - 使用 Gitea 本地的 actions 镜像
|
||||
- name: 🔍 Check out repository code
|
||||
uses: https://devstar.cn/actions/checkout@v4
|
||||
|
||||
# 2. 显示环境信息
|
||||
- name: ℹ️ Environment Info
|
||||
run: |
|
||||
rustc --version
|
||||
cargo --version
|
||||
echo "Building repository: ${{ gitea.repository }}"
|
||||
|
||||
# 3. 构建项目(调试模式)
|
||||
- name: 🔧 Build (Debug)
|
||||
run: cargo build --verbose
|
||||
|
||||
# 4. 构建项目(发布模式)
|
||||
- name: 🚀 Build (Release)
|
||||
run: cargo build --release --verbose
|
||||
|
||||
# 5. 运行测试
|
||||
- name: ✅ Run Tests
|
||||
run: cargo test --verbose
|
||||
|
||||
# 6. 清理构建缓存
|
||||
- name: 🧹 Cleanup
|
||||
run: cargo clean
|
||||
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@@ -1,4 +1,3 @@
|
||||
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
@@ -17,7 +16,11 @@
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": []
|
||||
"args": [],
|
||||
// 添加环境变量解决文件锁问题
|
||||
"env": {
|
||||
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL": "sparse"
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
25
.vscode/task.json
vendored
Normal file
25
.vscode/task.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "cargo-clean-build",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": [
|
||||
"build",
|
||||
"--bin=hello_remote_world",
|
||||
"--package=hello_remote_world"
|
||||
],
|
||||
"group": "build",
|
||||
"problemMatcher": ["$rustc"],
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": false,
|
||||
"panel": "shared",
|
||||
"showReuseMessage": true,
|
||||
"clear": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
9
CODE_OF_CONDUCT.md
Normal file
9
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Microsoft Open Source Code of Conduct
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
|
||||
Resources:
|
||||
|
||||
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
|
||||
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
||||
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "hello_remote_world"
|
||||
version = "0.1.0"
|
||||
authors = ["VS Code <vscode@microsoft.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path ="./src/lib/lib.rs"
|
||||
|
||||
80
README.md
80
README.md
@@ -1,76 +1,16 @@
|
||||
# Try Out Development Containers: Rust
|
||||
# Rust
|
||||
Rust 基础开发环境镜像模板项目
|
||||
|
||||
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-rust)
|
||||
Rust 项目工程模板
|
||||
|
||||
A **development container** is a running [Docker](https://www.docker.com) container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Remote - Containers](https://aka.ms/vscode-remote/containers)**.
|
||||
## 使用方法
|
||||
|
||||
This is a sample project that lets you try out either option in a few easy steps. We have a variety of other [vscode-remote-try-*](https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories) sample projects, too.
|
||||
```
|
||||
cargo run
|
||||
```
|
||||
|
||||
> **Note:** If you already have a Codespace or dev container, you can jump to the [Things to try](#things-to-try) section.
|
||||
### 版权说明
|
||||
|
||||
## Setting up the development container
|
||||
Copyright @ Mengning Software
|
||||
|
||||
### GitHub Codespaces
|
||||
Follow these steps to open this sample in a Codespace:
|
||||
1. Click the Code drop-down menu and select the **Open with Codespaces** option.
|
||||
1. Select **+ New codespace** at the bottom on the pane.
|
||||
|
||||
For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace).
|
||||
|
||||
### VS Code Remote - Containers
|
||||
|
||||
If you already have VS Code and Docker installed, you can click the badge above or [here](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-rust) to get started. Clicking these links will cause VS Code to automatically install the Remote - Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use.
|
||||
|
||||
Follow these steps to open this sample in a container using the VS Code Remote - Containers extension:
|
||||
|
||||
1. If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started).
|
||||
|
||||
2. To use this repository, you can either open the repository in an isolated Docker volume:
|
||||
|
||||
- Press <kbd>F1</kbd> and select the **Remote-Containers: Try a Sample...** command.
|
||||
- Choose the "Rust" sample, wait for the container to start, and try things out!
|
||||
> **Note:** Under the hood, this will use the **Remote-Containers: Clone Repository in Container Volume...** command to clone the source code in a Docker volume instead of the local filesystem. [Volumes](https://docs.docker.com/storage/volumes/) are the preferred mechanism for persisting container data.
|
||||
|
||||
Or open a locally cloned copy of the code:
|
||||
|
||||
- Clone this repository to your local filesystem.
|
||||
- Press <kbd>F1</kbd> and select the **Remote-Containers: Open Folder in Container...** command.
|
||||
- Select the cloned copy of this folder, wait for the container to start, and try things out!
|
||||
|
||||
## Things to try
|
||||
|
||||
Once you have this sample opened, you'll be able to work with it like you would locally.
|
||||
|
||||
> **Note:** This container runs as a non-root user with sudo access by default. Comment out `"remoteUser": "vscode"` in `.devcontainer/devcontainer.json` if you'd prefer to run as root.
|
||||
|
||||
Some things to try:
|
||||
|
||||
1. **Edit:**
|
||||
- Open `main.rs`
|
||||
- Try adding some code and check out the language features.
|
||||
- Notice that several extensions are already installed in the container, such as Rust support for VS Code, since the `.devcontainer/devcontainer.json` lists a set of extensions, including `"rust-lang.rust"`, to install automatically when the container is created.
|
||||
1. **Terminal:** Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> and type `uname` and other Linux commands from the terminal window.
|
||||
1. **Build, Run, and Debug:**
|
||||
- Open `main.rs`
|
||||
- Add a breakpoint (e.g. on line 8).
|
||||
- Press <kbd>F5</kbd> to launch the app in the container.
|
||||
- Once the breakpoint is hit, try hovering over variables, examining locals, and more.
|
||||
|
||||
## Contributing
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
||||
|
||||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
||||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
## License
|
||||
|
||||
Copyright © Microsoft Corporation All rights reserved.<br />
|
||||
Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
梦宁软件(江苏)有限公司 版权所有
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -3,7 +3,21 @@
|
||||
* Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||
*-------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
|
||||
use std::collections::HashMap;
|
||||
let mut map = HashMap::new();
|
||||
for (i, &num) in nums.iter().enumerate() {
|
||||
if let Some(&j) = map.get(&(target - num)) {
|
||||
return vec![j as i32, i as i32];
|
||||
}
|
||||
map.insert(num, i);
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let name = "VS Code Remote - Containers";
|
||||
println!("Hello, {}!", name);
|
||||
let nums = vec![2, 7, 11, 15];
|
||||
let target = 9;
|
||||
let result = two_sum(nums, target);
|
||||
println!("{:?}", result); // 输出: [0, 1]
|
||||
}
|
||||
Reference in New Issue
Block a user