Skip to content

Commit

Permalink
add buildscript to CI
Browse files Browse the repository at this point in the history
* add build env script to set the c++ paths
* update READMEs accordingly
* update CI workflows for build env script
* update for clippy compliance
* decrease test iterations for efficient tests
  • Loading branch information
dmacattack committed Dec 19, 2024
1 parent 72cd142 commit 23ae41b
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 31 deletions.
48 changes: 45 additions & 3 deletions .github/workflows/bundled-lint-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ name: Lint and Test - Bundled

env:
VSOMEIP_INSTALL_PATH: vsomeip-install
GENERIC_CPP_STDLIB_PATH: /usr/include/c++/11
ARCH_SPECIFIC_CPP_STDLIB_PATH: /usr/include/x86_64-linux-gnu/c++/11

on:
push:
Expand All @@ -27,6 +25,7 @@ on:
- "**/include/**"
- "**/src/**"
- "**/Cargo.*"
- "build/**"
workflow_call:
workflow_dispatch:

Expand All @@ -36,9 +35,35 @@ concurrency:

jobs:

set-env:
name: Set environment variables
runs-on: ubuntu-latest

outputs:
arch_specific_cpp_stdlib_path: ${{ steps.set_env.outputs.arch_specific_cpp_stdlib_path }}
generic_cpp_stdlib_path: ${{ steps.set_env.outputs.generic_cpp_stdlib_path }}

steps:
- uses: actions/checkout@v4

- name: Add execute permissions for envsetup
run: chmod +x build/envsetup.sh

- name: Set stdlib paths dynamically
id: set_env
run: |
source ./build/envsetup.sh highest
echo "arch_specific_cpp_stdlib_path=$ARCH_SPECIFIC_CPP_STDLIB_PATH" >> $GITHUB_OUTPUT
echo "generic_cpp_stdlib_path=$GENERIC_CPP_STDLIB_PATH" >> $GITHUB_OUTPUT
lint:
name: Lint
runs-on: ubuntu-latest
needs: set-env

env:
ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.arch_specific_cpp_stdlib_path }}
GENERIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.generic_cpp_stdlib_path }}

steps:
- uses: actions/checkout@v4
Expand All @@ -49,10 +74,14 @@ jobs:
- name: Set environment variables
run: |
echo "VSOMEIP_INSTALL_PATH=${{ github.workspace }}/${{ env.VSOMEIP_INSTALL_PATH }}" >> $GITHUB_ENV
env
- name: Print environment variables for debugging
run: |
echo "VSOMEIP_INSTALL_PATH: ${{ env.VSOMEIP_INSTALL_PATH }}"
echo "GENERIC_CPP_STDLIB_PATH: ${{ env.GENERIC_CPP_STDLIB_PATH }}"
echo "ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ env.ARCH_SPECIFIC_CPP_STDLIB_PATH }}"
env
- name: Ensure vsomeip install path exists
run: |
Expand All @@ -77,6 +106,11 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
needs: set-env

env:
ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.arch_specific_cpp_stdlib_path }}
GENERIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.generic_cpp_stdlib_path }}

steps:
- uses: actions/checkout@v4
Expand All @@ -92,6 +126,7 @@ jobs:
- name: Print environment variables for debugging
run: |
echo "VSOMEIP_INSTALL_PATH: ${{ env.VSOMEIP_INSTALL_PATH }}"
env
- name: Ensure vsomeip install path exists
run: |
Expand All @@ -113,7 +148,9 @@ jobs:
- name: Run tests and report code coverage
run: |
# enable nightly features so that we can also include Doctests
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${VSOMEIP_INSTALL_PATH}/lib RUSTC_BOOTSTRAP=1 cargo tarpaulin -o xml -o lcov -o html --doc --tests -- --test-threads 1
# TODO: tarpaulin fails silently. Possible version issue
# LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${VSOMEIP_INSTALL_PATH}/lib RUSTC_BOOTSTRAP=1 cargo tarpaulin -o xml -o lcov -o html --doc --tests -- --test-threads 1
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${VSOMEIP_INSTALL_PATH}/lib cargo test -- --test-threads 1
- name: Upload coverage report (xml)
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -142,6 +179,11 @@ jobs:
build-docs:
name: Build documentation
runs-on: ubuntu-latest
needs: set-env

