Skip to content

Commit

Permalink
chore: add devcontainer setup and contribution guide
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed Oct 1, 2022
1 parent 9388a08 commit e10d101
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM dev:rust

USER root

RUN rustup component add rustfmt clippy && \
rustup target add x86_64-pc-windows-gnu && \
apk add --no-cache mingw-w64-gcc musl-dev && \
ln -s /usr/x86_64-w64-mingw32/lib/liboleaut32.a /usr/x86_64-w64-mingw32/lib/libOleAut32.a

RUN apk update && apk add --no-cache nodejs npm

RUN npm i -g yarn

USER rust
66 changes: 66 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "${containerWorkspaceFolderBasename}",
"dockerFile": "Dockerfile",
"remoteEnv": {
"WSL_HOST_IP": "${localEnv:WSL_HOST_IP}",
"WSL_IP": "${localEnv:WSL_IP}"
},
"runArgs": [
"--env-file",
"${localWorkspaceFolder}/.env"
],
"mounts": [
"type=bind,src=${localWorkspaceFolder}/.devcontainer/fish-history,dst=/home/rust/.local/share/fish",
"type=bind,src=${localEnv:HOME}/.blueprints,dst=/home/rust/.blueprints",
"type=bind,src=${localEnv:HOME}/.ssh,dst=/home/rust/.ssh,readonly",
"type=volume,src=rust-global-cache,dst=/usr/local/cargo/registry",
"type=volume,src=yarn-global-cache,dst=/home/rust/.yarn/berry/cache",
// DEBUG: for debug purpose only
"type=bind,src=${localWorkspaceFolder}/../mystic-light-sdk,dst=/workspaces/mystic-light-sdk"
],
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
// common
"alefragnani.bookmarks",
"orepor.color-tabs-vscode-ext",
"rudijansenvanvuuren.blueprints",
"naumovs.color-highlight",
"EditorConfig.EditorConfig",
"vscode-snippet.Snippet",
// md
"yzhang.markdown-all-in-one",
"hediet.vscode-drawio",
// yaml
"redhat.vscode-yaml",
// string
"qcz.text-power-tools",
"britesnow.vscode-toggle-quotes",
// git
"eamodio.gitlens",
"mhutchie.git-graph",
"vivaxy.vscode-conventional-commits",
// spell checker
"streetsidesoftware.code-spell-checker",
"streetsidesoftware.code-spell-checker-russian",
// debug
"hediet.debug-visualizer",
// rust
"rust-lang.rust-analyzer",
"serayuzgur.crates",
"vadimcn.vscode-lldb",
"bungcip.better-toml",
// js-ts
"dbaeumer.vscode-eslint"
],
// 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": "sudo chown rust /usr/local/cargo/registry && sudo chown rust /home/rust/.yarn/berry",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "node"
"containerEnv": {
"CONTAINER_PROJECT_HOME": "${containerWorkspaceFolder}",
"HOST_PROJECT_HOME": "${localWorkspaceFolder}",
"MYSTIC_LIGHT_SDK_PATH": "${containerWorkspaceFolder}/native-app/sdk"
}
}
12 changes: 12 additions & 0 deletions .devcontainer/execute.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env fish

echo "Run any cargo command"

while true
set path (cat .devcontainer/command-pipe)

kill %1
reset

eval "RUST_BACKTRACE=1 $path &"
end
3 changes: 3 additions & 0 deletions .devcontainer/send.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env fish

echo (string replace $CONTAINER_PROJECT_HOME $HOST_PROJECT_HOME (realpath $argv)) > ../.devcontainer/command-pipe
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
},
"eslint.nodePath": "chrome-extension/.yarn/sdks",
"prettier.prettierPath": "chrome-extension/.yarn/sdks/prettier/index.js",
"typescript.tsdk": "chrome-extension/.yarn/sdks/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"conventionalCommits.scopes": [
"native-app",
"chrome-extension"
]
}
51 changes: 51 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contributing

Make sure you have Rust toolchain installed

## Setup

## Linux

**You won't be able to execute program or run tests as sdk supports only windows**

1. Add windows target `rustup target add x86_64-pc-windows-gnu`
2. Add MinGW (e.g. for the alpine `apk add mingw-w64-gcc`)
3. Specify target by env `CARGO_BUILD_TARGET=x86_64-pc-windows-gnu`

You can now build some of the bin using `cargo build --bin app`, but you have to run it on any other windows machine with the Dragon Center installed.


## Windows

Should work without any hassle.

Run `cargo run` to run app server

### WSL 2

There is a catch - wsl 2 runs in linux environment, but it still can run windows executable, so we can use WSL 2 linux environment to build actual program and then run built .exe file

1. Install additional libs to able to build windows app following [linux instructions](#linux)
2. Open WSL2 Terminal as Administrator
3. Go to `native-app` directory
4. Run `cargo run`


### WSL 2 + Docker

If you are using Rust inside Docker container you not able to run .exe files from inside it, but you can use named pipe to pass commands to the host WSL 2 instance that able to run .exe

For this either use Remote Containers extension with the provided `.devcontainer` setup or follow next instruction:

1. Install additional libs to able to build windows app following [linux instructions](#linux)
2. Mount existing named pipe and scripts to the docker container `type=bind,src=${localWorkspaceFolder}/.devcontainer,dst=${containerWorkspaceFolder}/.devcontainer`
3. Specify environment variables for container:
- `CONTAINER_PROJECT_HOME` - path to the project inside the container
- `HOST_PROJECT_HOME` - path to projects in WSL
- `MYSTIC_LIGHT_SDK_PATH` - absolute path to `native-app/sdk` library
- `CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER` - relative path to `.devcontainer/send.fish` script
4. Run the container
5. You can use `wsl2-docker.env` in order to fill needed environment variable that will wrap execution for the program run
6. Start new WSL terminal with admin right and execute script `.devcontainer/execute.fish` that will listen for new commands and execute it
7. Run `cargo run` inside the container
8. Execution will end without any info, but you should see test running output in the WSL terminal
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CARGO_BUILD_TARGET=x86_64-pc-windows-gnu
2 changes: 2 additions & 0 deletions wsl2-docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CARGO_BUILD_TARGET=x86_64-pc-windows-gnu
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER=../.devcontainer/send.fish
1 change: 1 addition & 0 deletions wsl2.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CARGO_BUILD_TARGET=x86_64-pc-windows-gnu

0 comments on commit e10d101

Please sign in to comment.