Skip to content

Commit

Permalink
feat: git subtree move in hugr-llvm
Browse files Browse the repository at this point in the history
Due to the LLVM dependency the package is excluded from default CI runs, except check which does not require llvm.

A separate job for building and testing is added that runs on push to main.
  • Loading branch information
ss2165 authored Nov 22, 2024
2 parents 649589c + 010f5cf commit 1b94d45
Show file tree
Hide file tree
Showing 158 changed files with 11,478 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/snapshots/*.snap -diff
4 changes: 4 additions & 0 deletions .github/change-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ python:
- "uv.lock"
- "specification/schema/**"
- ".github/workflows/ci-py.yml"


llvm:
- "hugr-llvm/**"
64 changes: 50 additions & 14 deletions .github/workflows/ci-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
pull_request:
branches:
- main
- '*'
merge_group:
types: [checks_requested]
workflow_dispatch: {}
Expand All @@ -23,7 +23,7 @@ env:

jobs:
# Check if changes were made to the relevant files.
# Always returns true if running on the default branch, to ensure all changes are throughly checked.
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
changes:
name: Check for changes
runs-on: ubuntu-latest
Expand All @@ -35,6 +35,7 @@ jobs:
outputs:
rust: ${{ steps.filter.outputs.rust == 'true' || steps.override.outputs.out == 'true' }}
python: ${{ steps.filter.outputs.python == 'true' || steps.override.outputs.out == 'true' }}
llvm: ${{ steps.filter.outputs.llvm == 'true' || steps.override.outputs.out == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Override label
Expand Down Expand Up @@ -91,9 +92,9 @@ jobs:
- name: Install CapnProto
run: sudo apt-get install -y capnproto
- name: Build benchmarks with no features
run: cargo bench --verbose --no-run --workspace --no-default-features
run: cargo bench --verbose --no-run --no-default-features
- name: Build benchmarks with all features
run: cargo bench --verbose --no-run --workspace --all-features
run: cargo bench --verbose --no-run --all-features

# Run tests on Rust stable
tests-stable-no-features:
Expand All @@ -110,12 +111,13 @@ jobs:
toolchain: "stable"
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}

- name: Install CapnProto
run: sudo apt-get install -y capnproto
- name: Build with no features
run: cargo test --verbose --workspace --no-default-features --no-run
run: cargo test --verbose --no-default-features --no-run
- name: Tests with no features
run: cargo test --verbose --workspace --no-default-features
run: cargo test --verbose --no-default-features

# Run tests on Rust stable
tests-stable-all-features:
Expand All @@ -132,12 +134,13 @@ jobs:
toolchain: "stable"
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}

- name: Install CapnProto
run: sudo apt-get install -y capnproto
- name: Build with all features
run: cargo test --verbose --workspace --all-features --no-run
run: cargo test --verbose --all-features --no-run
- name: Tests with all features
run: cargo test --verbose --workspace --all-features
run: cargo test --verbose --all-features
- name: Build HUGR binary
run: cargo build -p hugr-cli
- name: Upload the binary to the artifacts
Expand Down Expand Up @@ -170,13 +173,13 @@ jobs:
- name: Install CapnProto
run: sudo apt-get install -y capnproto
- name: Build with no features
run: cargo test --verbose --workspace --no-default-features --no-run
run: cargo test --verbose --no-default-features --no-run
- name: Tests with no features
run: cargo test --verbose --workspace --no-default-features
run: cargo test --verbose --no-default-features
- name: Build with all features
run: cargo test --verbose --workspace --all-features --no-run
run: cargo test --verbose --all-features --no-run
- name: Tests with all features
run: cargo test --verbose --workspace --all-features
run: cargo test --verbose --all-features

# Ensure that serialized extensions match rust implementation
std-extensions:
Expand Down Expand Up @@ -225,8 +228,8 @@ jobs:
- name: Run tests with coverage instrumentation
run: |
cargo llvm-cov clean --workspace
cargo llvm-cov --no-report --workspace --no-default-features --doctests
cargo llvm-cov --no-report --workspace --all-features --doctests
cargo llvm-cov --no-report --no-default-features --doctests
cargo llvm-cov --no-report --all-features --doctests
- name: Generate coverage report
run: cargo llvm-cov --all-features report --codecov --output-path coverage.json
- name: Upload coverage to codecov.io
Expand All @@ -237,6 +240,39 @@ jobs:
flags: rust
token: ${{ secrets.CODECOV_TOKEN }}

tests-stable-llvm:
needs: changes
if: ${{ ( needs.changes.outputs.llvm == 'true' && github.event_name == 'push' ) || needs.changes.outputs.override == 'true' }}
runs-on: ubuntu-latest
name: tests hugr-llvm
strategy:
matrix:
llvm-version:
# different strings for install action and feature name
# adapted from https://github.com/TheDan64/inkwell/blob/master/.github/workflows/test.yml
- ["14.0", "14-0"]

steps:
- uses: actions/checkout@v4
- uses: mozilla-actions/[email protected]
- id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: "stable"
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
- name: Install CapnProto
run: sudo apt-get install -y capnproto
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2
with:
version: ${{ matrix.llvm-version[0] }}
env: true
- name: Build
run: cargo test -p hugr-llvm --verbose --features llvm${{ matrix.llvm-version[1] }} --no-run
- name: Tests with no features
run: cargo test -p hugr-llvm --verbose --features llvm${{ matrix.llvm-version[1] }}

rs-semver-checks:
needs: [changes, check]
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name == 'pull_request' }}
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ lto = "thin"

[workspace]
resolver = "2"
members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]
members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model", "hugr-llvm"]
default-members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]

[workspace.package]
rust-version = "1.75"
Expand Down Expand Up @@ -64,6 +65,7 @@ predicates = "3.1.0"
indexmap = "2.3.0"
fxhash = "0.2.1"
bumpalo = { version = "3.16.0" }
pathsearch = "0.2.0"

[profile.dev.package]
insta.opt-level = 3
Expand Down
3 changes: 3 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ To setup the environment manually you will need:
- Rust `>=1.75`: https://www.rust-lang.org/tools/install
- uv `>=0.3`: docs.astral.sh/uv/getting-started/installation
- capnproto `>=1.0`: https://capnproto.org/install.html
- Optional: llvm `== 14.0`. The "llvm" feature (backed by the sub-crate `hugr-llvm`)
requires LLVM installed. We use the rust bindings
[llvm-sys](https://crates.io/crates/llvm-sys) to [llvm](https://llvm.org/),

Once you have these installed, you can install the required python dependencies and setup pre-commit hooks with:

Expand Down
14 changes: 14 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ in
default = true;
description = "run `just setup` on entering shell";
};

llvmVersion = lib.mkOption {
type = lib.types.str;
default = "14";
};
};

config = {
Expand All @@ -23,6 +28,10 @@ in
pkgs.graphviz
pkgs.cargo-insta
pkgs.capnproto

# These are required for hugr-llvm to be able to link to llvm.
pkgs.libffi
pkgs.libxml2
] ++ lib.optionals
pkgs.stdenv.isDarwin
(with pkgs.darwin.apple_sdk; [
Expand All @@ -32,6 +41,11 @@ in
frameworks.SystemConfiguration
]);

env = {
"LLVM_SYS_${cfg.llvmVersion}0_PREFIX" = "${pkgs."llvmPackages_${cfg.llvmVersion}".libllvm.dev}";
};


# https://devenv.sh/scripts/
scripts.hello.exec = "echo Welcome to hugr dev shell!";

Expand Down
114 changes: 114 additions & 0 deletions hugr-llvm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.13.3](https://github.com/CQCL/hugr-llvm/compare/v0.6.0...v0.6.1) - 2024-11-25
No changes - version bump to catch up with other hugr crates in repository move.

## [0.6.1](https://github.com/CQCL/hugr-llvm/compare/v0.6.0...v0.6.1) - 2024-10-23

### Bug Fixes

- don't normalise half turns ([#137](https://github.com/CQCL/hugr-llvm/pull/137))

## [0.6.0](https://github.com/CQCL/hugr-llvm/compare/v0.5.1...v0.6.0) - 2024-10-21

### Bug Fixes

- Conversion operations having poison results ([#131](https://github.com/CQCL/hugr-llvm/pull/131))

### New Features

- [**breaking**] Allow extension callbacks to have non-`'static` lifetimes ([#128](https://github.com/CQCL/hugr-llvm/pull/128))
- [**breaking**] Support `tket2.rotation.from_halfturns_unchecked` ([#133](https://github.com/CQCL/hugr-llvm/pull/133))

### Refactor

- [**breaking**] remove trait emit op ([#104](https://github.com/CQCL/hugr-llvm/pull/104))
- [**breaking**] rework extensions interface ([#119](https://github.com/CQCL/hugr-llvm/pull/119))
- [**breaking**] move packaged extensions from `crate::custom` to `crate::extension` ([#126](https://github.com/CQCL/hugr-llvm/pull/126))

## [0.5.1](https://github.com/CQCL/hugr-llvm/compare/v0.5.0...v0.5.1) - 2024-09-23

### New Features

- provide `inline_constant_functions` ([#108](https://github.com/CQCL/hugr-llvm/pull/108))

## [0.5.0](https://github.com/CQCL/hugr-llvm/compare/v0.4.0...v0.5.0) - 2024-09-16

### New Features

- Add emitters for int <-> float/usize conversions ([#94](https://github.com/CQCL/hugr-llvm/pull/94))
- [**breaking**] array ops ([#96](https://github.com/CQCL/hugr-llvm/pull/96))
- Add conversions itobool, ifrombool ([#101](https://github.com/CQCL/hugr-llvm/pull/101))
- Add `tket2` feature and lowerings for `tket2.rotation` extension ([#100](https://github.com/CQCL/hugr-llvm/pull/100))

### Testing

- Add execution test framework ([#97](https://github.com/CQCL/hugr-llvm/pull/97))

## [0.3.1](https://github.com/CQCL/hugr-llvm/compare/v0.3.0...v0.3.1) - 2024-08-28

### New Features
- Emit more int operations ([#87](https://github.com/CQCL/hugr-llvm/pull/87))

## [0.3.0](https://github.com/CQCL/hugr-llvm/compare/v0.2.1...v0.3.0) - 2024-08-27

### New Features
- [**breaking**] Lower string, print, and panic ([#78](https://github.com/CQCL/hugr-llvm/pull/78))
- Lower float operations ([#83](https://github.com/CQCL/hugr-llvm/pull/83))
- Lower logic extension ([#81](https://github.com/CQCL/hugr-llvm/pull/81))
- Lower arrays ([#82](https://github.com/CQCL/hugr-llvm/pull/82))

## [0.2.1](https://github.com/CQCL/hugr-llvm/compare/v0.2.0...v0.2.1) - 2024-08-19

### Documentation
- Remove fixed crate version in usage instructions ([#68](https://github.com/CQCL/hugr-llvm/pull/68))

### New Features
- Add lowering for LoadFunction ([#65](https://github.com/CQCL/hugr-llvm/pull/65))
- Emission for CallIndirect nodes ([#73](https://github.com/CQCL/hugr-llvm/pull/73))

## [0.2.0](https://github.com/CQCL/hugr-llvm/compare/v0.1.0...v0.2.0) - 2024-07-31

### New Features
- make EmitFuncContext::iw_context pub ([#55](https://github.com/CQCL/hugr-llvm/pull/55))

### Refactor
- use HugrFuncType/HugrType/HugrSumType ([#56](https://github.com/CQCL/hugr-llvm/pull/56))
- remove unneeded `HugrView` constraints ([#59](https://github.com/CQCL/hugr-llvm/pull/59))
- [**breaking**] add `LLVMSumValue` ([#63](https://github.com/CQCL/hugr-llvm/pull/63))

### Testing
- Add test for LoadFunction Op ([#60](https://github.com/CQCL/hugr-llvm/pull/60))

## [0.1.0](https://github.com/CQCL/hugr-llvm/releases/tag/v0.1.0) - 2024-07-10

### Bug Fixes
- Syntax error
- sum type tag elision logic reversed
- [**breaking**] Allow Const and FuncDecl as children of Modules, Dataflow Parents, and CFG nodes ([#46](https://github.com/CQCL/hugr-llvm/pull/46))

### Documentation
- fix bad grammar ([#34](https://github.com/CQCL/hugr-llvm/pull/34))

### New Features
- Emission for Call nodes
- Support values
- add `get_extern_func` ([#28](https://github.com/CQCL/hugr-llvm/pull/28))
- lower CFGs ([#26](https://github.com/CQCL/hugr-llvm/pull/26))
- Add initial codegen extension for `prelude` ([#29](https://github.com/CQCL/hugr-llvm/pull/29))
- [**breaking**] `Namer` optionally appends node index to mangled names. ([#32](https://github.com/CQCL/hugr-llvm/pull/32))
- Implement lowerings for ieq,ilt_s,sub in int codegen extension ([#33](https://github.com/CQCL/hugr-llvm/pull/33))
- Add initial `float` extension ([#31](https://github.com/CQCL/hugr-llvm/pull/31))
- Emit more int comparison operators ([#47](https://github.com/CQCL/hugr-llvm/pull/47))

### Refactor
- clean up fat.rs ([#38](https://github.com/CQCL/hugr-llvm/pull/38))

### Testing
- add a test for sum type tags
- Add integration tests lowering guppy programs ([#35](https://github.com/CQCL/hugr-llvm/pull/35))
40 changes: 40 additions & 0 deletions hugr-llvm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "hugr-llvm"
version = "0.13.3"
description = "A general and extensible crate for lowering HUGRs into LLVM IR"

edition.workspace = true
rust-version.workspace = true

readme = "README.md"
license.workspace = true
homepage.workspace = true
repository.workspace = true
documentation = "https://docs.rs/hugr-llvm"
authors = ["TKET development team <[email protected]>"]
keywords = ["Quantum", "Quantinuum"]
categories = ["compilers"]

[features]
default = ["llvm14-0"]
llvm14-0 = ["inkwell/llvm14-0"]

[dependencies]
inkwell = { version = "0.4.0", default-features = false }
hugr-core = { path = "../hugr-core", version = "0.13.3"}
anyhow = "1.0.83"
itertools.workspace = true
delegate.workspace = true
petgraph.workspace = true
lazy_static.workspace = true
downcast-rs.workspace = true
strum.workspace = true

[dev-dependencies]
insta.workspace = true
rstest.workspace = true
portgraph.workspace = true
pathsearch.workspace = true
serde_json.workspace = true
serde.workspace = true
typetag.workspace = true
Loading

0 comments on commit 1b94d45

Please sign in to comment.