env:
ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.arch_specific_cpp_stdlib_path }}
GENERIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.generic_cpp_stdlib_path }}

steps:
- uses: actions/checkout@v4
Expand Down
63 changes: 55 additions & 8 deletions .github/workflows/unbundled-lint-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ env:
VSOMEIP_SOURCE_PATH: vsomeip-src
VSOMEIP_INSTALL_PATH: vsomeip-install

GENERIC_CPP_STDLIB_PATH: /usr/include/c++/11
ARCH_SPECIFIC_CPP_STDLIB_PATH: /usr/include/x86_64-linux-gnu/c++/11

on:
push:
branches: [ main ]
Expand All @@ -31,6 +28,7 @@ on:
- "**/include/**"
- "**/src/**"
- "**/Cargo.*"
- "build/**"
workflow_call:
workflow_dispatch:

Expand All @@ -39,10 +37,39 @@ concurrency:
cancel-in-progress: true

jobs:

set-env:
name: Set environment variables
runs-on: ubuntu-latest

outputs:
arch_specific_cpp_stdlib_path: ${{ steps.set_env.outputs.arch_specific_cpp_stdlib_path }}
generic_cpp_stdlib_path: ${{ steps.set_env.outputs.generic_cpp_stdlib_path }}

steps:
- uses: actions/checkout@v4

- name: Add execute permissions for envsetup
run: chmod +x build/envsetup.sh

- name: Set stdlib paths dynamically
id: set_env
run: |
source ./build/envsetup.sh highest
echo "arch_specific_cpp_stdlib_path=$ARCH_SPECIFIC_CPP_STDLIB_PATH" >> $GITHUB_OUTPUT
echo "generic_cpp_stdlib_path=$GENERIC_CPP_STDLIB_PATH" >> $GITHUB_OUTPUT
obtain_and_build_vsomeip:
runs-on: ubuntu-latest
needs: set-env

outputs:
cache_key: ${{ steps.generate_cache_key.outputs.CACHE_KEY }}

env:
ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.arch_specific_cpp_stdlib_path }}
GENERIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.generic_cpp_stdlib_path }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -53,14 +80,18 @@ jobs:
echo "VSOMEIP_SOURCE_PATH=${{ github.workspace }}/${{ env.VSOMEIP_SOURCE_PATH }}" >> $GITHUB_ENV
echo "VSOMEIP_INSTALL_PATH=${{ github.workspace }}/${{ env.VSOMEIP_INSTALL_PATH }}" >> $GITHUB_ENV
echo "VSOMEIP_SOURCE_PATH_WITH_WILDCARD=${{ github.workspace }}/${{ env.VSOMEIP_SOURCE_PATH }}/*" >> $GITHUB_ENV
env
- name: Print environment variables for debugging
run: |
echo "VSOMEIP_SOURCE_TARBALL: ${{ env.VSOMEIP_SOURCE_TARBALL }}"
echo "VSOMEIP_SOURCE_PATH: ${{ env.VSOMEIP_SOURCE_PATH }}"
echo "VSOMEIP_INSTALL_PATH: ${{ env.VSOMEIP_INSTALL_PATH }}"
echo "VSOMEIP_SOURCE_PATH_WITH_WILDCARD: ${{ env.VSOMEIP_SOURCE_PATH_WITH_WILDCARD }}"
echo "GENERIC_CPP_STDLIB_PATH: ${{ env.GENERIC_CPP_STDLIB_PATH }}"
echo "ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ env.ARCH_SPECIFIC_CPP_STDLIB_PATH }}"
env
- name: Download tarball
run: |
wget -O vsomeip-source.tar.gz $VSOMEIP_SOURCE_TARBALL
Expand Down Expand Up @@ -120,9 +151,14 @@ jobs:

