diff --git a/.bazelrc b/.bazelrc index 51cac5a3..7ebe3025 100644 --- a/.bazelrc +++ b/.bazelrc @@ -7,3 +7,6 @@ test --test_output=errors common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/ common --registry=https://bcr.bazel.build +common --credential_helper=*.qnx.com=%workspace%/scripts/internal/qnx_creds.py + +build:build_qnx8 --platforms=@score_toolchains_rust//platforms:aarch64-unknown-qnx8_0 diff --git a/.bazelversion b/.bazelversion index 2bf50aaf..e7fdef7e 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -8.3.0 +8.4.2 diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..bc9c72fd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,24 @@ +--- +name: Bug report +about: Create a report for a bug +title: 'Bug: Your bug title' +labels: 'bug' +assignees: '' + +--- + +### Describe the bug: + + +### Steps to reproduce the behavior: +1. +2. + +### Observed behavior: + +### Expected behavior + +### Occurrence: + + +### Attachments / Logs: diff --git a/.github/actions/gitlint/action.yml b/.github/actions/gitlint/action.yml index cb16e6ff..da484568 100644 --- a/.github/actions/gitlint/action.yml +++ b/.github/actions/gitlint/action.yml @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2025 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. diff --git a/.github/actions/setup-rust-build/action.yml b/.github/actions/setup-rust-build/action.yml new file mode 100644 index 00000000..efb910e9 --- /dev/null +++ b/.github/actions/setup-rust-build/action.yml @@ -0,0 +1,40 @@ +name: 'Setup Rust Build Environment' +description: 'Checks out code, installs protoc, and caches cargo dependencies' + +inputs: + repo-token: + description: 'GitHub token for protoc downloads' + required: true + + +runs: + using: "composite" + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Install protoc 26.1 + uses: arduino/setup-protoc@v3 + with: + version: 26.1 + repo-token: ${{ inputs.repo-token }} + + - name: Cache cargo & target + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + ~/.cargo/bin + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - name: Install cargo-tarpaulin if not already installed + run: | + if ! command -v cargo-tarpaulin > /dev/null; then + cargo install cargo-tarpaulin --version 0.32.7 --locked + else + echo "cargo-tarpaulin is already installed" + fi + shell: bash diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..893cba07 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,33 @@ + + + +## Notes for Reviewer + + +## Pre-Review Checklist for the PR Author + +* [ ] PR title is short, expressive and meaningful +* [ ] Commits are properly organized +* [ ] Relevant issues are linked in the [References](#references) section +* [ ] Tests are conducted +* [ ] Unit tests are added + +## Checklist for the PR Reviewer + +* [ ] Commits are properly organized and messages are according to the guideline +* [ ] Unit tests have been written for new behavior +* [ ] Public API is documented +* [ ] PR title describes the changes + +## Post-review Checklist for the PR Author + +* [ ] All open points are addressed and tracked via issues + +## References + + + +Closes # + + + diff --git a/.github/setup-rust-build/action.yml b/.github/setup-rust-build/action.yml new file mode 100644 index 00000000..c5e62f1d --- /dev/null +++ b/.github/setup-rust-build/action.yml @@ -0,0 +1,52 @@ +# ******************************************************************************* +# 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: "Setup Rust Build Environment" +description: "Checks out code, installs protoc, and caches cargo dependencies" + +inputs: + repo-token: + description: "GitHub token for protoc downloads" + required: true + +runs: + using: "composite" + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Install protoc 26.1 + uses: arduino/setup-protoc@v3 + with: + version: 26.1 + repo-token: ${{ inputs.repo-token }} + + - name: Cache cargo & target + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + ~/.cargo/bin + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - name: Install cargo-tarpaulin if not already installed + run: | + if ! command -v cargo-tarpaulin > /dev/null; then + cargo install cargo-tarpaulin --version 0.32.7 --locked + else + echo "cargo-tarpaulin is already installed" + fi + shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..34bc40c7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,71 @@ +# ******************************************************************************* +# 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: Bazel Build + +on: + pull_request: + types: [opened, reopened, synchronize] + merge_group: + types: [checks_requested] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SCORE_QNX_USER: ${{ secrets.SCORE_QNX_USER }} + SCORE_QNX_PASSWORD: ${{ secrets.SCORE_QNX_PASSWORD }} + SCORE_QNX_LICENSE: ${{ secrets.SCORE_QNX_LICENSE }} +jobs: + build: + name: Build Bazel Code + runs-on: ${{ vars.REPO_RUNNER_LABELS && fromJSON(vars.REPO_RUNNER_LABELS) || 'ubuntu-latest' }} + steps: + - name: Checkout code + uses: actions/checkout@v4.2.2 + + - name: Install protoc 26.1 + uses: arduino/setup-protoc@v3 + with: + version: 26.1 + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Bazel + uses: bazel-contrib/setup-bazel@0.15.0 + with: + bazelisk-version: 1.26.0 # newest LTS before 1 Jun 2025 + disk-cache: true + repository-cache: true + bazelisk-cache: true + + - name: Bazel info (discover paths) + id: bazel-info + run: | + echo "BAZEL_OUTPUT_BASE=$(bazel info output_base)" >> $GITHUB_ENV + echo "BAZEL_USER_ROOT=$(bazel info output_user_root)" >> $GITHUB_ENV + echo "BAZEL_REPO_CACHE=$(bazel info repository_cache)" >> $GITHUB_ENV + bazel info + + - name: Cache Bazel output base + uses: actions/cache@v4 + with: + path: | + ${{ env.BAZEL_OUTPUT_BASE }}/action_cache + ${{ env.BAZEL_OUTPUT_BASE }}/bazel-out + ${{ env.BAZEL_OUTPUT_BASE }}/external + ${{ env.BAZEL_OUTPUT_BASE }}/execroot + key: bazel-ob-v2-${{ runner.os }}-${{ hashFiles('.bazelversion', 'MODULE.bazel', 'MODULE.bazel.lock', '**/*.bzl', 'Cargo.lock') }} + restore-keys: | + bazel-ob-v2-${{ runner.os }}- + + - name: Build with Bazel + run: | + bazel build //... diff --git a/.github/workflows/cargo_required.yml b/.github/workflows/cargo_required.yml new file mode 100644 index 00000000..a4921c15 --- /dev/null +++ b/.github/workflows/cargo_required.yml @@ -0,0 +1,94 @@ +# ******************************************************************************* +# 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: cargo build, test, coverage and miri report + +on: + push: + branches: [main, development] + pull_request: + branches: [main, development] + types: [opened, ready_for_review, reopened, synchronize] + +env: + CARGO_TERM_COLOR: always + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + cargo-checks: + #permissions for docs deployment + permissions: + contents: write + pages: write + id-token: write + runs-on: ${{ vars.REPO_RUNNER_LABELS && fromJSON(vars.REPO_RUNNER_LABELS) || 'ubuntu-latest' }} + timeout-minutes: 45 # minutes is the maximum allowed for a cold run + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Rust Build Environment + uses: ./.github/actions/setup-rust-build + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + # ---------- BUILD ---------- + - name: Cargo build + run: cargo build --verbose + + # ---------- TARPAULIN(TEST + COVERAGE) ---------- + - name: Run tests under coverage + run: cargo +nightly tarpaulin --version 0.32.7 --skip-clean --out Html --verbose --no-dead-code --engine llvm --all-features + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: tarpaulin-report.html + + # ---------- MIRI ---------- + - name: Install nightly + miri (minimal profile) + uses: actions-rs/toolchain@v1 + if: github.event.pull_request.draft == false + with: + toolchain: nightly-2025-05-30 + profile: minimal + components: miri + override: true + + - name: Prefetch crates for nightly + if: github.event.pull_request.draft == false + run: cargo +nightly-2025-05-30 fetch --locked + + - name: Purge Miri artifacts + if: github.event.pull_request.draft == false + run: | + rm -rf target/miri + rm -rf ~/.cache/miri + + - name: Prefetch and build dependencies for Miri + if: github.event.pull_request.draft == false + run: cargo +nightly-2025-05-30 miri setup + + - name: Run Miri and save report + if: github.event.pull_request.draft == false + env: + CARGO_INCREMENTAL: "0" # turn off incremental + run: | + set -o pipefail + cargo +nightly-2025-05-30 miri test --workspace \ + -- --skip test_mt_one_pop_one_stealer \ + --skip test_mt_one_push_mpmc_one_stealer \ + --skip test_one_producer_multi_stealer_mt_thread \ + --skip test_one_producer_one_stealer_mt_thread \ + 2>&1 | tee miri_report.txt diff --git a/.github/workflows/copyright.yml b/.github/workflows/copyright.yml index 08ef3767..8483278d 100644 --- a/.github/workflows/copyright.yml +++ b/.github/workflows/copyright.yml @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2025 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -17,6 +17,9 @@ on: types: [opened, reopened, synchronize] merge_group: types: [checks_requested] +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + jobs: copyright-check: uses: eclipse-score/cicd-workflows/.github/workflows/copyright.yml@main diff --git a/.github/workflows/docs-cleanup.yml b/.github/workflows/docs-cleanup.yml index cfa4ae24..56626f0f 100644 --- a/.github/workflows/docs-cleanup.yml +++ b/.github/workflows/docs-cleanup.yml @@ -20,7 +20,7 @@ permissions: on: schedule: - - cron: '0 0 * * *' # Runs every day at midnight UTC + - cron: "0 0 * * *" # Runs every day at midnight UTC jobs: docs-cleanup: diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 620d6972..adb88769 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2025 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -18,7 +18,8 @@ on: types: [opened, reopened, synchronize] merge_group: types: [checks_requested] - +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: formatting-check: uses: eclipse-score/cicd-workflows/.github/workflows/format.yml@main diff --git a/.github/workflows/gitlint.yml b/.github/workflows/gitlint.yml index 90487edc..61b8fe0c 100644 --- a/.github/workflows/gitlint.yml +++ b/.github/workflows/gitlint.yml @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2025 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -15,10 +15,12 @@ name: Gitlint check on: pull_request: types: [opened, synchronize, reopened] +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: lint-commits: name: check-commit-messages - runs-on: ubuntu-latest + runs-on: ${{ vars.REPO_RUNNER_LABELS && fromJSON(vars.REPO_RUNNER_LABELS) || 'ubuntu-latest' }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -29,3 +31,4 @@ jobs: uses: ./.github/actions/gitlint with: pr-number: ${{ github.event.number }} + base-branch: ${{ github.event.pull_request.base.ref }} diff --git a/.github/workflows/license_check.yml b/.github/workflows/license_check.yml index aba7f99d..49319672 100644 --- a/.github/workflows/license_check.yml +++ b/.github/workflows/license_check.yml @@ -17,14 +17,15 @@ on: types: [opened, reopened, synchronize] merge_group: types: [checks_requested] - +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} permissions: pull-requests: write issues: write - jobs: license-check: + if: ${{ github.repository == 'eclipse-score/baselibs_rust' }} uses: eclipse-score/cicd-workflows/.github/workflows/license-check.yml@main with: repo-url: "${{ github.server_url }}/${{ github.repository }}" diff --git a/.github/workflows/lint_fmt_clippy.yml b/.github/workflows/lint_fmt_clippy.yml new file mode 100644 index 00000000..a7e02f0f --- /dev/null +++ b/.github/workflows/lint_fmt_clippy.yml @@ -0,0 +1,67 @@ +# ******************************************************************************* +# 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: rustfmt and clippy check + +on: + pull_request: + branches: [main, development] + types: [opened, ready_for_review, reopened, synchronize] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +jobs: + lint-fmt-clippy: + timeout-minutes: 6 # 6 minutes is the maximum allowed for a cold run + runs-on: ${{ vars.REPO_RUNNER_LABELS && fromJSON(vars.REPO_RUNNER_LABELS) || 'ubuntu-latest' }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install protoc 26.1 + uses: arduino/setup-protoc@v3 + with: + version: 26.1 + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Cache Cargo registry, git deps & target + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-lint-fmt-clippy-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-lint-fmt-clippy- + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.90.0 + override: true + components: rustfmt, clippy + + - name: check code format (rustfmt) + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + - name: check clippy errors + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-features --all-targets --workspace -- -D warnings diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..6c5a1df7 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 +# ******************************************************************************* + +name: Bazel Tests + +on: + pull_request: + types: [opened, reopened, synchronize] + merge_group: + types: [checks_requested] +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + setup-and-run-tests: + runs-on: ${{ vars.REPO_RUNNER_LABELS && fromJSON(vars.REPO_RUNNER_LABELS) || 'ubuntu-latest' }} + steps: + - name: Checkout repository + uses: actions/checkout@v4.2.2 + + - name: Install protoc 26.1 + uses: arduino/setup-protoc@v3 + with: + version: 26.1 + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Bazel with shared caching + uses: bazel-contrib/setup-bazel@0.15.0 + with: + bazelisk-version: 1.26.0 + disk-cache: true + repository-cache: true + bazelisk-cache: true + + - name: Run Tests via Bazel + run: | + echo "Running: bazel test //src/..." + bazel test //src/... diff --git a/.gitignore b/.gitignore index e7dc3299..0a1cc729 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,21 @@ styles/ .venv __pycache__/ /.coverage + +# Rust +debug/ +target/ +/build/ + +*~ +.*swp +.*swo + +# pytest reports +tests/**/*.html +tests/**/*.xml + +# VS Code files +.vscode* +*.orig +.venv_docs diff --git a/.vscode/settings.json b/.vscode/settings.json index 47cb9540..0b59e9ef 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,12 +5,10 @@ "files.trimTrailingWhitespace": true, "editor.insertSpaces": true, "editor.tabCompletion": "on", - // Default for any filetype "editor.rulers": [ 99 ], - // Exclude build, temp and cache folders "files.watcherExclude": { ".*/**": true, @@ -19,7 +17,6 @@ ".venv*/**": true, "_build/**": true, }, - // Python Settings // Exclude build, temp and cache folders "python.analysis.exclude": [ @@ -31,33 +28,30 @@ "_build", ], "[python]": { - // In python using 80 characters per line is the standard. "editor.rulers": [ - 79 + 120 ], - // Opinionated option for the future: - // "editor.formatOnSave": true, + "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.sortImports": "explicit" + "source.organizeImports": "explicit", + "source.sortImports": "explicit", }, "editor.defaultFormatter": "charliermarsh.ruff", }, - // Markdown Settings "[markdown]": { // We mostly write markdown in some combination with python, // so we use the same rulers as python. "editor.rulers": [ - 79, 99 + 79, + 99 ] }, - "bazel.lsp.command": "bazel", "bazel.lsp.args": [ "run", "//:starpls_server" ], - // RST Settings "[restructuredtext]": { "editor.tabSize": 3, @@ -99,8 +93,15 @@ "--ignore-glob=bazel-*/*", "--ignore-glob=.venv_docs/*", "--ignore-glob=_build/*", - ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, + "editor.formatOnSave": true, + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer", + "editor.formatOnSave": true, + }, + "rust-analyzer.cargo.cfgs": [ + "!miri" + ], } diff --git a/BUILD b/BUILD index 473b5d5c..e56bbccd 100644 --- a/BUILD +++ b/BUILD @@ -10,7 +10,6 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* - load("@score_docs_as_code//:docs.bzl", "docs") load("@score_tooling//:defs.bzl", "copyright_checker", "dash_license_checker", "setup_starpls", "use_format_targets") load("//:project_config.bzl", "PROJECT_CONFIG") @@ -23,6 +22,8 @@ setup_starpls( copyright_checker( name = "copyright", srcs = [ + "docs", + "examples", "src", "tests", "//:BUILD", @@ -33,8 +34,32 @@ copyright_checker( visibility = ["//visibility:public"], ) +# Needed for Dash tool to check python dependency licenses. +# This is a workaround to filter out local packages from the Cargo.lock file. +# The tool is intended for third-party content. +genrule( + name = "filtered_cargo_lock", + srcs = ["Cargo.lock"], + outs = ["Cargo.lock.filtered"], + cmd = """ + awk ' + BEGIN { skip = 0; data = "" } + /^\\[\\[package\\]\\]/ { + if (data != "" && !skip) print data; + skip = 1; + data = $$0; + next; + } + data != "" { data = data "\\n" $$0 } + # any package that has a "source = " line will not be skipped. + /^source = / { skip = 0 } + END { if (data != "" && !skip) print data } + ' $(location Cargo.lock) > $@ + """, +) + dash_license_checker( - src = "//examples:cargo_lock", + src = ":filtered_cargo_lock", file_type = "", # let it auto-detect based on project_config project_config = PROJECT_CONFIG, visibility = ["//visibility:public"], @@ -43,6 +68,16 @@ dash_license_checker( # Add target for formatting checks use_format_targets() +exports_files([ + "MODULE.bazel", +]) + +# Creates all documentation targets: +# - `:docs` for building documentation at build-time docs( + data = [ + # "@score_platform//:needs_json", + # "@score_process//:needs_json", + ], source_dir = "docs", ) diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..b9a7033c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "log" +version = "0.0.1" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..eaf4500b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[workspace] +resolver = "2" +# Split to default members without tests and examples. +# Used when executing cargo from project root. +default-members = ["src/log"] +# Include tests and examples as a member for IDE support and Bazel builds. +members = ["src/log"] + + +[workspace.package] +version = "0.0.1" +edition = "2021" +license-file = "LICENSE.md" +authors = ["S-CORE Contributors"] + + +[workspace.dependencies] + + +[workspace.lints.clippy] +std_instead_of_core = "warn" +alloc_instead_of_core = "warn" + + +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] } diff --git a/LICENSE b/LICENSE index f433b1a5..261eeb9e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -175,3 +174,28 @@ of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..8c69a8bc --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,13 @@ +Copyright 2025 Contributors to the Eclipse Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/MODULE.bazel b/MODULE.bazel index 1ec606dd..9ba2f0c1 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -11,47 +11,113 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* module( - name = "cpp_rust_template_repository", - version = "1.0", + name = "score_baselibs_rust", + version = "0.0.1", + compatibility_level = 0, ) +# Bazel global rules bazel_dep(name = "rules_python", version = "1.4.1") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_rust", version = "0.61.0") +bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "aspect_rules_lint", version = "1.0.3") +bazel_dep(name = "buildifier_prebuilt", version = "7.3.1") +bazel_dep(name = "platforms", version = "1.0.0") -PYTHON_VERSION = "3.12" +# S-CORE process rules +bazel_dep(name = "score_bazel_platforms", version = "0.0.2") +bazel_dep(name = "score_docs_as_code", version = "1.4.0") +bazel_dep(name = "score_tooling", version = "1.0.2") -python = use_extension("@rules_python//python/extensions:python.bzl", "python") -python.toolchain( - is_default = True, - python_version = PYTHON_VERSION, +bazel_dep(name = "score_process", version = "1.2.1", dev_dependency = True) +bazel_dep(name = "score_platform", version = "0.3.0", dev_dependency = True) # This is main score repo +bazel_dep(name = "score_virtualization", version = "0.0.1", dev_dependency = True) + +# Toolchains and extensions +bazel_dep(name = "score_toolchains_gcc", version = "0.4", dev_dependency = True) +bazel_dep(name = "score_toolchains_qnx", version = "0.0.2", dev_dependency = True) +bazel_dep(name = "rust_qnx8_toolchain", version = "1.2.0", dev_dependency = True) +bazel_dep(name = "score_toolchains_rust", version = "0.1.1", dev_dependency = True) + +# S-CORE crates +bazel_dep(name = "score_crates") + +# Overrides +git_override( + module_name = "score_tooling", + commit = "654664dae7df2700fd5840c5ed6c07ac6c61705d", #until 1.0.4 is released + remote = "https://github.com/eclipse-score/tooling.git", +) + +git_override( + module_name = "score_toolchains_rust", + commit = "6651945b4ba8e7c342d9740e9cb2d37842f56261", + remote = "https://github.com/eclipse-score/toolchains_rust.git", ) -use_repo(python) -# Add GoogleTest dependency -bazel_dep(name = "googletest", version = "1.17.0") +git_override( + module_name = "score_virtualization", + commit = "99d3f153c43796b67a63e82aad1ede6a881aa6af", + remote = "https://github.com/qorix-group/score_virtualization.git", +) -# Rust rules for Bazel -bazel_dep(name = "rules_rust", version = "0.63.0") +git_override( + module_name = "score_crates", + # TODO: 'commit' and 'remote' must be updated once required changes are merged. + # https://github.com/eclipse-score/score-crates/pull/16 + commit = "f0bf4bdf98d8a8ad548256ab24dc08f9ba8f04aa", + remote = "https://github.com/qorix-group/score-crates.git", +) -# C/C++ rules for Bazel -bazel_dep(name = "rules_cc", version = "0.2.1") +archive_override( + module_name = "rust_qnx8_toolchain", + strip_prefix = "qnx8", + urls = [ + "https://github.com/qorix-group/rust-lang-qnx8/releases/download/1.2.0/qnx8_rust_toolchain.tar.gz", + ], +) -# LLVM Toolchains Rules - host configuration -bazel_dep(name = "toolchains_llvm", version = "1.4.0") +# Extensions -llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") -llvm.toolchain( - cxx_standard = {"": "c++17"}, - llvm_version = "19.1.0", +gcc = use_extension("@score_toolchains_gcc//extentions:gcc.bzl", "gcc", dev_dependency = True) +gcc.toolchain( + sha256 = "457f5f20f57528033cb840d708b507050d711ae93e009388847e113b11bf3600", + strip_prefix = "x86_64-unknown-linux-gnu", + url = "https://github.com/eclipse-score/toolchains_gcc_packages/releases/download/0.0.1/x86_64-unknown-linux-gnu_gcc12.tar.gz", ) -use_repo(llvm, "llvm_toolchain") -use_repo(llvm, "llvm_toolchain_llvm") +use_repo(gcc, "gcc_toolchain", "gcc_toolchain_gcc") -register_toolchains("@llvm_toolchain//:all") +toolchains_qnx = use_extension("@score_toolchains_qnx//:extensions.bzl", "toolchains_qnx", dev_dependency = True) +toolchains_qnx.sdp( + sha256 = "f2e0cb21c6baddbcb65f6a70610ce498e7685de8ea2e0f1648f01b327f6bac63", + strip_prefix = "installation", + url = "https://www.qnx.com/download/download/79858/installation.tgz", +) + +PYTHON_VERSION = "3.12" + +python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) +python.toolchain( + is_default = True, + python_version = PYTHON_VERSION, +) +use_repo(python) -# tooling -bazel_dep(name = "score_tooling", version = "1.0.1") -bazel_dep(name = "aspect_rules_lint", version = "1.5.3") -bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2") +use_repo(toolchains_qnx, "toolchains_qnx_sdp") +use_repo(toolchains_qnx, "toolchains_qnx_qcc") +use_repo(toolchains_qnx, "toolchains_qnx_ifs") -#docs-as-code -bazel_dep(name = "score_docs_as_code", version = "1.1.0") +# Registers the custom Rust toolchain wired to @qnx_rust +register_toolchains( + "@toolchains_qnx_qcc//:qcc_aarch64", + "@score_toolchains_rust//toolchains/aarch64-unknown-qnx8_0:toolchain_aarch64_qnx8_0", + "@score_toolchains_rust//toolchains/x86_64-unknown-linux-gnu:toolchain_x86_64_linux", + dev_dependency = True, +) + +register_toolchains( + "@toolchains_qnx_ifs//:ifs_x86_64", + "@toolchains_qnx_ifs//:ifs_aarch64", + dev_dependency = True, +) diff --git a/README.md b/README.md index 1e8af750..324ab079 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,26 @@ +# Base Libraries - Rust -# C++ & Rust Bazel Template Repository - -This repository serves as a **template** for setting up **C++ and Rust projects** using **Bazel**. -It provides a **standardized project structure**, ensuring best practices for: - -- **Build configuration** with Bazel. -- **Testing** (unit and integration tests). -- **Documentation** setup. -- **CI/CD workflows**. -- **Development environment** configuration. +Foundational Rust libraries providing common functionality for S-CORE modules. --- ## 📂 Project Structure -| File/Folder | Description | -| ----------------------------------- | ------------------------------------------------- | -| `README.md` | Short description & build instructions | -| `src/` | Source files for the module | -| `tests/` | Unit tests (UT) and integration tests (IT) | -| `examples/` | Example files used for guidance | -| `docs/` | Documentation (Doxygen for C++ / mdBook for Rust) | -| `.github/workflows/` | CI/CD pipelines | -| `.vscode/` | Recommended VS Code settings | -| `.bazelrc`, `MODULE.bazel`, `BUILD` | Bazel configuration & settings | -| `project_config.bzl` | Project-specific metadata for Bazel macros | -| `LICENSE.md` | Licensing information | -| `CONTRIBUTION.md` | Contribution guidelines | +| File/Folder | Description | +| ---------------------------------------------------- | ------------------------------------------ | +| `README.md` | Short description and build instructions | +| `src/` | Source files | +| `tests/` | Unit tests (UT) and integration tests (IT) | +| `examples/` | Usage examples | +| `docs/` | Documentation using `docs-as-code` | +| `.github/workflows/` | CI/CD pipelines | +| `.vscode` | Recommended VS Code settings | +| `.bazelrc`, `.bazelversion`, `MODULE.bazel`, `BUILD` | Bazel configuration and settings | +| `Cargo.toml`, `rust-toolchain.toml`, `rustfmt.toml` | Cargo configuration and settings | +| `project_config.bzl` | Project-specific metadata for Bazel macros | +| `LICENSE`, `LICENSE.md` | Licensing information | +| `CONTRIBUTION.md` | Contribution guidelines | +| `NOTICE` | Notices for Eclipse Safe Open Vehicle Core | --- @@ -35,8 +29,8 @@ It provides a **standardized project structure**, ensuring best practices for: ### 1️⃣ Clone the Repository ```sh -git clone https://github.com/eclipse-score/YOUR_PROJECT.git -cd YOUR_PROJECT +git clone https://github.com/eclipse-score/baselibs_rust.git +cd baselibs_rust ``` ### 2️⃣ Build the Examples of module @@ -74,9 +68,8 @@ bazel test //tests/... ## 🛠 Tools & Linters -The template integrates **tools and linters** from **centralized repositories** to ensure consistency across projects. +**Tools and linters** from **centralized repositories** are integrated to ensure consistency across projects. -- **C++:** `clang-tidy`, `cppcheck`, `Google Test` - **Rust:** `clippy`, `rustfmt`, `Rust Unit Tests` - **CI/CD:** GitHub Actions for automated builds and tests @@ -85,30 +78,3 @@ The template integrates **tools and linters** from **centralized repositories** ## 📖 Documentation - A **centralized docs structure** is planned. - ---- - -## ⚙️ `project_config.bzl` - -This file defines project-specific metadata used by Bazel macros, such as `dash_license_checker`. - -### 📌 Purpose - -It provides structured configuration that helps determine behavior such as: - -- Source language type (used to determine license check file format) -- Safety level or other compliance info (e.g. ASIL level) - -### 📄 Example Content - -```python -PROJECT_CONFIG = { - "asil_level": "QM", # or "ASIL-A", "ASIL-B", etc. - "source_code": ["cpp", "rust"] # Languages used in the module -} -``` - -### 🔧 Use Case - -When used with macros like `dash_license_checker`, it allows dynamic selection of file types - (e.g., `cargo`, `requirements`) based on the languages declared in `source_code`. diff --git a/docs/conf.py b/docs/conf.py index cf13475a..9f48d883 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2024 Contributors to the Eclipse Foundation +# Copyright (c) 2025 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -20,11 +20,11 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -project = "Module Template Project" -project_url = "https://eclipse-score.github.io/module_template/" -project_prefix = "MODULE_TEMPLATE_" +project = "Base Libraries - Rust" +project_url = "https://github.com/eclipse-score/baselibs_rust" +project_prefix = "BASELIBS_RUST_" author = "S-CORE" -version = "0.1" +version = "0.0.1" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration @@ -33,6 +33,7 @@ extensions = [ "sphinx_design", "sphinx_needs", + "myst_parser", "sphinxcontrib.plantuml", "score_plantuml", "score_metamodel", @@ -41,6 +42,8 @@ "score_layout", ] +myst_enable_extensions = ["colon_fence"] + exclude_patterns = [ # The following entries are not required when building the documentation via 'bazel # build //docs:docs', as that command runs in a sandboxed environment. However, when @@ -50,6 +53,12 @@ ".venv_docs", ] +# Enable markdown rendering +source_suffix = { + ".rst": "restructuredtext", + ".md": "markdown", +} + templates_path = ["templates"] # Enable numref diff --git a/docs/index.rst b/docs/index.rst index f8e53dad..54a223a0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,6 @@ .. # ******************************************************************************* - # Copyright (c) 2024 Contributors to the Eclipse Foundation + # Copyright (c) 2025 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -12,10 +12,10 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -Module Template Documentation +Base Libraries - Rust ============================= -This documentation describes the structure, usage and configuration of the Bazel-based C++/Rust module template. +This documentation describes the Rust base libraries. .. contents:: Table of Contents :depth: 2 @@ -24,36 +24,36 @@ This documentation describes the structure, usage and configuration of the Bazel Overview -------- -This repository provides a standardized setup for projects using **C++** or **Rust** and **Bazel** as a build system. -It integrates best practices for build, test, CI/CD and documentation. +Foundational Rust libraries providing common functionality for S-CORE modules. Requirements ------------ -.. stkh_req:: Example Functional Requirement - :id: stkh_req__docgen_enabled__example - :status: valid - :safety: QM - :security: YES - :reqtype: Functional - :rationale: Ensure documentation builds are possible for all modules - +- TODO: add requirements once available. Project Layout -------------- -The module template includes the following top-level structure: +Project is structured in following manner: -- `src/`: Main C++/Rust sources -- `tests/`: Unit and integration tests +- `README.md`: Short description and build instructions +- `src/`: Source files +- `tests/`: Unit tests (UT) and integration tests (IT) - `examples/`: Usage examples - `docs/`: Documentation using `docs-as-code` - `.github/workflows/`: CI/CD pipelines +- `.vscode`: Recommended VS Code settings +- `.bazelrc`, `.bazelversion`, `MODULE.bazel`, `BUILD`: Bazel configuration and settings +- `Cargo.toml`, `rust-toolchain.toml`, `rustfmt.toml`: Cargo configuration and settings +- `project_config.bzl`: Project-specific metadata for Bazel macros +- `LICENSE`, `LICENSE.md`: Licensing information +- `CONTRIBUTION.md`: Contribution guidelines +- `NOTICE`: Notices for Eclipse Safe Open Vehicle Core Quick Start ----------- -To build the module: +To build the module for host platform: .. code-block:: bash @@ -64,19 +64,3 @@ To run tests: .. code-block:: bash bazel test //tests/... - -Configuration -------------- - -The `project_config.bzl` file defines metadata used by Bazel macros. - -Example: - -.. code-block:: python - - PROJECT_CONFIG = { - "asil_level": "QM", - "source_code": ["cpp", "rust"] - } - -This enables conditional behavior (e.g., choosing `clang-tidy` for C++ or `clippy` for Rust). diff --git a/examples/BUILD b/examples/BUILD index 012dd541..d1031a1d 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -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 +# ******************************************************************************* + # Needed for Dash tool to check python dependency licenses. filegroup( name = "cargo_lock", diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 5819ca5a..00000000 --- a/pyproject.toml +++ /dev/null @@ -1,9 +0,0 @@ -[tool.basedpyright] -extends = "bazel-bin/ide_support.runfiles/score_tooling+/python_basics/pyproject.toml" -verboseOutput = true - -exclude = [ - "**/__pycache__", - "**/.*", - "**/bazel-*", -] diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..ff100edc --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.90.0" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..d1f04540 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,6 @@ +# rust formatter rules. +# check configuration fields here: https://rust-lang.github.io/rustfmt/?version=v1.6.0&search= + + +tab_spaces = 4 +max_width = 150 diff --git a/tests/rust/BUILD b/src/log/BUILD similarity index 72% rename from tests/rust/BUILD rename to src/log/BUILD index 828a0015..aa991bd5 100644 --- a/tests/rust/BUILD +++ b/src/log/BUILD @@ -10,9 +10,15 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_rust//rust:defs.bzl", "rust_test") +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") + +rust_library( + name = "log", + srcs = glob(["src/**/*.rs"]), + visibility = ["//visibility:public"], +) rust_test( - name = "rust_hello_test", - srcs = ["test_main.rs"], + name = "log_tests", + crate = ":log", ) diff --git a/src/log/Cargo.toml b/src/log/Cargo.toml new file mode 100644 index 00000000..b5403bb7 --- /dev/null +++ b/src/log/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "log" +version.workspace = true +edition.workspace = true +license-file.workspace = true +authors.workspace = true + +[dependencies] + +[lints] +workspace = true diff --git a/src/log/src/lib.rs b/src/log/src/lib.rs new file mode 100644 index 00000000..7d785351 --- /dev/null +++ b/src/log/src/lib.rs @@ -0,0 +1,17 @@ +// NOTE: this library is a placeholder until actual library is merged. +// Cargo workspace requires any member to be present, otherwise CI/CD won't be able to pass. + +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/tests/.git-keep b/tests/.git-keep new file mode 100644 index 00000000..e69de29b diff --git a/tests/cpp/BUILD b/tests/cpp/BUILD deleted file mode 100644 index e3b354ed..00000000 --- a/tests/cpp/BUILD +++ /dev/null @@ -1,19 +0,0 @@ -# ******************************************************************************* -# 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 -# ******************************************************************************* -cc_test( - name = "cpp_test_main", - srcs = ["test_main.cpp"], - deps = [ - "@googletest//:gtest_main", # GoogleTest dependency via Bazel Modules - ], -) diff --git a/tests/cpp/test_main.cpp b/tests/cpp/test_main.cpp deleted file mode 100644 index f5231079..00000000 --- a/tests/cpp/test_main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************** -* 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 -********************************************************************************/ -#include - -// Function to be tested -int add(int a, int b) { - return a + b; -} - -// Test case -TEST(AdditionTest, HandlesPositiveNumbers) { - EXPECT_EQ(add(2, 3), 5); - EXPECT_EQ(add(10, 20), 30); -} - -TEST(AdditionTest, HandlesNegativeNumbers) { - EXPECT_EQ(add(-2, -3), -5); - EXPECT_EQ(add(-10, 5), -5); -} - -TEST(AdditionTest, HandlesZero) { - EXPECT_EQ(add(0, 0), 0); - EXPECT_EQ(add(0, 5), 5); - EXPECT_EQ(add(5, 0), 5); -} - -// Main function for running tests -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/tests/rust/test_main.rs b/tests/rust/test_main.rs deleted file mode 100644 index 9390d5e3..00000000 --- a/tests/rust/test_main.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[test] -fn test_hello() { - assert_eq!(2 + 2, 4); -}