Skip to content

Commit 551769e

Browse files
authored
chore: improve development environment (#353)
* chore: add vscode dev template * chore(vscode): makes auto detecting the rust std sourcemap when debugging * chore(devcontainer): add `vscode-lldb` * chore(devcontainer): mapping rust std source map to lldb by default * chore(devcontainer): support dind
1 parent e27ffca commit 551769e

File tree

9 files changed

+165
-8
lines changed

9 files changed

+165
-8
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
}
99
},
1010
"features": {
11+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
1112
"ghcr.io/jungaretti/features/make:1": {},
1213
"ghcr.io/lee-orr/rusty-dev-containers/cargo-make:0": {}
1314
},
@@ -20,13 +21,17 @@
2021
"customizations": {
2122
"vscode": {
2223
"settings": {
23-
"extensions.verifySignature": false
24+
"extensions.verifySignature": false,
25+
"lldb.launch.preRunCommands": [
26+
"script lldb.debugger.HandleCommand('settings set target.source-map /rustc/{} \"{}/lib/rustlib/src/rust\"'.format(os.popen('rustc --version --verbose').read().split('commit-hash: ')[1].split('\\n')[0].strip(), os.popen('rustc --print sysroot').readline().strip()))"
27+
]
2428
},
2529
"extensions": [
2630
"rust-lang.rust-analyzer",
2731
"eamodio.gitlens",
2832
"ms-azuretools.vscode-docker",
29-
"ms-vscode.hexeditor"
33+
"ms-vscode.hexeditor",
34+
"vadimcn.vscode-lldb"
3035
]
3136
}
3237
}

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
target/
2+
k6/
3+
examples/
4+
assets/
5+
.vscodes/
6+
.github/
7+
8+
scripts/*
9+
!scripts/install_onnx.sh
10+
!scripts/download_models.sh

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# Generated by Cargo
2-
# will have compiled files and executables
31
debug/
42
target/
53
temp/
64
.idea/
75
.idea
6+
7+
.vscode/*
8+
!.vscode/launch.template.jsonc
9+
!.vscode/settings.template.jsonc
10+
811
scripts/debug.sh
912

1013
node_modules/

.vscode/launch.template.jsonc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
3+
Copy this file into '.vscode/launch.json' or merge its contents into your existing
4+
configurations.
5+
6+
*/
7+
8+
{
9+
"configurations": [
10+
{
11+
"name": "Debug Runtime",
12+
"type": "lldb",
13+
"request": "launch",
14+
"cargo": {
15+
"args": [
16+
"build",
17+
"--bin=edge-runtime",
18+
"--features=cli/tracing"
19+
],
20+
"filter": {
21+
"kind": "bin"
22+
}
23+
},
24+
"cwd": "${workspaceFolder}",
25+
"sourceLanguages": [
26+
"rust"
27+
],
28+
"args": [
29+
"-v",
30+
"start",
31+
"--main-service",
32+
"./examples/main",
33+
"--event-worker",
34+
"./examples/event-manager"
35+
36+
// To enable the inspector capability, uncomment the line below.
37+
// "--inspect-brk"
38+
39+
// If you want to listen to the inspect session on a different port, uncomment the
40+
// line below instead.
41+
// "--inspect-brk=127.0.0.1:<PORT>"
42+
43+
// If you want to allow an inspector session to be created on the main worker,
44+
// uncomment the line below.
45+
//
46+
// This flag must be used in combination with the flag above.
47+
// "--inspect-main"
48+
],
49+
"env": {
50+
"RUST_BACKTRACE": "full",
51+
"EDGE_RUNTIME_PORT": "9998"
52+
53+
// If you want to get a detailed log, uncomment below.
54+
// Value of environment variable below is described in detail in the links below:
55+
// https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
56+
// "RUST_LOG": "trace"
57+
}
58+
},
59+
{
60+
"name": "Attach V8 Inspector",
61+
"type": "node",
62+
"address": "127.0.0.1",
63+
"request": "attach",
64+
"localRoot": "/",
65+
"remoteRoot": "/",
66+
"timeout": 1000000,
67+
68+
// Properties below are optional.
69+
"restart": true,
70+
71+
// Inspector is accepting sessions on 9229 by default. If you changed the listening port
72+
// via the inspector flag above, this value must also be changed.
73+
"port": 9229
74+
}
75+
]
76+
}

