diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..61db02e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,48 @@ +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +FROM mcr.microsoft.com/devcontainers/rust:latest +ARG USERNAME=vscode +ARG TARGETARCH + +RUN apt-get update && \ + export DEBIAN_FRONTEND=noninteractive && \ + apt-get -y install \ + curl \ + gcc \ + git \ + openjdk-17-jre \ + zip \ + libclang-dev \ + && \ + rm -rf /var/lib/apt/lists/* + +# Download openfasttrace JARs and create shortcut oft executable +ARG OFT_CORE_VERSION=4.1.0 +ARG OFT_ASCIIDOC_PLUGIN_VERSION=0.3.0 +ENV LIB_DIR=/opt/oft/lib +RUN mkdir -p $LIB_DIR \ + && base_url=https://github.com/itsallcode \ + && wget -P $LIB_DIR ${base_url}/openfasttrace/releases/download/$OFT_CORE_VERSION/openfasttrace-$OFT_CORE_VERSION.jar \ + && 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 \ + && echo '#!/bin/bash\n\njava -cp "${LIB_DIR}/*" org.itsallcode.openfasttrace.core.cli.CliStarter "$@"' > /usr/local/bin/oft \ + && chmod +x /usr/local/bin/oft + +# Before installing cargo tools, change to the user that will be used in the container later. +# The reason is that cargo creates some cache, etc. folders with the correct group rustlang, but +# without making them group writable. Easiest fix is to change to the correct user before the install, +# so that the owner is correct from the start. +USER ${USERNAME} + +# Install cargo cli tools +RUN cargo install cargo-nextest cargo-deny cargo-tarpaulin --locked diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..bb056fc --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,86 @@ +// ################################################################################ +// Copyright (c) 2025 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache License Version 2.0 which is available at +// https: //www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: Apache-2.0 +// ################################################################################ +// +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/rust +{ + "name": "up-transport-iceoryx2-rust", + "build": { + "dockerfile": "Dockerfile" + }, + "runArgs": [ + "--privileged" + ], + "containerEnv": { + "WORKSPACE_FOLDER": "${containerWorkspaceFolder}" + }, + "mounts": [ + { + // This is a workaround which is again necessary on MacOS 14.0, it looks like this bug is back: + // https://github.com/microsoft/vscode-dev-containers/issues/1487#issuecomment-1143907307 + "type": "volume", + "source": "rust-volume", + "target": "/rust-volume" + }, + { + "type": "bind", + "source": "${localWorkspaceFolder}/.devcontainer/scripts", + "target": "/home/vscode/scripts" + }, + { + "type": "bind", + "source": "${localEnv:HOME}${localEnv:USERPROFILE}/.ssh", + "target": "/home/vscode/.ssh" + } + ], + "postCreateCommand": ".devcontainer/scripts/post-create.sh --workspace-folder='${containerWorkspaceFolder}'", + "workspaceMount": "source=${localWorkspaceFolder},target=/workspace/${localWorkspaceFolderBasename}/,type=bind", + "workspaceFolder": "/workspace/${localWorkspaceFolderBasename}/", + "remoteUser": "vscode", + "customizations": { + "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.check.command": "clippy", + "rust-analyzer.checkOnSave": true, + "coverage-gutters.coverageBaseDir": "**", + "coverage-gutters.coverageFileNames": [ + "target/tarpaulin/lcov.info" + ] + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "asciidoctor.asciidoctor-vscode", + "bianxianyang.htmlplay", + "bierner.markdown-mermaid", + "bierner.markdown-preview-github-styles", + "davidanson.vscode-markdownlint", + "gxl.git-graph-3", + "hediet.vscode-drawio", + "linusu.auto-dark-mode", + "ms-azuretools.vscode-containers", + "rust-lang.rust-analyzer", + "streetsidesoftware.code-spell-checker", + "tamasfe.even-better-toml", + "timonwong.shellcheck", + "vadimcn.vscode-lldb", + "yzhang.markdown-all-in-one" + ] + } + } +} diff --git a/.devcontainer/scripts/bashrc_addition.sh b/.devcontainer/scripts/bashrc_addition.sh new file mode 100644 index 0000000..6cde26d --- /dev/null +++ b/.devcontainer/scripts/bashrc_addition.sh @@ -0,0 +1,47 @@ +#!/bin/bash +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +if [ -d "$HOME/.ssh" ]; then + source ${WORKSPACE_FOLDER}/.devcontainer/scripts/ensure-ssh-permissions.sh +fi +source ${WORKSPACE_FOLDER}/.devcontainer/scripts/colors.sh + +PRIMARY_COLOR=$COLOR_GRAY +SECONDARY_COLOR=$COLOR_NC +INFO_COLOR=$COLOR_CYAN + +WELCOME_INFO="${SECONDARY_COLOR} +██ ██ ███████ ██ ██████ ██████ ███ ███ ███████ +██ ██ ██ ██ ██ ██ ██ ████ ████ ██ +██ █ ██ █████ ██ ██ ██ ██ ██ ████ ██ █████ +██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ███ ███ ███████ ███████ ██████ ██████ ██ ██ ███████ +${PRIMARY_COLOR} +to the Eclipse Foundation ${INFO_COLOR}$(basename "$WORKSPACE_FOLDER")${PRIMARY_COLOR} code repository + +Workspace Folder ${SECONDARY_COLOR}$WORKSPACE_FOLDER + +${INFO_COLOR}Library Version(s)${PRIMARY_COLOR} +Rust Version ${SECONDARY_COLOR}$(rustc --version)${PRIMARY_COLOR} +Cargo Version ${SECONDARY_COLOR}$(cargo --version)${PRIMARY_COLOR} + +${INFO_COLOR}Git${PRIMARY_COLOR} +Username ${SECONDARY_COLOR}$(git config user.name)${PRIMARY_COLOR} +Email ${SECONDARY_COLOR}$(git config user.email)${PRIMARY_COLOR} + +to see this info again, use the ${INFO_COLOR}welcome${PRIMARY_COLOR} command${COLOR_NC} +" + +alias welcome='printf "$WELCOME_INFO"' +welcome diff --git a/.devcontainer/scripts/colors.sh b/.devcontainer/scripts/colors.sh new file mode 100644 index 0000000..2a61843 --- /dev/null +++ b/.devcontainer/scripts/colors.sh @@ -0,0 +1,31 @@ +#!/bin/bash +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +export COLOR_NC='\e[0m' # No Color +export COLOR_BLACK='\e[0;30m' +export COLOR_GRAY='\e[1;30m' +export COLOR_RED='\e[0;31m' +export COLOR_LIGHT_RED='\e[1;31m' +export COLOR_GREEN='\e[0;32m' +export COLOR_LIGHT_GREEN='\e[1;32m' +export COLOR_BROWN='\e[0;33m' +export COLOR_YELLOW='\e[1;33m' +export COLOR_BLUE='\e[0;34m' +export COLOR_LIGHT_BLUE='\e[1;34m' +export COLOR_PURPLE='\e[0;35m' +export COLOR_LIGHT_PURPLE='\e[1;35m' +export COLOR_CYAN='\e[0;36m' +export COLOR_LIGHT_CYAN='\e[1;36m' +export COLOR_LIGHT_GRAY='\e[0;37m' +export COLOR_WHITE='\e[1;37m' diff --git a/.devcontainer/scripts/ensure-ssh-permissions.sh b/.devcontainer/scripts/ensure-ssh-permissions.sh new file mode 100644 index 0000000..86c33b7 --- /dev/null +++ b/.devcontainer/scripts/ensure-ssh-permissions.sh @@ -0,0 +1,23 @@ +#!/bin/bash +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +# Sometimes when mounting volumes, the files unexpectedly change their read-write-execute status. +# This is dependent on the OS the Docker container is mounting from, and how it exposes its +# files permissions, ownership, and "executability" to the container and the containers user. +# +# More about specific permissions inside the .ssh folder +# https://serverfault.com/a/253314 +sudo find ~/.ssh -maxdepth 1 -type f -exec chmod 600 {} \; +chmod u+r ~/.ssh/config +chmod u+r ~/.ssh/known_hosts diff --git a/.devcontainer/scripts/functions/get-arch-and-os.sh b/.devcontainer/scripts/functions/get-arch-and-os.sh new file mode 100644 index 0000000..5df5502 --- /dev/null +++ b/.devcontainer/scripts/functions/get-arch-and-os.sh @@ -0,0 +1,42 @@ +#!/bin/bash +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +get_arch_and_os() { + ARCH=$(uname -m) + OS=$(uname -s | tr "[:upper:]" "[:lower:]") + + case "$ARCH" in + x86_64) + TARGET_ARCH="x86_64" + ;; + aarch64 | arm64) + TARGET_ARCH="aarch64" + ;; + *) + echo "Unsupported architecture: $ARCH" + exit 1 + ;; + esac + + case "$OS" in + linux) + TARGET_OS="unknown-linux-gnu" + ;; + *) + echo "OS is unsupported or not implemented in this script: $OS" + exit 1 + ;; + esac + echo "$TARGET_ARCH $TARGET_OS" +} diff --git a/.devcontainer/scripts/functions/install-rust-toolchain.sh b/.devcontainer/scripts/functions/install-rust-toolchain.sh new file mode 100755 index 0000000..3c37033 --- /dev/null +++ b/.devcontainer/scripts/functions/install-rust-toolchain.sh @@ -0,0 +1,29 @@ +#!/bin/bash +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +install_rust_toolchain() { + source ${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/get-arch-and-os.sh + read -r TARGET_ARCH TARGET_OS <<< "$(get_arch_and_os)" + ARCH_AND_OS="${TARGET_ARCH}-${TARGET_OS}" + echo "Detected architecture and OS: $ARCH_AND_OS" + RUST_TOOLCHAIN="stable-$ARCH_AND_OS" + if rustup toolchain list | grep -q $RUST_TOOLCHAIN; then + echo "Rust toolchain '$RUST_TOOLCHAIN' is already installed." + return 0 + fi + echo "Adding rustup target '$ARCH_AND_OS'" + rustup target add "$ARCH_AND_OS" + echo "Installing Rust toolchain for '$ARCH_AND_OS'" + rustup toolchain install "$RUST_TOOLCHAIN" +} diff --git a/.devcontainer/scripts/post-create.sh b/.devcontainer/scripts/post-create.sh new file mode 100755 index 0000000..fe036f5 --- /dev/null +++ b/.devcontainer/scripts/post-create.sh @@ -0,0 +1,54 @@ +#!/bin/bash +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +#region sudo stuff + +HOST_OS="" +ARCH_AND_OS_FUNC="${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/get-arch-and-os.sh" +if [[ -f "$ARCH_AND_OS_FUNC" ]]; then + source $ARCH_AND_OS_FUNC + read -r _ HOST_OS <<< "$(get_arch_and_os)" +fi +if [[ "$HOST_OS" == "darwin" ]]; then # darwin == Mac OS + # This is a workaround which is againt necessary on MacOS 14.0, it looks like this bug is back: + # https://github.com/microsoft/vscode-dev-containers/issues/1487#issuecomment-1143907307 + # grant permissions to mounted rust volume + echo "(Mac OS only) Granting permissions to mounted rust volume" + sudo chown vscode:vscode /rust-volume + + # create /.cargo/config.toml in root folder + sudo mkdir /.cargo/ + sudo touch /.cargo/config.toml + sudo bash -c "cat << EOF > /.cargo/config.toml + [build] + target-dir = \"/rust-volume/target\" + EOF" +fi + +if ! grep -q "bashrc_addition" ~/.bashrc && [[ -f "${WORKSPACE_FOLDER}/.devcontainer/scripts/bashrc_addition.sh" ]]; then + echo "source ${WORKSPACE_FOLDER}/.devcontainer/scripts/bashrc_addition.sh" >> ~/.bashrc +fi + +#endregion + +for arg in "$@"; do + if [[ "$arg" == --workspace-folder=* ]]; then + WORKSPACE_FOLDER="${arg#--workspace-folder=}" + fi +done +INSTALL_RUST_TOOLCHAIN_FUNC="${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/install-rust-toolchain.sh" +if [[ -f "$INSTALL_RUST_TOOLCHAIN_FUNC" ]]; then + source $INSTALL_RUST_TOOLCHAIN_FUNC + install_rust_toolchain "$@" +fi diff --git a/.gitattributes b/.gitattributes index 6313b56..d135af2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,14 @@ +# ################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ################################################################################ + * text=auto eol=lf diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index cc91e27..4d9deb1 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,4 +1,15 @@ -name: Rust Project CI +################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################name: Rust Project CI on: push: diff --git a/.gitignore b/.gitignore index ea8c4bf..2a5f86e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,14 @@ +# ################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ################################################################################ + /target diff --git a/Cargo.toml b/Cargo.toml index 942eae5..9f7e8dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,16 @@ +# ################################################################################ +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https: //www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ################################################################################ + [package] name = "up-transport-iceoryx2-rust" version = "0.1.0" diff --git a/src/lib.rs b/src/lib.rs index b03e38a..c9c2ee6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,16 @@ +// ################################################################################ +// Copyright (c) 2025 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache License Version 2.0 which is available at +// https: //www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: Apache-2.0 +// ################################################################################ + use async_trait::async_trait; use std::sync::Arc; use up_rust::{UCode, UListener, UMessage, UStatus, UTransport, UUri};