Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
rust-tide: Move to gdb remote and add vscode support (#825)
Browse files Browse the repository at this point in the history
* Move to gdb remote and add vscode support

* remove launch.json comments and gdb install info

* update to tide 0.10

* dockerfile for base

* fix copy error

* add logging to base server

* update base reference

* include test library implementation

Co-authored-by: Kamran Shamsi <45264227+Kamran64@users.noreply.github.com>
  • Loading branch information
No9 and Kamran64 authored Jun 11, 2020
1 parent 4bd9aeb commit f240fc2
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 26 deletions.
37 changes: 20 additions & 17 deletions experimental/rust-tide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,35 @@ Templates are used to create your local project and start your development. When
}
```

1. Your application will be rebuild and republished so refresh http://localhost:8000/ it will now say `Hello, Tide`
1. Your application will rebuild and republish so refresh http://localhost:8000/ it will now say `Hello, Tide`


## Debugging

To debug your application running in a container, start the container using:
This stack is configured to run a remote gdb server in the app container.
You can connect to the gdb server on localhost:1234 with the tools of your choice.
However the stack also comes preconfigured to integrate with VSCode and you can debug the application with the following steps:

```bash
appsody debug --docker-options "--cap-add=SYS_PTRACE --security-opt seccomp=unconfined"
```
1. Start the container in debug mode
This is done by pressing `CTRL + SHFT + B` and selecting `Appsody: debug`
Or through the menu option `Terminal --> Run Task --> Appsody: debug`
The command will start the the app with the gdb server and wait for incoming connections from any address to port 1234.

The command will start the LLDB platform and wait for incoming connections from any address to port 1234.
2. Run the Appsody copy task to get the symbols for the the local debugger.
This is done by pressing `CTRL + SHFT + B` and selecting `Appsody: copy`
Or through the menu option `Terminal --> Run Task --> Appsody: copy`

3. Now we can debug the program with pressing `F5`
Or through the menu option `Run --> Start Debugging`

You can connect `lldb` in remote debug mode to this container as follows:
4. See https://code.visualstudio.com/docs/cpp/cpp-debug for more information on using the debugger.

```bash
lldb \
-o "platform select remote-linux" \
-o "platform connect connect://localhost:1234" \
-o "platform settings -w /project/server/bin/target/debug" \
-o "file rust-tide-server"
If the debugger returns an error like
```

Once in lldb, you can use `breakpoint set` to set breakpoints in your application, and then `run` to start the app.

**NOTE:** Due to a current limitation, breakpoints must be set _before_ the application is run. Breakpoints can be disabled, but cannot be re-enabled without restarting the app. After adding or re-enabling breakpoints, restart the app with `process kill` and then `run`.
Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path to debugger...
```
You may need to install `gdb` on your system.
See Linux(https://code.visualstudio.com/docs/cpp/config-linux), [Mac](https://code.visualstudio.com/docs/cpp/config-clang-mac), [Windows](https://code.visualstudio.com/docs/cpp/cpp-debug#_windows-debugging-with-gdb) for OS specific information.

## License

Expand Down
9 changes: 5 additions & 4 deletions experimental/rust-tide/image/Dockerfile-stack
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
FROM rust:1.43.1-buster

RUN apt-get update && apt-get install -y lldb
RUN apt-get update && apt-get install -y gdbserver

ENV CARGO_HOME=/usr/local/cargo/deps

ENV APPSODY_MOUNTS=/:/project/user-app
ENV APPSODY_DEPS=$CARGO_HOME
ENV APPSODY_WATCH_DIR=/project/user-app
ENV APPSODY_WATCH_REGEX="^(Cargo.toml|.*.rs)$"
ENV APPSODY_WATCH_IGNORE_DIR=/project/server/bin/target;/project/user-app/target
ENV APPSODY_PROJECT_DIR=/project
ENV APPSODY_RUN="cargo run --manifest-path ../server/bin/Cargo.toml"
ENV APPSODY_RUN_ON_CHANGE=$APPSODY_RUN
ENV APPSODY_RUN_KILL=true

ENV APPSODY_DEBUG="cargo build --manifest-path ../server/bin/Cargo.toml && lldb-server platform --listen '*:1234' --min-gdbserver-port 5000 --max-gdbserver-port 5001 --server"
ENV APPSODY_DEBUG="cargo build --manifest-path ../server/bin/Cargo.toml && gdbserver localhost:1234 /project/server/bin/target/debug/rust-tide-server"
ENV APPSODY_DEBUG_ON_CHANGE="$APPSODY_DEBUG"
ENV APPSODY_DEBUG_KILL=true

ENV APPSODY_TEST="cargo test --manifest-path /project/user-app/Cargo.toml"
ENV APPSODY_TEST="/project/test-stack.sh"
ENV APPSODY_TEST_ON_CHANGE=$APPSODY_TEST
ENV APPSODY_TEST_KILL=false
ENV APPSODY_TEST_KILL=true

COPY ./LICENSE /licenses/
COPY ./project /project
Expand Down
2 changes: 1 addition & 1 deletion experimental/rust-tide/image/project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/number9/rust-tide:0.1.0 as server
FROM docker.io/number9/rust-tide-base:0.2.0 as server

FROM rust:1.43.1-buster as builder

Expand Down
2 changes: 1 addition & 1 deletion experimental/rust-tide/image/project/server/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tide = { version = "0.9" }
tide = { version = "0.10" }
async-std = { version = "1" }
application = { package = "rust-tide-default", path = "/project/user-app"}
12 changes: 12 additions & 0 deletions experimental/rust-tide/image/project/server/bin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM rust:1.43.1-buster
# This file is used to publish the server as a base image.
# docker build -t docker.io/number9/rust-tide-base:v1.0.0 .
# docker push docker.io/number9/rust-tide-base:v1.0.0 .

WORKDIR "/project/server/bin"

COPY Cargo.toml ./

WORKDIR "/project/server/bin/src"

COPY src ./
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn main() -> Result<(), std::io::Error> {
let port = env::var("PORT").unwrap_or_else(|_| "8000".to_string());
let address = format!("0.0.0.0:{}", port);
task::block_on(async {
tide::log::start();
let mut app = tide::new();
app.at("/").nest({
application::app()
Expand Down
12 changes: 12 additions & 0 deletions experimental/rust-tide/image/project/test-stack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

cargo build --manifest-path ../server/bin/Cargo.toml
cargo run --manifest-path ../server/bin/Cargo.toml &

until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:8000); do
printf '.';
sleep 0.2;
done

cargo test --manifest-path ../server/bin/Cargo.toml -p rust-tide-default
kill -9 $(pidof rust-tide-server)
2 changes: 1 addition & 1 deletion experimental/rust-tide/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Rust Tide
version: 0.1.0
version: 0.2.0
description: Tide web framework for Rust
license: Apache-2.0
language: rust
Expand Down
26 changes: 26 additions & 0 deletions experimental/rust-tide/templates/default/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/rust-tide-server",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerServerAddress": "localhost:1234",
"serverLaunchTimeout": 1000,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
13 changes: 12 additions & 1 deletion experimental/rust-tide/templates/default/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Appsody: copy",
"type": "shell",
"command": "bash",
"args": [
"-c",
"\"docker cp `docker ps | grep \"rust-tide\" | awk '{ print $1 }'`:/project/server/bin/target/debug/rust-tide-server .\"",
],
"group": "build",
"problemMatcher": []
},
{
"label": "Appsody: run",
"type": "shell",
Expand All @@ -11,7 +22,7 @@
{
"label": "Appsody: debug",
"type": "shell",
"command": "appsody debug",
"command": "appsody debug --docker-options \"--cap-add=SYS_PTRACE --security-opt seccomp=unconfined\"",
"group": "build",
"problemMatcher": []
},
Expand Down
5 changes: 4 additions & 1 deletion experimental/rust-tide/templates/default/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tide = { version = "0.9" }
tide = { version = "0.10" }
http-types = "2.0.1"
async-std = { version = "1" }
surf = { version = "2.0.0-alpha.3", default-features = false, features = ["h1-client"] }
13 changes: 13 additions & 0 deletions experimental/rust-tide/templates/default/tests/test-lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use async_std::task;

#[test]
fn hello_world() -> Result<(), http_types::Error> {
task::block_on(async {
let string = surf::get(format!("http://127.0.0.1:{}", 8000))
.recv_string()
.await
.unwrap();
assert_eq!(string, "Hello, world!".to_string());
Ok(())
})
}

0 comments on commit f240fc2

Please sign in to comment.