lint:
name: Lint
needs: obtain_and_build_vsomeip
needs:
- obtain_and_build_vsomeip
- set-env
runs-on: ubuntu-latest

env:
ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.arch_specific_cpp_stdlib_path }}
GENERIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.generic_cpp_stdlib_path }}
CACHE_KEY: ${{ needs.obtain_and_build_vsomeip.outputs.cache_key }}

steps:
Expand Down Expand Up @@ -170,10 +206,15 @@ jobs:

test:
name: Test
needs: obtain_and_build_vsomeip
needs:
- obtain_and_build_vsomeip
- set-env
runs-on: ubuntu-latest

env:
CACHE_KEY: ${{ needs.obtain_and_build_vsomeip.outputs.cache_key }}
ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.arch_specific_cpp_stdlib_path }}
GENERIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.generic_cpp_stdlib_path }}

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -221,7 +262,9 @@ jobs:
- name: Run tests and report code coverage
run: |
# enable nightly features so that we can also include Doctests
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${VSOMEIP_INSTALL_PATH}/lib RUSTC_BOOTSTRAP=1 cargo tarpaulin --no-default-features -o xml -o lcov -o html --doc --tests -- --test-threads 1
# TODO: tarpaulin fails silently. Possible version issue
# LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${VSOMEIP_INSTALL_PATH}/lib RUSTC_BOOTSTRAP=1 cargo tarpaulin --no-default-features -o xml -o lcov -o html --doc --tests -- --test-threads 1
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${VSOMEIP_INSTALL_PATH}/lib cargo test -- --test-threads 1
- name: Upload coverage report (xml)
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -249,10 +292,14 @@ jobs:

build-docs:
name: Build documentation
needs: obtain_and_build_vsomeip
needs:
- obtain_and_build_vsomeip
- set-env
runs-on: ubuntu-latest
env:
CACHE_KEY: ${{ needs.obtain_and_build_vsomeip.outputs.cache_key }}
ARCH_SPECIFIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.arch_specific_cpp_stdlib_path }}
GENERIC_CPP_STDLIB_PATH: ${{ needs.set-env.outputs.generic_cpp_stdlib_path }}

steps:
- uses: actions/checkout@v4
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ This library implements a uTransport client for vsomeip in Rust following the uP

### Building the Library

To build the library, run:
To build the library, setup the environment

``` bash
source build/env_setup.sh
```

then run:
```bash
VSOMEIP_INSTALL_PATH=<path/to/where/to/install/vsomeip> GENERIC_CPP_STDLIB_PATH=<path/to/generic/cpp/stdlib> ARCH_SPECIFIC_CPP_STDLIB_PATH=<path/to/arch_specific/cpp/stdlib> cargo build
VSOMEIP_INSTALL_PATH=<path/to/where/to/install/vsomeip> cargo build
```

