Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly
groups:
all-dependencies:
patterns:
- '*'
159 changes: 159 additions & 0 deletions .github/workflows/all-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: all-tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions: write-all

jobs:
# From https://doc.rust-lang.org/rustc/instrument-coverage.html
gen-coverage:
runs-on: ubuntu-latest
timeout-minutes: 30

environment:
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-llvm-cov

- name: Regular Tests
run: cargo llvm-cov test --no-report --tests --all-features

- name: Doc Tests
run: cargo llvm-cov test --no-report --doc --all-features

- name: Coverage Report
run: cargo llvm-cov report --doctests --cobertura > coverage.xml

- name: Generate Coverage Report
uses: clearlyip/code-coverage-report-action@v5
id: code_coverage_report_action
# Don't run for dependabot unless you fix PR comment permissions
if: ${{ github.actor != 'dependabot[bot]'}}
with:
# Location of the generated coverage file
filename: 'coverage.xml'
only_list_changed_files: true
badge: true
fail_on_negative_difference: true

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
# Make sure the report was generated and that the event is actually a pull request, run if failed or success
if: steps.code_coverage_report_action.outputs.file != '' && github.event_name == 'pull_request' && (success() || failure())
with:
recreate: true
path: code-coverage-results.md

# See https://crates.io/crates/cargo-hack
build_features:
runs-on: ubuntu-latest
timeout-minutes: 30

environment:
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}

steps:
- uses: actions/checkout@v4

- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: libsodium-dev

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-hack

- run: |
cargo hack --each-feature build --ignore-private
cargo hack --each-feature test --ignore-private --no-run

# From https://github.com/rust-lang/miri
miri:
runs-on: ubuntu-latest
timeout-minutes: 30

environment:
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}

steps:
- uses: actions/checkout@v3

- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: libsodium-dev

- name: Install Miri
run: |
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- name: Test with Miri
run: |
MIRIFLAGS="-Zmiri-disable-isolation" \
cargo miri test --all-features

# From https://doc.rust-lang.org/cargo/guide/continuous-integration.html#verifying-rust-version
# See https://crates.io/crates/cargo-hack
msrv:
runs-on: ubuntu-latest
timeout-minutes: 30

environment:
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}

steps:
- uses: actions/checkout@v4

- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: libsodium-dev

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-hack

- run: cargo hack check --version-range 1.79 --all-targets --all-features --ignore-private

test:
strategy:
matrix:
os: [ubuntu, windows, macos]
arch: [x86_64]
include:
- os: macos
arch: arm
triple: aarch64-apple-darwin
runs-on: ${{ format('{0}-latest', matrix.os) }}
timeout-minutes: 30

environment:
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: dtolnay/rust-toolchain@stable
if: ${{ matrix.triple == null }}
- uses: dtolnay/rust-toolchain@stable
if: ${{ matrix.triple }}
with:
target: ${{ matrix.triple }}

- uses: Swatinem/rust-cache@v2

- run: cargo test --verbose --all-features
32 changes: 32 additions & 0 deletions .github/workflows/cargo-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: cargo-tag

on:
push:
branches: [ "main" ]

jobs:
update-tag:
runs-on: ubuntu-latest
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}

steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.TAG_TOKEN }}

- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: |
jq

- uses: dtolnay/rust-toolchain@stable

- name: Update tag with Cargo.toml
run: |
git config --global user.name 'Tag updating bot'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.TAG_TOKEN }}@github.com/${{ github.repository }}
VERSION="$(cargo metadata --format-version 1 | jq '.packages | .[] | select(.name == "lc3sim")| .version' | tr -d '"')"
git tag -m '' -a v"$VERSION"
git push origin v"$VERSION"
continue-on-error: true
44 changes: 44 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: clippy

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
clippy:
permissions:
contents: read
security-events: write
actions: read

runs-on: ubuntu-latest

environment:
name: ${{ github.ref_name != 'main' && 'testing' || 'unrestricted' }}

steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

- name: Install clippy utils
run: cargo install clippy-sarif sarif-fmt

- name: Run clippy
run:
cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
104 changes: 104 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Derived from: https://github.com/dnaka91/advent-of-code/blob/main/.github/workflows/docs.yml
name: pages

on:
push:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
docs:
permissions:
pages: write
id-token: write
contents: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2

- name: Build docs
run: RUSTDOCFLAGS='--cfg docsrs' cargo doc --all-features

- name: Add redirect
run: echo '<meta http-equiv="refresh" content="0;url=lc3sim/index.html">' > target/doc/index.html
- name: Remove lock file
run: rm target/doc/.lock

- uses: ben-z/[email protected]
with:
branch: gh-pages-mutex

- name: Deploy to GitHub Pages
id: deployment
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: target/doc
target-folder: docs/

coverage:
permissions:
pages: write
id-token: write
contents: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: jq \
wget

- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-llvm-cov

- name: Regular Tests
run: cargo llvm-cov test --no-report --tests --all-features

- name: Doc Tests
run: cargo llvm-cov test --no-report --doc --all-features

- name: Coverage Shield
run: |
printf \
'https://img.shields.io/badge/Code_Coverage-%.2f%%25-blue' \
"$(cargo llvm-cov --quiet --summary-only --doctests --json | \
jq '.data[0].totals.lines.percent')" | \
wget -i - -O badge.svg

- name: Coverage Report
run: cargo llvm-cov report --doctests --html

- name: Add Shield to Report
run: mv badge.svg target/llvm-cov/html

- uses: ben-z/[email protected]
with:
branch: gh-pages-mutex

- name: Deploy to GitHub Pages
id: deployment
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: target/llvm-cov/html
target-folder: coverage/
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lc3sim"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -15,4 +15,3 @@ path = "src/cli.rs"

[dependencies]
thiserror = "2"

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
[![Crate][CrateStatus]][Crate]
[![Tests][TestsStatus]][Tests]
[![Docs][PagesStatus]][Docs]
[![Coverage][Coverage]][CoveragePages]

# LC3 Simulator

_A Rust-based simulator for the LC3 micro-architecture_

[CrateStatus]: https://img.shields.io/crates/v/lc3sim.svg
[Crate]: https://crates.io/crates/lc3sim
[TestsStatus]: https://github.com/wpkelso/lc3sim/actions/workflows/all-tests.yml/badge.svg?branch=main
[Tests]: https://github.com/wpkelso/lc3sim/actions/workflows/all-tests.yml
[PagesStatus]: https://github.com/wpkelso/lc3sim/actions/workflows/pages.yml/badge.svg?branch=main
[Docs]: https://wpkelso.github.io/lc3sim/docs/lc3sim/
[Coverage]: https://wpkelso.github.io/lc3sim/coverage/badge.svg
[CoveragePages]: https://wpkelso.github.io/lc3sim/coverage/
5 changes: 5 additions & 0 deletions src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl RegAddr {
_ => panic!("Argument outside of [0, 7] (the valid LC-3 registers"),
}
}

/// Converts and calls [`Self::panic_from_u8`].
pub const fn panic_from_u16(value: u16) -> Self {
Self::panic_from_u8(value as u8)
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Error)]
Expand Down
Loading
Loading