Skip to content

Commit 20e1571

Browse files
committed
added devcontainer
1 parent 0bceeb2 commit 20e1571

11 files changed

Lines changed: 337 additions & 6 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
################################################################################
2+
# Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
################################################################################
13+
14+
FROM mcr.microsoft.com/devcontainers/rust:latest
15+
ARG USERNAME=vscode
16+
ARG TARGETARCH
17+
18+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
19+
&& apt-get -y install \
20+
curl \
21+
gcc \
22+
git \
23+
openjdk-17-jre \
24+
zip \
25+
&& \
26+
rm -rf /var/lib/apt/lists/*
27+
28+
# Download openfasttrace JARs and create shortcut oft executable
29+
ARG OFT_CORE_VERSION=4.1.0
30+
ARG OFT_ASCIIDOC_PLUGIN_VERSION=0.3.0
31+
ENV LIB_DIR=/opt/oft/lib
32+
RUN mkdir -p $LIB_DIR \
33+
&& base_url=https://github.com/itsallcode \
34+
&& wget -P $LIB_DIR ${base_url}/openfasttrace/releases/download/$OFT_CORE_VERSION/openfasttrace-$OFT_CORE_VERSION.jar \
35+
&& wget -P $LIB_DIR ${base_url}/openfasttrace-asciidoc-plugin/releases/download/$OFT_ASCIIDOC_PLUGIN_VERSION/openfasttrace-asciidoc-plugin-$OFT_ASCIIDOC_PLUGIN_VERSION-with-dependencies.jar \
36+
&& echo '#!/bin/bash\n\njava -cp "${LIB_DIR}/*" org.itsallcode.openfasttrace.core.cli.CliStarter "$@"' > /usr/local/bin/oft \
37+
&& chmod +x /usr/local/bin/oft
38+
39+
# Before installing cargo tools, change to the user that will be used in the container later.
40+
# The reason is that cargo creates some cache, etc. folders with the correct group rustlang, but
41+
# without making them group writable. Easiest fix is to change to the correct user before the install,
42+
# so that the owner is correct from the start.
43+
USER ${USERNAME}
44+
45+
# Install cargo cli tools
46+
RUN cargo install cargo-nextest cargo-deny cargo-tarpaulin --locked
47+
RUN sudo apt update && \
48+
sudo apt install -y libclang-dev

.devcontainer/devcontainer.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
3+
{
4+
"name": "up-transport-iceoryx2-rust",
5+
"build": {
6+
"dockerfile": "Dockerfile"
7+
},
8+
"runArgs": [
9+
"--privileged"
10+
],
11+
"containerEnv": {
12+
"WORKSPACE_FOLDER": "${containerWorkspaceFolder}"
13+
},
14+
"mounts": [
15+
{
16+
// This is a workaround which is again necessary on MacOS 14.0, it looks like this bug is back:
17+
// https://github.com/microsoft/vscode-dev-containers/issues/1487#issuecomment-1143907307
18+
"type": "volume",
19+
"source": "rust-volume",
20+
"target": "/rust-volume"
21+
},
22+
{
23+
"type": "bind",
24+
"source": "${localWorkspaceFolder}/.devcontainer/scripts",
25+
"target": "/home/vscode/scripts"
26+
},
27+
{
28+
"type": "bind",
29+
"source": "${localEnv:HOME}${localEnv:USERPROFILE}/.ssh",
30+
"target": "/home/vscode/.ssh"
31+
}
32+
],
33+
"postCreateCommand": ".devcontainer/scripts/post-create.sh --workspace-folder='${containerWorkspaceFolder}'",
34+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace/${localWorkspaceFolderBasename}/,type=bind",
35+
"workspaceFolder": "/workspace/${localWorkspaceFolderBasename}/",
36+
"remoteUser": "vscode",
37+
"customizations": {
38+
"vscode": {
39+
// Set *default* container specific settings.json values on container create.
40+
"settings": {
41+
"lldb.executable": "/usr/bin/lldb",
42+
// VS Code don't watch files under ./target
43+
"files.watcherExclude": {
44+
"**/target/**": true
45+
},
46+
"rust-analyzer.check.command": "clippy",
47+
"rust-analyzer.checkOnSave": true,
48+
"coverage-gutters.coverageBaseDir": "**",
49+
"coverage-gutters.coverageFileNames": [
50+
"target/tarpaulin/lcov.info"
51+
]
52+
},
53+
// Add the IDs of extensions you want installed when the container is created.
54+
"extensions": [
55+
"asciidoctor.asciidoctor-vscode",
56+
"bianxianyang.htmlplay",
57+
"bierner.markdown-mermaid",
58+
"bierner.markdown-preview-github-styles",
59+
"davidanson.vscode-markdownlint",
60+
"gxl.git-graph-3",
61+
"hediet.vscode-drawio",
62+
"linusu.auto-dark-mode",
63+
"ms-azuretools.vscode-containers",
64+
"rust-lang.rust-analyzer",
65+
"streetsidesoftware.code-spell-checker",
66+
"tamasfe.even-better-toml",
67+
"timonwong.shellcheck",
68+
"vadimcn.vscode-lldb",
69+
"yzhang.markdown-all-in-one"
70+
]
71+
}
72+
}
73+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
if [ -d "$HOME/.ssh" ]; then
4+
source ${WORKSPACE_FOLDER}/.devcontainer/scripts/ensure-ssh-permissions.sh
5+
fi
6+
source ${WORKSPACE_FOLDER}/.devcontainer/scripts/colors.sh
7+
8+
PRIMARY_COLOR=$COLOR_GRAY
9+
SECONDARY_COLOR=$COLOR_NC
10+
INFO_COLOR=$COLOR_CYAN
11+
12+
WELCOME_INFO="${SECONDARY_COLOR}
13+
██ ██ ███████ ██ ██████ ██████ ███ ███ ███████
14+
██ ██ ██ ██ ██ ██ ██ ████ ████ ██
15+
██ █ ██ █████ ██ ██ ██ ██ ██ ████ ██ █████
16+
██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
17+
███ ███ ███████ ███████ ██████ ██████ ██ ██ ███████
18+
${PRIMARY_COLOR}
19+
to the Eclipse Foundation ${INFO_COLOR}$(basename "$WORKSPACE_FOLDER")${PRIMARY_COLOR} code repository
20+
21+
Workspace Folder ${SECONDARY_COLOR}$WORKSPACE_FOLDER
22+
23+
${INFO_COLOR}Library Version(s)${PRIMARY_COLOR}
24+
Rust Version ${SECONDARY_COLOR}$(rustc --version)${PRIMARY_COLOR}
25+
Cargo Version ${SECONDARY_COLOR}$(cargo --version)${PRIMARY_COLOR}
26+
27+
${INFO_COLOR}Git${PRIMARY_COLOR}
28+
Username ${SECONDARY_COLOR}$(git config user.name)${PRIMARY_COLOR}
29+
Email ${SECONDARY_COLOR}$(git config user.email)${PRIMARY_COLOR}
30+
31+
to see this info again, use the ${INFO_COLOR}welcome${PRIMARY_COLOR} command${COLOR_NC}
32+
"
33+
34+
alias welcome='printf "$WELCOME_INFO"'
35+
welcome

.devcontainer/scripts/colors.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
export COLOR_NC='\e[0m' # No Color
4+
export COLOR_BLACK='\e[0;30m'
5+
export COLOR_GRAY='\e[1;30m'
6+
export COLOR_RED='\e[0;31m'
7+
export COLOR_LIGHT_RED='\e[1;31m'
8+
export COLOR_GREEN='\e[0;32m'
9+
export COLOR_LIGHT_GREEN='\e[1;32m'
10+
export COLOR_BROWN='\e[0;33m'
11+
export COLOR_YELLOW='\e[1;33m'
12+
export COLOR_BLUE='\e[0;34m'
13+
export COLOR_LIGHT_BLUE='\e[1;34m'
14+
export COLOR_PURPLE='\e[0;35m'
15+
export COLOR_LIGHT_PURPLE='\e[1;35m'
16+
export COLOR_CYAN='\e[0;36m'
17+
export COLOR_LIGHT_CYAN='\e[1;36m'
18+
export COLOR_LIGHT_GRAY='\e[0;37m'
19+
export COLOR_WHITE='\e[1;37m'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Sometimes when mounting volumes, the files unexpectedly change their read-write-execute status.
4+
# This is dependent on the OS the Docker container is mounting from, and how it exposes its
5+
# files permissions, ownership, and "executability" to the container and the containers user.
6+
#
7+
# More about specific permissions inside the .ssh folder
8+
# https://serverfault.com/a/253314
9+
sudo find ~/.ssh -maxdepth 1 -type f -exec chmod 600 {} \;
10+
chmod u+r ~/.ssh/config
11+
chmod u+r ~/.ssh/known_hosts
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
get_arch_and_os() {
4+
ARCH=$(uname -m)
5+
OS=$(uname -s | tr "[:upper:]" "[:lower:]")
6+
7+
case "$ARCH" in
8+
x86_64)
9+
TARGET_ARCH="x86_64"
10+
;;
11+
aarch64 | arm64)
12+
TARGET_ARCH="aarch64"
13+
;;
14+
*)
15+
echo "Unsupported architecture: $ARCH"
16+
exit 1
17+
;;
18+
esac
19+
20+
case "$OS" in
21+
linux)
22+
TARGET_OS="unknown-linux-gnu"
23+
;;
24+
*)
25+
echo "OS is unsupported or not implemented in this script: $OS"
26+
exit 1
27+
;;
28+
esac
29+
echo "$TARGET_ARCH $TARGET_OS"
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
install_rust_toolchain() {
4+
source ${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/get-arch-and-os.sh
5+
read -r TARGET_ARCH TARGET_OS <<< "$(get_arch_and_os)"
6+
ARCH_AND_OS="${TARGET_ARCH}-${TARGET_OS}"
7+
echo "Detected architecture and OS: $ARCH_AND_OS"
8+
RUST_TOOLCHAIN="stable-$ARCH_AND_OS"
9+
if rustup toolchain list | grep -q $RUST_TOOLCHAIN; then
10+
echo "Rust toolchain '$RUST_TOOLCHAIN' is already installed."
11+
return 0
12+
fi
13+
echo "Adding rustup target '$ARCH_AND_OS'"
14+
rustup target add "$ARCH_AND_OS"
15+
echo "Installing Rust toolchain for '$ARCH_AND_OS'"
16+
rustup toolchain install "$RUST_TOOLCHAIN"
17+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
#region sudo stuff
4+
5+
HOST_OS=""
6+
ARCH_AND_OS_FUNC="${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/get-arch-and-os.sh"
7+
if [[ -f "$ARCH_AND_OS_FUNC" ]]; then
8+
source $ARCH_AND_OS_FUNC
9+
read -r _ HOST_OS <<< "$(get_arch_and_os)"
10+
fi
11+
if [[ "$HOST_OS" == "darwin" ]]; then # darwin == Mac OS
12+
# This is a workaround which is againt necessary on MacOS 14.0, it looks like this bug is back:
13+
# https://github.com/microsoft/vscode-dev-containers/issues/1487#issuecomment-1143907307
14+
# grant permissions to mounted rust volume
15+
echo "(Mac OS only) Granting permissions to mounted rust volume"
16+
sudo chown vscode:vscode /rust-volume
17+
18+
# create /.cargo/config.toml in root folder
19+
sudo mkdir /.cargo/
20+
sudo touch /.cargo/config.toml
21+
sudo bash -c "cat << EOF > /.cargo/config.toml
22+
[build]
23+
target-dir = \"/rust-volume/target\"
24+
EOF"
25+
fi
26+
27+
if ! grep -q "bashrc_addition" ~/.bashrc && [[ -f "${WORKSPACE_FOLDER}/.devcontainer/scripts/bashrc_addition.sh" ]]; then
28+
echo "source ${WORKSPACE_FOLDER}/.devcontainer/scripts/bashrc_addition.sh" >> ~/.bashrc
29+
fi
30+
31+
#endregion
32+
33+
for arg in "$@"; do
34+
if [[ "$arg" == --workspace-folder=* ]]; then
35+
WORKSPACE_FOLDER="${arg#--workspace-folder=}"
36+
fi
37+
done
38+
INSTALL_RUST_TOOLCHAIN_FUNC="${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/install-rust-toolchain.sh"
39+
if [[ -f "$INSTALL_RUST_TOOLCHAIN_FUNC" ]]; then
40+
source $INSTALL_RUST_TOOLCHAIN_FUNC
41+
install_rust_toolchain "$@"
42+
fi

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"activityBar.background": "#422809",
4+
"titleBar.activeBackground": "#5D380D",
5+
"titleBar.activeForeground": "#FDF9F3"
6+
}
7+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use up_rust::{UCode, UStatus, UUri};
2+
3+
pub(crate) fn verify_filter_criteria(
4+
source_filter: &UUri,
5+
sink_filter: Option<&UUri>,
6+
) -> Result<(), UStatus> {
7+
if let Some(sink_filter_uuri) = sink_filter {
8+
if sink_filter_uuri.is_notification_destination()
9+
&& source_filter.is_notification_destination()
10+
{
11+
return Err(UStatus::fail_with_code(
12+
UCode::INVALID_ARGUMENT,
13+
"source and sink filters must not both have resource ID 0",
14+
));
15+
}
16+
if sink_filter_uuri.is_rpc_method()
17+
&& !source_filter.has_wildcard_resource_id()
18+
&& !source_filter.is_notification_destination()
19+
{
20+
return Err(UStatus::fail_with_code(UCode::INVALID_ARGUMENT, "source filter must either have the wildcard resource ID or resource ID 0, if sink filter matches RPC method resource ID"));
21+
}
22+
} else if !source_filter.has_wildcard_resource_id() && !source_filter.is_event() {
23+
return Err(UStatus::fail_with_code(UCode::INVALID_ARGUMENT, "source filter must either have the wildcard resource ID or a resource ID from topic range, if sink filter is empty"));
24+
}
25+
// everything else might match valid messages
26+
Ok(())
27+
}
28+
29+
30+
#[cfg(test)]
31+
mod tests {
32+
use super::*;
33+
34+
fn test_uri(authority: &str, instance: u16, typ: u16, version: u8, resource: u16) -> UUri {
35+
let entity_id = ((instance as u32) << 16) | (typ as u32);
36+
UUri::try_from_parts(authority, entity_id, version, resource).unwrap()
37+
}
38+
39+
// performing successful tests for service name computation
40+
41+
#[test]
42+
// [specitem,oft-sid="dsn~up-transport-iceoryx2-service-name~1",oft-needs="utest"]
43+
fn test_publish_service_name() {
44+
let source = test_uri("device1", 0x0000, 0x10AB, 0x03, 0x7FFF);
45+
46+
let name = Iceoryx2Transport::compute_service_name(&source, None).unwrap();
47+
assert_eq!(name, "up/device1/10AB/0/3/7FFF");
48+
}
49+
}

0 commit comments

Comments
 (0)