in the project root directory.
Expand All @@ -23,7 +29,7 @@ This library leverages the [up-rust](https://github.com/eclipse-uprotocol/up-rus

To run the tests, run
```bash
VSOMEIP_INSTALL_PATH= <path/to/vsomeip/install> LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path/to/vsomeip/install>/lib GENERIC_CPP_STDLIB_PATH=<path/to/generic/cpp/stdlib> ARCH_SPECIFIC_CPP_STDLIB_PATH=<path/to/arch_specific/cpp/stdlib> cargo test -- --test-threads 1
VSOMEIP_INSTALL_PATH= <path/to/vsomeip/install> LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path/to/vsomeip/install>/lib cargo test -- --test-threads 1
```

Breaking this down:
Expand Down
120 changes: 120 additions & 0 deletions build/envsetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash
#
# to set environment variables for c++ stdlib paths:
# $ source build/envsetup.sh
#
# to automatically select the highest version of the c++ stdlib:
# $ source build/envsetup.sh highest

# console colors
RED='\033[0;31m'
GRN='\033[0;32m'
ORNG='\033[0;33m'
NC='\033[0;0m'
USE_HIGHEST=0
if [ "$1" == "highest" ]; then
USE_HIGHEST=1
fi

# find the highest number in an array
select_highest_number() {
local numbers=("$@")
local highest_number=0

for number in "${numbers[@]}"; do
if [ "$number" -gt "$highest_number" ]; then
highest_number=$number
fi
done

echo "$highest_number"
}

# Select a directory from a list of directories
select_directory() {
local directories=("$@")
local selected_path=""
# Check if the directory array contains numbers or strings
is_number=0
if [[ "${directories[0]}" =~ ^[0-9]+$ ]]; then
is_number=1
fi

# Check the number of directories
if [ "${#directories[@]}" -eq 1 ]; then
# If only one directory is found, set MY_PATH to it
selected_path="${directories[0]}"

elif [ "$USE_HIGHEST" -eq 1 ] && [ "$is_number" -eq 1 ]; then
highest_version=$(select_highest_number "${directories[@]}")
selected_path="$highest_version"

else
# Display directories to the user if more than one exists
printf "Select a directory: \n" 1>&2
for i in "${!directories[@]}"; do
printf "%d) %s\n" "$((i + 1))" "${directories[i]}" 1>&2
done

# Prompt the user to enter a choice
read -p "Enter the number of your choice: " choice

# Validate the user’s input
if [[ "$choice" -ge 1 && "$choice" -le "${#directories[@]}" ]]; then
selected_path="${directories[choice - 1]}"
else
printf "${RED}Invalid selection ${NC}\n" 1>&2
return 1
fi
fi

# Return the selected path
echo "$selected_path"
}

# find c++ include
if [ -d "/usr/include/c++/" ]; then
CPP_DIRS=$( ls /usr/include/c++/ )
CPP_ARRAY=($CPP_DIRS)
STDLIB_DIR=$(select_directory "${CPP_ARRAY[@]}")
if [ -z "$STDLIB_DIR" ]; then
return 1
fi
STDLIB_PATH="/usr/include/c++/${STDLIB_DIR}"
else
# Print warning if the directory doesn't exist
echo -e "${RED}/usr/include/c++/ does not exist.${NC}"
return
fi

# find machine dir
MACHINE_NAME=$(uname -m)
MACHINE_DIRS=$( ls /usr/include/ | grep "${MACHINE_NAME}" )
MACHINE_ARRAY=($MACHINE_DIRS)
ARCH_DIR=$(select_directory "${MACHINE_ARRAY[@]}")
if [ -z "$ARCH_DIR" ]; then
return 1
fi
ARCH_PATH="/usr/include/${ARCH_DIR}"

# find arch c++ include
if [ -d "$ARCH_PATH/c++/" ]; then
CPP_DIRS=$( ls ${ARCH_PATH}/c++/ )
CPP_ARRAY=($CPP_DIRS)
STDLIB_DIR=$(select_directory "${CPP_ARRAY[@]}")
if [ -z "$STDLIB_DIR" ]; then
return 1
fi
ARCH_STDLIB_PATH="${ARCH_PATH}/c++/${STDLIB_DIR}"
else
# Print warning if the directory doesn't exist
echo -e "${RED}$ARCH_PATH/c++/ does not exist.${NC}"
return
fi

# export the variables
export GENERIC_CPP_STDLIB_PATH=$STDLIB_PATH
export ARCH_SPECIFIC_CPP_STDLIB_PATH=$ARCH_STDLIB_PATH

echo -e "${ORNG}Set GENERIC_CPP_STDLIB_PATH=${GRN}$GENERIC_CPP_STDLIB_PATH${NC}"
echo -e "${ORNG}Set ARCH_SPECIFIC_CPP_STDLIB_PATH=${GRN}$ARCH_SPECIFIC_CPP_STDLIB_PATH${NC}"
Loading

0 comments on commit 23ae41b

Please sign in to comment.