diff --git a/.aspect/cli/config.yml b/.aspect/cli/config.yml new file mode 100644 index 00000000..f1bf7adb --- /dev/null +++ b/.aspect/cli/config.yml @@ -0,0 +1,4 @@ +lint: + aspects: + - //tools/bazel:lint.bzl%ruff + - //tools/bazel:lint.bzl%clang_tidy diff --git a/.bazeliskrc b/.bazeliskrc new file mode 100644 index 00000000..897c6dfd --- /dev/null +++ b/.bazeliskrc @@ -0,0 +1,2 @@ +BAZELISK_BASE_URL=https://static.aspect.build/aspect +USE_BAZEL_VERSION=aspect/2025.06.52 diff --git a/.clang-tidy b/.clang-tidy index 1d664e14..ec5061b6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,33 +1,53 @@ -Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type' +# .clang-tidy + +# Enable broad sets, disable one modernize check explicitly. +Checks: > + clang-diagnostic-*, + clang-analyzer-*, + cppcoreguidelines-*, + modernize-*, + -modernize-use-trailing-return-type + +# Lint everything. Set a regex (e.g. ^src/|^include/) to scope. HeaderFilterRegex: '' -AnalyzeTemporaryDtors: false -FormatStyle: google + +# Use clang-format's "google" style when auto-fixing. +FormatStyle: google + +# Per-check options, grouped for readability. CheckOptions: - - key: cert-dcl16-c.NewSuffixes - value: 'L;LL;LU;LLU' - - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField - value: '0' - - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors - value: '1' - - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - value: '1' - - key: google-readability-braces-around-statements.ShortStatementLines - value: '1' - - key: google-readability-function-size.StatementThreshold - value: '800' - - key: google-readability-namespace-comments.ShortNamespaceLines - value: '10' - - key: google-readability-namespace-comments.SpacesBeforeComments - value: '2' - - key: modernize-loop-convert.MaxCopySize - value: '16' - - key: modernize-loop-convert.MinConfidence - value: reasonable - - key: modernize-loop-convert.NamingStyle - value: CamelCase - - key: modernize-pass-by-value.IncludeStyle - value: llvm - - key: modernize-replace-auto-ptr.IncludeStyle - value: llvm - - key: modernize-use-nullptr.NullMacros - value: 'NULL' + # --- CERT --- + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: '0' + + # --- CppCoreGuidelines --- + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: '1' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + + # --- Google Readability --- + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + + # --- Modernize --- + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: 'reasonable' + - key: modernize-loop-convert.NamingStyle + value: 'CamelCase' + - key: modernize-pass-by-value.IncludeStyle + value: 'llvm' + - key: modernize-replace-auto-ptr.IncludeStyle + value: 'llvm' + - key: modernize-use-nullptr.NullMacros + value: 'NULL' diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 5daec749..00000000 --- a/.flake8 +++ /dev/null @@ -1,24 +0,0 @@ -[flake8] - -### Rules ### -# F401 - module imported but unused -# F403 - ‘from module import *’ used; unable to detect undefined names -exclude = - __init__.py::F401,F403 - -# E124 - closing bracket does not match visual indentation -ignore = - E124 - - -### File patterns ### -exclude = - .git, - __pycache__ - -filename = - *.py - -### Options ### -max-line-length = 150 -max-doc-length = 150 \ No newline at end of file diff --git a/.github/Dockerfile b/.github/Dockerfile new file mode 100644 index 00000000..9dc0cbed --- /dev/null +++ b/.github/Dockerfile @@ -0,0 +1,21 @@ +FROM debian:latest + +ARG USER=ci +ARG BAZELISK_TAG=v1.19.0 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates curl git \ + build-essential gcc g++ \ + clang lld ninja-build sudo \ + python3 \ + && rm -rf /var/lib/apt/lists/* + +RUN curl -fsSL -o /usr/local/bin/bazelisk \ + "https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64" \ + && chmod 0755 /usr/local/bin/bazelisk \ + && ln -s /usr/local/bin/bazelisk /usr/local/bin/bazel + +RUN useradd -m ${USER} \ + && echo "${USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +WORKDIR /home/${USER}/workspace diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..ca79ca5b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/images/logo.png b/.github/images/logo.png similarity index 100% rename from images/logo.png rename to .github/images/logo.png diff --git a/.github/images/logo_dark.png b/.github/images/logo_dark.png new file mode 100644 index 00000000..deecfc02 Binary files /dev/null and b/.github/images/logo_dark.png differ diff --git a/images/screenshot.png b/.github/images/screenshot.png similarity index 100% rename from images/screenshot.png rename to .github/images/screenshot.png diff --git a/.github/workflows/distro-ci.yml b/.github/workflows/distro-ci.yml deleted file mode 100644 index d7860526..00000000 --- a/.github/workflows/distro-ci.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: HyperCPU CI/CD Pipeline (build HyperCPU on different platforms) - -on: - pull_request: - branches: - - master - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-latest - container: - image: hyperwin/hcpu-ci:${{ matrix.config.tag }} - # see https://github.com/bazelbuild/bazel/issues/13823 - options: --init - name: "Build on ${{matrix.config.name}}" - strategy: - matrix: - config: - - tag: fedora - name: Fedora - - tag: debian-stable - name: Debian Stable - - tag: debian-unstable - name: Debian Unstable - - tag: archlinux - name: Arch Linux - - tag: gentoo-glibc - name: Gentoo GLibc -# - tag: gentoo-musl -# name: Gentoo Musl -# - tag: alpine -# name: Alpine - - tag: ubuntu - name: Ubuntu - - steps: - - run: | - set -e - DISTRO=$( cat /etc/*-release | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|fedora|gentoo|alpine)' | uniq ) - if [ "$DISTRO" == "gentoo" ]; then - source /etc/profile - fi - git clone https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git && cd HyperCPU - git checkout ${{ github.event.pull_request.head.sha }} - git submodule update --init --recursive - - conan profile detect && conan install . --build=cmake --build=missing - bazelisk build //src/... //tests/... --config=linux-opt diff --git a/.github/workflows/docker-autobuild.yml b/.github/workflows/docker-autobuild.yml deleted file mode 100644 index db5b838e..00000000 --- a/.github/workflows/docker-autobuild.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: HyperCPU CI/CD Pipeline (update Docker images) - -on: - schedule: - - cron: "0 0 */7 * *" - push: - paths: - - 'docker/**' - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-latest - name: "Update ${{ matrix.config.name }} Docker image" - strategy: - matrix: - config: - - tag: fedora - name: Fedora - - tag: debian-stable - name: Debian Stable - - tag: debian-unstable - name: Debian Unstable - - tag: archlinux - name: Arch Linux - - tag: gentoo-glibc - name: Gentoo GLibc - - tag: alpine - name: Alpine - - tag: ubuntu - name: Ubuntu - - steps: - - name: Install Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: hyperwin - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 2 - submodules: true - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: "{{ defaultContext }}:docker/${{ matrix.config.tag }}" - push: true - tags: hyperwin/hcpu-ci:${{ matrix.config.tag }} - - build-gentoo-musl-stage1: - runs-on: ubuntu-latest - name: "Update Gentoo Musl Docker image - stage 1" - steps: - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: hyperwin - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 2 - submodules: true - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: "{{ defaultContext }}:docker/gentoo-musl/stage1" - push: true - tags: hyperwin/hcpu-ci:gentoo-musl-build - - build-gentoo-musl-stage2: - runs-on: ubuntu-latest - name: "Update Gentoo Musl Docker image - stage 2" - needs: build-gentoo-musl-stage1 - steps: - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: hyperwin - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 2 - submodules: true - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: "{{ defaultContext }}:docker/gentoo-musl/stage2" - push: true - tags: hyperwin/hcpu-ci:gentoo-musl - diff --git a/.github/workflows/mainline-compile.yml b/.github/workflows/mainline-compile.yml new file mode 100644 index 00000000..0986cd2f --- /dev/null +++ b/.github/workflows/mainline-compile.yml @@ -0,0 +1,52 @@ +name: HyperCPU CI/CD Pipeline (compile project) + +on: + workflow_call: + +jobs: + testing: + name: Compile (${{ matrix.compiler }}) + runs-on: ubuntu-latest + container: + image: ghcr.io/hypercpu-project/hypercpu-builder:latest + options: --init + permissions: + contents: read + packages: read + + strategy: + fail-fast: false + matrix: + compiler: [gcc, clang] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + + - name: Cache Bazel + uses: actions/cache@v4 + with: + path: | + ~/.cache/bazel + key: bazel-${{ runner.os }}-${{ matrix.compiler }}-${{ hashFiles('**/*.bazel', '**/*.bzl') }} + restore-keys: | + bazel-${{ runner.os }}-${{ matrix.compiler }}- + bazel-${{ runner.os }}- + + - name: Fix permissions + run: chown -R ci:ci "$GITHUB_WORKSPACE" + + - name: Bazel build (linux-opt mode, with ${{ matrix.compiler }} compiler) + run: sudo -u ci bazelisk build //... --config=linux-opt --compiler=${{ matrix.compiler }} + + - name: Upload package tarball + uses: actions/upload-artifact@v4 + with: + name: hcpu-tarballs-${{ matrix.compiler }} + path: | + bazel-bin/tools/packaging/*.tar.gz + !bazel-bin/tools/packaging/hcpu.tar.gz + if-no-files-found: error diff --git a/.github/workflows/mainline-format.yml b/.github/workflows/mainline-format.yml new file mode 100644 index 00000000..4183bb57 --- /dev/null +++ b/.github/workflows/mainline-format.yml @@ -0,0 +1,27 @@ +name: HyperCPU CI/CD Pipeline (format) + +on: + workflow_call: + +jobs: + format: + runs-on: ubuntu-latest + container: + image: ghcr.io/hypercpu-project/hypercpu-builder:latest + options: --init + permissions: + contents: read + packages: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Fix permissions + run: chown -R ci:ci "$GITHUB_WORKSPACE" + + - name: Run formatters + run: sudo -u ci bazelisk run :format + + - name: Check diff + run: sudo -u ci git diff --quiet diff --git a/.github/workflows/mainline-lint.yml b/.github/workflows/mainline-lint.yml new file mode 100644 index 00000000..17c8d592 --- /dev/null +++ b/.github/workflows/mainline-lint.yml @@ -0,0 +1,28 @@ +name: HyperCPU CI/CD Pipeline (lint) + +on: + workflow_call: + +jobs: + lint: + runs-on: ubuntu-latest + container: + image: ghcr.io/hypercpu-project/hypercpu-builder:latest + options: --init + permissions: + contents: read + packages: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - name: Fix permissions + run: chown -R ci:ci "$GITHUB_WORKSPACE" + + - name: Run linters + continue-on-error: true + run: sudo -u ci bazelisk lint //src/... --aspect:interactive=false -k --config=linux-dbg diff --git a/.github/workflows/mainline-prepare.yml b/.github/workflows/mainline-prepare.yml new file mode 100644 index 00000000..bf062ee4 --- /dev/null +++ b/.github/workflows/mainline-prepare.yml @@ -0,0 +1,35 @@ +name: Build & Push GHCR HyperCPU Builder Image (prepare environment) + +on: + workflow_call: + +jobs: + build-docker-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: .github/Dockerfile + push: true + tags: ghcr.io/hypercpu-project/hypercpu-builder:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/mainline-test.yml b/.github/workflows/mainline-test.yml new file mode 100644 index 00000000..b4d0cbb2 --- /dev/null +++ b/.github/workflows/mainline-test.yml @@ -0,0 +1,42 @@ +name: HyperCPU CI/CD Pipeline (install & smoke) + +on: + workflow_call: + inputs: + artifact_name: + type: string + default: "hcpu-tarballs*" + +jobs: + install-and-test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: Debian + image: debian:stable + - name: Fedora + image: fedora:latest + - name: Arch Linux + image: archlinux:base-devel + + container: + image: ${{ matrix.image }} + + steps: + - name: Download tarball artifacts + uses: actions/download-artifact@v4 + with: + pattern: ${{ inputs.artifact_name }} + merge-multiple: true + path: artifacts/ + + - name: Extract and run tarballs + run: | + for archive in artifacts/*.tar.gz; do + tar -xpf "$archive" -C / --overwrite + for f in /opt/hcpu/tests/*; do + [ -f "$f" ] && [ -x "$f" ] && "$f" + done + done diff --git a/.github/workflows/mainline.yml b/.github/workflows/mainline.yml new file mode 100644 index 00000000..ababaf32 --- /dev/null +++ b/.github/workflows/mainline.yml @@ -0,0 +1,28 @@ +# Main workflow file. This complex workflow declares +# primary automated jobs that are relevant to +# building and testing HyperCPU. + +name: HyperCPU CI/CD Pipeline + +on: + push: + +jobs: + prepare: + uses: ./.github/workflows/mainline-prepare.yml + + package: + needs: prepare + uses: ./.github/workflows/mainline-compile.yml + + format: + needs: prepare + uses: ./.github/workflows/mainline-format.yml + + lint: + needs: prepare + uses: ./.github/workflows/mainline-lint.yml + + tests: + needs: package + uses: ./.github/workflows/mainline-test.yml \ No newline at end of file diff --git a/.github/workflows/run-tests-feature-branch.yml b/.github/workflows/run-tests-feature-branch.yml deleted file mode 100644 index f162b636..00000000 --- a/.github/workflows/run-tests-feature-branch.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: HyperCPU CI/CD Pipeline (feature branch) - -on: - push: - -jobs: - testing: - runs-on: ubuntu-latest - container: - image: hyperwin/hcpu-ci:debian-unstable - # see https://github.com/bazelbuild/bazel/issues/13823 - options: --init - if: (github.ref != 'refs/heads/master' && github.ref != 'refs/heads/dev') || !contains(github.event.head_commit.message, '[ci skip]') - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - submodules: "true" - - - name: Install conan dependecies - run: | - conan profile detect && conan install . --build=missing - - - name: Build and test with GCC on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=gcc - bazelisk clean --expunge - - - name: Build and test with LLVM on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=clang - bazelisk clean --expunge diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml deleted file mode 100644 index cf42f349..00000000 --- a/.github/workflows/testing.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: HyperCPU CI/CD Pipeline - -on: - pull_request: - branches: - - master - -jobs: - testing: - runs-on: ubuntu-latest - container: - image: hyperwin/hcpu-ci:debian-unstable - # see https://github.com/bazelbuild/bazel/issues/13823 - options: --init - name: Run full test suite - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - submodules: "true" - - - name: Install conan dependecies - run: | - conan profile detect && conan install . --build=missing - - - name: Build and test with GCC on Debug profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=gcc - bazelisk clean --expunge - - - name: Build and test with GCC on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-opt --compiler=gcc - bazelisk clean --expunge - - - name: Build and test with LLVM on Debug profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=clang - bazelisk clean --expunge - - - name: Build and test with LLVM on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-opt --compiler=clang - bazelisk clean --expunge diff --git a/.github/workflows/version-increment.yml b/.github/workflows/version-increment.yml index 887ea69e..8d21cb58 100644 --- a/.github/workflows/version-increment.yml +++ b/.github/workflows/version-increment.yml @@ -6,58 +6,42 @@ on: - master jobs: - versioning-patch-increment: + versioning-increment: runs-on: ubuntu-latest container: image: hyperwin/hcpu-ci:debian-unstable - options: --user root - if: "contains(github.event.head_commit.message, '[ci patch inc]')" - permissions: - contents: write - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: "0" - - - name: Setup git user - uses: fregante/setup-git-user@v1 - - - name: Increment version (patch) - run: | - tools/increment_version.py --increment patch - - - name: Push changes to master branch - run: | - git config --global --add safe.directory '*' - git add . - git commit -m "[auto]: Increment patch version" - git push origin master - versioning-minor-increment: - runs-on: ubuntu-latest - container: hyperwin/hcpu-ci:debian-unstable - if: "contains(github.event.head_commit.message, '[ci minor inc]')" permissions: contents: write + strategy: + matrix: + include: + - increment: patch + marker: '[ci-patch-increase]' + - increment: minor + marker: '[ci-minor-increase]' + - increment: major + marker: '[ci-major-increase]' + + if: > + contains(github.event.head_commit.message, '[ci-patch-increase]') || + contains(github.event.head_commit.message, '[ci-minor-increase]') || + contains(github.event.head_commit.message, '[ci-major-increase]') + steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: - fetch-depth: "0" + fetch-depth: 0 - - name: Setup git user - uses: fregante/setup-git-user@v1 + - uses: fregante/setup-git-user@v1 - - name: Increment version (minor) + - name: Fire increment version script (${{ matrix.increment }}) + id: increment run: | - tools/increment_version.py --increment minor + tools/increment_version.py --increment ${{ matrix.increment }} >> $GITHUB_OUTPUT - - name: Push changes to master branch - run: | - git config --global --add safe.directory '*' - git add . - git commit -m "[auto]: Increment minor version" - git push origin master + - name: Commit changes + uses: EndBug/add-and-commit@v9 + with: + message: "Increment ${{ matrix.increment }} version to ${{ steps.increment.outputs }}" diff --git a/.gitignore b/.gitignore index 8856848f..691671db 100644 --- a/.gitignore +++ b/.gitignore @@ -101,6 +101,6 @@ conan/ # Bazel builds with four directories, see for info: # https://bazel.build/remote/output-directories -bazel-* -bazel -output \ No newline at end of file +bazel-*/ +bazel/ +output/ diff --git a/.gitmodules b/.gitmodules index 62e35b98..953052d6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,12 @@ [submodule "dist/HPool"] path = dist/HPool url = https://github.com/randommfs/HPool +[submodule "foreign/eternal"] + path = foreign/eternal + url = https://github.com/mapbox/eternal +[submodule "foreign/HPool"] + path = foreign/HPool + url = https://github.com/randommfs/HPool +[submodule "foreign/libbacktrace"] + path = foreign/libbacktrace + url = https://github.com/ianlancetaylor/libbacktrace diff --git a/BUILD.bazel b/BUILD.bazel index 76e2bfa1..c191ce24 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -16,6 +16,7 @@ config_setting( refresh_compile_commands( name = "refresh_compile_commands", + exclude_external_sources = True, targets = { "//src/...": "--config=linux-dbg", "//tests/...": "--config=linux-dbg", @@ -32,6 +33,14 @@ refresh_compile_commands( # ) ) +exports_files( + [ + ".ruff.toml", + ".clang-tidy", + ], + visibility = ["//visibility:public"], +) + format_multirun( name = "format", cc = "@llvm_toolchain//:bin/clang-format", diff --git a/MODULE.bazel b/MODULE.bazel index 77feb092..7ecc8417 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,40 +6,43 @@ module( compatibility_level = 1, ) -# We use conan for deps management -conan = use_extension("//conan:conan_deps_module_extension.bzl", "conan_extension") -use_repo( - conan, - "abseil", - "argparse", - "benchmark", - "boost", - "bzip2", - "eternal", - "fmt", - "gtest", - "libbacktrace", - "libunwind", - "re2", - "spdlog", - "xz_utils", - "zlib", -) +######################### +# Starlark dependencies # +######################### + +# Rules for building cpp objects: shared & static libs, binaries etc. +bazel_dep(name = "rules_cc", version = "0.1.2") -bazel_dep(name = "rules_cc", version = "0.0.17") -bazel_dep(name = "aspect_rules_lint", version = "1.3.5") +# Bazel skylib: core library for starlark. bazel_dep(name = "bazel_skylib", version = "1.7.1") +# Bazel helpers to include other projects. +bazel_dep(name = "rules_foreign_cc", version = "0.14.0") + +# These rules provide hooks for compile_commands.json generation - useful for clangd. bazel_dep(name = "hedron_compile_commands", dev_dependency = True) -bazel_dep(name = "buildifier_prebuilt", version = "8.0.3", dev_dependency = True) +# Rules for creating tarballs with our precious binaries. +bazel_dep(name = "rules_pkg", version = "1.1.0", dev_dependency = True) + +# Rules to constraint buildsystem. +bazel_dep(name = "platforms", version = "1.0.0", dev_dependency = True) + +# For formatting/linting. +bazel_dep(name = "aspect_rules_lint", version = "1.5.3", dev_dependency = True) + +# Formal bazel itself. +bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2") + +# Bazel deps are normally pulled from BCR (registry), but sometimes +# it is needed to fetch them elsewhere. This command does exactly that. git_override( module_name = "hedron_compile_commands", - commit = "4f28899228fb3ad0126897876f147ca15026151e", + commit = "abb61a688167623088f8768cc9264798df6a9d10", remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git", ) -# We use this for static analysis +# We use this for static analysis (and formatting). bazel_dep(name = "toolchains_llvm", version = "1.4.0", dev_dependency = True) llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") @@ -47,3 +50,19 @@ llvm.toolchain( llvm_version = "19.1.7", ) use_repo(llvm, "llvm_toolchain") + +################################ +# Actual HyperCPU dependencies # +################################ + +# These come from Google. +bazel_dep(name = "abseil-cpp", version = "20250512.1") +bazel_dep(name = "re2", version = "2024-07-02.bcr.1") +bazel_dep(name = "googletest", version = "1.17.0") +bazel_dep(name = "google_benchmark", version = "1.9.1") + +# These do not come from Google but we love them still. +bazel_dep(name = "fmt", version = "11.2.0") +bazel_dep(name = "spdlog", version = "1.15.3") +bazel_dep(name = "libunwind", version = "1.8.1") +bazel_dep(name = "argparse", version = "3.2.0") diff --git a/README.md b/README.md index 0250ffc2..3e2d91d8 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+### What is this
+
HyperCPU is a set of programs created to work with my own simple ISA (instruction set architecture). The project was created for fun, but it took a lot of time (and nerves), and I learned a lot while working on it.
HyperCPU project includes:
@@ -23,7 +43,7 @@ See [ROADMAP.md](ROADMAP.md) for project ideas and tasks.
>[!IMPORTANT]
> HyperCPU is almost ready for use! Wait for 1.0 release to try it out or build the project yourself, test it and report issues.
-
+
### Installation
diff --git a/conandata.yml b/conandata.yml
deleted file mode 100644
index aa465698..00000000
--- a/conandata.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-requirements:
- gtest: "1.14.0"
- benchmark: "1.9.1"
- abseil: "20240116.1"
- libbacktrace: "cci.20210118"
- argparse: "3.2"
- eternal: "1.0.1"
- re2: "20230801"
- fmt: "11.0.2"
- libunwind: "1.8.1"
- boost: "1.87.0"
- spdlog: "1.15.0"
diff --git a/conanfile.py b/conanfile.py
deleted file mode 100644
index 0707284c..00000000
--- a/conanfile.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from typing import Dict, Any, Collection
-from functools import cached_property, lru_cache
-
-from conan import ConanFile
-from conan.tools.google import bazel_layout
-
-
-class HyperCPU(ConanFile):
- name: "HyperCPU"
- settings = ["os", "compiler", "build_type", "arch"]
-
- # conan data is fetched dynamically from
- # conandata.yml
- conan_data: Dict[str, Any]
-
- @cached_property
- def generators(self) -> Collection[str]:
- return ["BazelToolchain", "BazelDeps"]
-
- @lru_cache
- def requirements(self) -> None:
- for req, version in self.conan_data["requirements"].items():
- self.requires(f"{req}/{version}")
-
- def layout(self):
- bazel_layout(self)
diff --git a/dist/BUILD.bazel b/dist/BUILD.bazel
deleted file mode 100644
index 39a3d6eb..00000000
--- a/dist/BUILD.bazel
+++ /dev/null
@@ -1,13 +0,0 @@
-load("@rules_cc//cc:defs.bzl", "cc_library")
-
-package(
- default_visibility = [
- "//:__subpackages__",
- ],
-)
-
-cc_library(
- name = "hpool",
- hdrs = ["HPool/hpool.hpp"],
- includes = ["HPool"],
-)
diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt
deleted file mode 100644
index 756d643c..00000000
--- a/dist/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-cmake_minimum_required(VERSION 3.22)
-
-# hpool
-set(HPOOL_BUILD_TESTS OFF CACHE BOOL "Whether to include test target into configuration" FORCE)
-set(HPOOL_BUILD_BENCHMARKS OFF CACHE BOOL "Whether to include benchmark target into configuration" FORCE)
-add_subdirectory(HPool)
-
-add_library(dist::hpool ALIAS hpool)
diff --git a/dist/HPool b/dist/HPool
deleted file mode 160000
index 352cdd4e..00000000
--- a/dist/HPool
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 352cdd4e5eb2bfb091bd4970386387b6d6f027b1
diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile
deleted file mode 100644
index ecea2c60..00000000
--- a/docker/alpine/Dockerfile
+++ /dev/null
@@ -1,11 +0,0 @@
-FROM alpine:latest
-
-ARG BAZELISK_TAG=v1.15.0
-
-RUN apk update \
- && apk add --no-cache python3 py3-pip clang gcc git cmake make ninja grep g++ linux-headers wget \
- && pip3 install --no-cache-dir --break-system-packages conan
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/docker/archlinux/Dockerfile b/docker/archlinux/Dockerfile
deleted file mode 100644
index 655622db..00000000
--- a/docker/archlinux/Dockerfile
+++ /dev/null
@@ -1,13 +0,0 @@
-FROM archlinux:latest
-
-ARG BAZELISK_TAG=v1.15.0
-
-RUN pacman -Syu --noconfirm --needed \
- python python-pip git cmake clang gcc \
- base-devel wget \
- && pip install --no-cache-dir --break-system-packages conan \
- && pacman -Scc --noconfirm
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/docker/debian-stable/Dockerfile b/docker/debian-stable/Dockerfile
deleted file mode 100644
index 041d377b..00000000
--- a/docker/debian-stable/Dockerfile
+++ /dev/null
@@ -1,12 +0,0 @@
-FROM debian:latest
-
-ARG BAZELISK_TAG=v1.15.0
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- git cmake clang libre2-9 libre2-dev python3 python3-pip cmake wget make gcc g++ \
- && pip3 install --no-cache-dir --break-system-packages conan \
- && rm -rf /var/lib/apt/lists/*
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/docker/debian-unstable/Dockerfile b/docker/debian-unstable/Dockerfile
deleted file mode 100644
index 5e84b468..00000000
--- a/docker/debian-unstable/Dockerfile
+++ /dev/null
@@ -1,12 +0,0 @@
-FROM debian:unstable
-
-ARG BAZELISK_TAG=v1.15.0
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- git cmake clang libre2-11 libre2-dev python3 python3-pip cmake wget make gcc g++ \
- && pip3 install --no-cache-dir --break-system-packages conan \
- && rm -rf /var/lib/apt/lists/*
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/docker/fedora/Dockerfile b/docker/fedora/Dockerfile
deleted file mode 100644
index 09d4a225..00000000
--- a/docker/fedora/Dockerfile
+++ /dev/null
@@ -1,14 +0,0 @@
-FROM fedora:latest
-
-ARG BAZELISK_TAG=v1.15.0
-
-RUN dnf update -y \
- && dnf install -y --setopt=install_weak_deps=False git cmake \
- clang gcc which nodejs python3 python3-pip make awk wget \
- && pip3 install --no-cache-dir --break-system-packages conan \
- && dnf clean all \
- && rm -rf /var/cache/dnf
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/docker/gentoo-glibc/Dockerfile b/docker/gentoo-glibc/Dockerfile
deleted file mode 100644
index d67b47d2..00000000
--- a/docker/gentoo-glibc/Dockerfile
+++ /dev/null
@@ -1,12 +0,0 @@
-FROM gentoo/stage3:systemd
-
-ARG BAZELISK_TAG=v1.15.0
-
-RUN emerge --sync > /dev/null && \
- getuto && \
- emerge llvm-core/clang cmake dev-vcs/git re2 libfmt gtest which wget conan --getbinpkg -j2 && \
- rm -rf /var/lib/repos/gentoo
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/docker/gentoo-musl/stage1/Dockerfile b/docker/gentoo-musl/stage1/Dockerfile
deleted file mode 100644
index 15412712..00000000
--- a/docker/gentoo-musl/stage1/Dockerfile
+++ /dev/null
@@ -1,6 +0,0 @@
-FROM gentoo/stage3:musl
-
-RUN emerge --sync > /dev/null && \
- getuto && \
- sed -i 's/^MAKEOPTS=".*"/MAKEOPTS="& -j8"/' /etc/portage/make.conf && \
- emerge llvm-core/llvm cmake gtest re2 libfmt dev-vcs/git conan --getbinpkg
diff --git a/docker/gentoo-musl/stage2/Dockerfile b/docker/gentoo-musl/stage2/Dockerfile
deleted file mode 100644
index b39ee4ab..00000000
--- a/docker/gentoo-musl/stage2/Dockerfile
+++ /dev/null
@@ -1,10 +0,0 @@
-FROM hyperwin/hcpu-ci:gentoo-musl-build
-
-ARG BAZELISK_TAG=v1.15.0
-
-RUN emerge llvm-core/clang --getbinpkg && \
- rm -rf /var/lib/repos/gentoo
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/docker/ubuntu/Dockerfile b/docker/ubuntu/Dockerfile
deleted file mode 100644
index 88d785f4..00000000
--- a/docker/ubuntu/Dockerfile
+++ /dev/null
@@ -1,13 +0,0 @@
-FROM ubuntu:latest
-
-ARG USER=bazel
-ARG BAZELISK_TAG=v1.15.0
-
-RUN apt update && apt install -y --no-install-recommends \
- git cmake clang libre2-10 libre2-dev python3 python3-pip cmake wget make gcc g++ \
- && pip3 install --no-cache-dir --break-system-packages conan \
- && rm -rf /var/lib/apt/lists/*
-
-RUN wget https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_TAG}/bazelisk-linux-amd64 && \
- chmod 755 bazelisk-linux-amd64 && \
- mv bazelisk-linux-amd64 /usr/bin/bazelisk
diff --git a/foreign/BUILD.bazel b/foreign/BUILD.bazel
new file mode 100644
index 00000000..0cedd4a3
--- /dev/null
+++ b/foreign/BUILD.bazel
@@ -0,0 +1,24 @@
+"Foreign deps"
+
+# Here we have projects that we rely on, but
+# cannot fetch from registry.
+
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+package(
+ default_visibility = [
+ "//:__subpackages__",
+ ],
+)
+
+cc_library(
+ name = "hpool",
+ hdrs = ["HPool/hpool.hpp"],
+ includes = ["HPool"],
+)
+
+cc_library(
+ name = "eternal",
+ hdrs = ["eternal/include/mapbox/eternal.hpp"],
+ includes = ["eternal/include"],
+)
diff --git a/foreign/HPool b/foreign/HPool
new file mode 160000
index 00000000..6b165437
--- /dev/null
+++ b/foreign/HPool
@@ -0,0 +1 @@
+Subproject commit 6b1654378a084f4e7cc7324670543df86d03b7fa
diff --git a/foreign/eternal b/foreign/eternal
new file mode 160000
index 00000000..dd2f5b9f
--- /dev/null
+++ b/foreign/eternal
@@ -0,0 +1 @@
+Subproject commit dd2f5b9ff38fcd36b59efd9d289127fa73efc6cb
diff --git a/ruff.toml b/ruff.toml
new file mode 100644
index 00000000..a69393f3
--- /dev/null
+++ b/ruff.toml
@@ -0,0 +1,61 @@
+# Exclude a variety of commonly ignored directories.
+exclude = [
+ ".bzr",
+ ".direnv",
+ ".eggs",
+ ".git",
+ ".git-rewrite",
+ ".hg",
+ ".ipynb_checkpoints",
+ ".mypy_cache",
+ ".nox",
+ ".pants.d",
+ ".pyenv",
+ ".pytest_cache",
+ ".pytype",
+ ".ruff_cache",
+ ".svn",
+ ".tox",
+ ".venv",
+ ".vscode",
+ "__pypackages__",
+ "_build",
+ "buck-out",
+ "build",
+ "dist",
+ "node_modules",
+ "site-packages",
+ "venv",
+]
+
+# Same as Black.
+line-length = 88
+indent-width = 4
+
+# Assume Python 3.9
+target-version = "py39"
+
+[lint]
+# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
+select = ["E4", "E7", "E9", "F"]
+ignore = []
+
+# Allow fix for all enabled rules (when `--fix`) is provided.
+fixable = ["ALL"]
+unfixable = []
+
+# Allow unused variables when underscore-prefixed.
+dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
+
+[format]
+# Like Black, use double quotes for strings.
+quote-style = "double"
+
+# Like Black, indent with spaces, rather than tabs.
+indent-style = "space"
+
+# Like Black, respect magic trailing commas.
+skip-magic-trailing-comma = false
+
+# Like Black, automatically detect the appropriate line ending.
+line-ending = "auto"
diff --git a/src/Assembler/BUILD.bazel b/src/Assembler/BUILD.bazel
index 8d09b706..8c9df9f2 100644
--- a/src/Assembler/BUILD.bazel
+++ b/src/Assembler/BUILD.bazel
@@ -9,13 +9,12 @@ cc_library(
hdrs = glob(["**/*.hpp"]),
visibility = ["//visibility:public"],
deps = [
- "//dist:hpool",
+ "//foreign:eternal",
+ "//foreign:hpool",
"//src/Common:hcpu_common",
"//src/PCH:pch_cstd",
"//src/Pog:pog",
- "@eternal",
"@fmt",
- "@re2",
"@spdlog",
],
)
@@ -23,9 +22,10 @@ cc_library(
cc_binary(
name = "hcasm",
srcs = ["Main.cpp"],
- visibility = ["//visibility:private"],
+ visibility = ["//visibility:public"],
deps = [
":assembler_core",
"@argparse",
+ "@re2",
],
)
diff --git a/src/Assembler/Core/BinaryTransformer.cpp b/src/Assembler/Core/BinaryTransformer.cpp
index f27fdd11..757eb883 100644
--- a/src/Assembler/Core/BinaryTransformer.cpp
+++ b/src/Assembler/Core/BinaryTransformer.cpp
@@ -2,9 +2,9 @@
#include "Assembler/Core/BinaryTransformer.hpp"
#include "Assembler/Core/Compiler.hpp"
+#include "Common/Exit.hpp"
#include "Common/LanguageSpec/Flags.hpp"
#include "Common/LanguageSpec/Opcodes.hpp"
-#include "Common/Exit.hpp"
#include "PCH/CStd.hpp"
HyperCPU::OperandTypes HCAsm::BinaryTransformer::DetermineOperandTypes(Operand& op1, Operand& op2) {
@@ -12,51 +12,51 @@ HyperCPU::OperandTypes HCAsm::BinaryTransformer::DetermineOperandTypes(Operand&
Op2T tp2 = Op2T::NONE; // Placeholder
switch (op1.type) {
- case HCAsm::OperandType::reg:
- tp1 = Op1T::R;
- break;
- case HCAsm::OperandType::mem_reg_add_int:
- case HCAsm::OperandType::memaddr_reg:
- tp1 = Op1T::RM;
- break;
- case HCAsm::OperandType::sint:
- case HCAsm::OperandType::uint:
- case HCAsm::OperandType::label:
- tp1 = Op1T::IMM;
- break;
- case HCAsm::OperandType::memaddr_int:
- case HCAsm::OperandType::memaddr_lbl:
- tp1 = Op1T::M;
- break;
- case HCAsm::OperandType::none:
- tp1 = Op1T::NONE;
- break;
- default:
- HyperCPU::unreachable();
+ case HCAsm::OperandType::reg:
+ tp1 = Op1T::R;
+ break;
+ case HCAsm::OperandType::mem_reg_add_int:
+ case HCAsm::OperandType::memaddr_reg:
+ tp1 = Op1T::RM;
+ break;
+ case HCAsm::OperandType::sint:
+ case HCAsm::OperandType::uint:
+ case HCAsm::OperandType::label:
+ tp1 = Op1T::IMM;
+ break;
+ case HCAsm::OperandType::memaddr_int:
+ case HCAsm::OperandType::memaddr_lbl:
+ tp1 = Op1T::M;
+ break;
+ case HCAsm::OperandType::none:
+ tp1 = Op1T::NONE;
+ break;
+ default:
+ HyperCPU::unreachable();
}
switch (op2.type) {
- case HCAsm::OperandType::reg:
- tp2 = Op2T::R;
- break;
- case HCAsm::OperandType::mem_reg_add_int:
- case HCAsm::OperandType::memaddr_reg:
- tp2 = Op2T::RM;
- break;
- case HCAsm::OperandType::sint:
- case HCAsm::OperandType::uint:
- case HCAsm::OperandType::label:
- tp2 = Op2T::IMM;
- break;
- case HCAsm::OperandType::memaddr_int:
- case HCAsm::OperandType::memaddr_lbl:
- tp2 = Op2T::M;
- break;
- case HCAsm::OperandType::none:
- tp2 = Op2T::NONE;
- break;
- default:
- HyperCPU::unreachable();
+ case HCAsm::OperandType::reg:
+ tp2 = Op2T::R;
+ break;
+ case HCAsm::OperandType::mem_reg_add_int:
+ case HCAsm::OperandType::memaddr_reg:
+ tp2 = Op2T::RM;
+ break;
+ case HCAsm::OperandType::sint:
+ case HCAsm::OperandType::uint:
+ case HCAsm::OperandType::label:
+ tp2 = Op2T::IMM;
+ break;
+ case HCAsm::OperandType::memaddr_int:
+ case HCAsm::OperandType::memaddr_lbl:
+ tp2 = Op2T::M;
+ break;
+ case HCAsm::OperandType::none:
+ tp2 = Op2T::NONE;
+ break;
+ default:
+ HyperCPU::unreachable();
}
return QuickCast(QuickOR(tp1, tp2));
diff --git a/src/Assembler/Core/Compiler.cpp b/src/Assembler/Core/Compiler.cpp
index 1f8438e6..a0bcb9dd 100644
--- a/src/Assembler/Core/Compiler.cpp
+++ b/src/Assembler/Core/Compiler.cpp
@@ -2,8 +2,8 @@
#include "Assembler/Core/BinaryTransformer.hpp"
#include "Assembler/Core/Compiler.hpp"
-#include "Common/Helpers/Classes.hpp"
#include "Common/Exit.hpp"
+#include "Common/Helpers/Classes.hpp"
#include "PCH/CStd.hpp"
#include "Pog/Pog.hpp"
@@ -21,8 +21,8 @@ HCAsm::HCAsmCompiler::HCAsmCompiler()
parser.get_line_offset() += tok.length();
return {};
});
- parser.token("\\/\\/.*"); // Single line comment
- parser.token("\\/\\*[\\S\\s]+\\*\\/"); /* Multi-line comment */
+ parser.token("\\/\\/.*"); // Single line comment
+ parser.token(R"(\/\*[\S\s]+\*\/)"); /* Multi-line comment */
parser.token(R"(\+)")
.symbol("+");
parser.token(R"(-)")
@@ -66,7 +66,7 @@ HCAsm::HCAsmCompiler::HCAsmCompiler()
parser.token("[a-zA-Z_][a-zA-Z0-9_]*")
.symbol("ident")
.action(TokenizeIdentifier);
- parser.token("\"((?:\\\\[\\s\\S]|[^\"\\\\])*)\"")
+ parser.token(R"lit("((?:\\[\s\S]|[^"\\])*)")lit")
.symbol("string")
.action(TokenizeString);
parser.token(R"(0s[0-9]+)")
@@ -313,35 +313,27 @@ HCAsm::BinaryResult HCAsm::HCAsmCompiler::TransformToBinary(HCAsm::CompilerState
spdlog::info("Running pass 1 - counting code size");
for (auto& instr : ir.ir) {
- VisitVariant(instr,
- [this, &ir](Instruction& instruction) mutable -> void {
- ir.code_size += InstructionSize(instruction);
- },
- [&ir](Label& label) mutable -> void {
+ VisitVariant(instr, [this, &ir](Instruction& instruction) mutable -> void { ir.code_size += InstructionSize(instruction); }, [&ir](Label& label) mutable -> void {
ir.labels[label.name] = ir.code_size;
if (label.is_entry_point) {
ir.entry_point = ir.code_size;
- }
- },
- [&ir](RawValue& raw) mutable -> void {
- ir.code_size += [&raw]() -> std::uint8_t {
- switch (raw.mode) {
- case Mode::b8_str:
- return std::get