.vscode/settings.template.jsonc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
3+
Copy this file into '.vscode/settings.json' or merge its contents into your existing
4+
configurations.
5+
6+
*/
7+
8+
{
9+
"lldb.launch.preRunCommands": [
10+
"script lldb.debugger.HandleCommand('settings set target.source-map /rustc/{} \"{}/lib/rustlib/src/rust\"'.format(os.popen('rustc --version --verbose').read().split('commit-hash: ')[1].split('\\n')[0].strip(), os.popen('rustc --print sysroot').readline().strip()))"
11+
],
12+
"rust-analyzer.cargo.features": [
13+
"cli/tracing"
14+
],
15+
"rust-analyzer.diagnostics.disabled": [
16+
"E0308"
17+
],
18+
"editor.rulers": [
19+
100
20+
]
21+
}

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,8 @@ faster-hex = "0.9.0"
8383
#[patch.crates-io]
8484
#deno_core = { path = "/your/path/to/deno_core/core" }
8585

86+
[profile.dind]
87+
inherits = "dev"
88+
8689
[profile.release]
8790
lto = true

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FROM rust:1.74.1-bookworm as builder
33
ARG TARGETPLATFORM
44
ARG GIT_V_VERSION
55
ARG ONNXRUNTIME_VERSION=1.17.0
6+
ARG PROFILE=release
7+
ARG FEATURES
8+
69
RUN apt-get update && apt-get install -y llvm-dev libclang-dev clang cmake
710
WORKDIR /usr/src/edge-runtime
811

@@ -11,9 +14,9 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} \
1114
COPY . .
1215

1316
RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} --mount=type=cache,target=/usr/src/edge-runtime/target,id=${TARGETPLATFORM} \
14-
GIT_V_TAG=${GIT_V_VERSION} cargo build --release && \
17+
GIT_V_TAG=${GIT_V_VERSION} cargo build --profile ${PROFILE} --features "${FEATURES}" && \
1518
cargo strip && \
16-
mv /usr/src/edge-runtime/target/release/edge-runtime /root
19+
mv /usr/src/edge-runtime/target/${PROFILE}/edge-runtime /root
1720

1821
RUN ./scripts/install_onnx.sh $ONNXRUNTIME_VERSION $TARGETPLATFORM /root/libonnxruntime.so
1922
RUN ./scripts/download_models.sh

scripts/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
# --features cli/tracing
4-
GIT_V_TAG=0.1.1 cargo build && EDGE_RUNTIME_PORT=9998 RUST_BACKTRACE=full ./target/debug/edge-runtime "$@" start \
4+
GIT_V_TAG=0.1.1 cargo build --features cli/tracing && \
5+
EDGE_RUNTIME_PORT=9998 RUST_BACKTRACE=full ./target/debug/edge-runtime "$@" start \
56
--main-service ./examples/main \
6-
--event-worker ./examples/event-manager
7+
--event-worker ./examples/event-manager

scripts/run_dind.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
GIT_V_TAG=0.1.1
4+
EDGE_RUNTIME_PORT=9998
5+
ONNXRUNTIME_VERSION=1.17.0
6+
FEATURES=cli/tracing
7+
RUST_BACKTRACE=full
8+
9+
SCRIPT=$(readlink -f "$0")
10+
SCRIPTPATH=$(dirname "$SCRIPT")
11+
12+
cd $SCRIPTPATH && \
13+
docker build \
14+
-t edge_runtime \
15+
--build-arg GIT_V_TAG=$GIT_V_TAG \
16+
--build-arg ONNXRUNTIME_VERSION=$ONNXRUNTIME_VERSION \
17+
--build-arg PROFILE=dind \
18+
--build-arg FEATURES=$FEATURES \
19+
"$SCRIPTPATH/.."
20+
21+
docker run \
22+
--privileged \
23+
--rm \
24+
-it \
25+
-p $EDGE_RUNTIME_PORT:$EDGE_RUNTIME_PORT \
26+
-w /home/deno \
27+
-v "$SCRIPTPATH/../examples:/home/deno/examples" \
28+
-e EDGE_RUNTIME_PORT=$EDGE_RUNTIME_PORT \
29+
-e RUST_BACKTRACE=$RUST_BACKTRACE \
30+
-e RUST_LOG=$RUST_LOG \
31+
edge_runtime:latest \
32+
start \
33+
-p $EDGE_RUNTIME_PORT \
34+
--main-service ./examples/main \
35+
--event-worker ./examples/event-manager \
36+
--static "./examples/**/*.bin"

0 commit comments

Comments
 (0)