Skip to content
Draft
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
213 changes: 12 additions & 201 deletions .github/actions/tket-c-api/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ inputs:
description: "Path where the tket-c-api library will be installed"
required: true
target:
description: "Target platform, used for caching"
description: "Target platform"
required: false
default: ${{ runner.arch }}
compatibility:
description: "Generic compatibility, e.g. 'manylinux_2_28' on linux or '11.0' on macos."
required: false
default: 'N/A'
runs:
using: composite
steps:
Expand All @@ -17,211 +21,18 @@ runs:
id: cache
with:
path: ${{ inputs.install-path }}
key: ${{ runner.os }}-${{ inputs.target }}-${{ hashFiles('tket1-passes/conanfile.txt') }}-${{ hashFiles('tket1-passes/conan-profiles/**') }}-${{ hashFiles('.github/actions/tket-c-api/action.yml') }}
key: ${{ runner.os }}-${{ inputs.target }}-${{ hashFiles('tket1-passes/conanfile.txt') }}

- name: Install conan
- name: Run install script
if: steps.cache.outputs.cache-hit != 'true'
uses: conan-io/setup-conan@v1
with:
cache_packages: true

- name: Set up conan remote
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0

- name: Install cross-compilation toolchains
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
TARGET="${{ inputs.target }}"

# Install cross-compilation toolchains based on target
case "$TARGET" in
aarch64-unknown-linux-gnu|aarch64-unknown-linux-musl)
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
;;
armv7-unknown-linux-gnueabihf|armv7-unknown-linux-musleabihf)
sudo apt-get update
sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
;;
i686-unknown-linux-gnu|i686-unknown-linux-musl)
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib
;;
x86_64-unknown-linux-gnu|x86_64-unknown-linux-musl)
# Native compilation, no cross-compiler needed
;;
*)
# For other targets, check if cross-compilation is needed
if [[ "$TARGET" == *"linux"* ]] && [[ "$TARGET" != *"x86_64"* ]]; then
echo "Warning: Unknown Linux target $TARGET, cross-compilation may fail"
fi
;;
esac

- name: Determine conan profile
if: steps.cache.outputs.cache-hit != 'true'
id: conan-profile
shell: bash
run: |
TARGET="${{ inputs.target }}"
PROFILE=""

case "$TARGET" in
aarch64-unknown-linux-gnu)
PROFILE="linux-armv8-gcc14"
;;
aarch64-unknown-linux-musl)
PROFILE="linux-armv8-gcc14"
;;
armv7-unknown-linux-gnueabihf)
PROFILE="linux-armv7-gcc14"
;;
armv7-unknown-linux-musleabihf)
PROFILE="linux-armv7-gcc14"
;;
i686-unknown-linux-gnu)
PROFILE="linux-i686-gcc14"
;;
i686-unknown-linux-musl)
PROFILE="linux-i686-gcc14"
;;
x86_64-unknown-linux-gnu)
PROFILE="linux-x86_64-gcc14"
;;
x86_64-unknown-linux-musl)
PROFILE="linux-x86_64-gcc14"
;;
x86_64-pc-windows-msvc)
PROFILE="windows-2025"
;;
*)
# For non-Linux targets or if no match, let conan generate a default profile
if [[ "$TARGET" == *"apple"* ]] && [[ "$TARGET" == *"aarch64"* ]]; then
PROFILE="macos-15"
elif [[ "$TARGET" == *"apple"* ]] && [[ "$TARGET" == *"x86_64"* ]]; then
PROFILE="macos-15-intel"
elif [[ "$TARGET" == *"windows"* ]] && [[ "$TARGET" == *"msvc"* ]]; then
PROFILE="windows-2025"
elif [[ "$TARGET" == *"armv8"* ]] || [[ "$TARGET" == *"aarch64"* ]]; then
PROFILE="linux-armv8-gcc14"
elif [[ "$TARGET" == *"x86_64"* ]]; then
PROFILE="linux-x86_64-gcc14"
else
PROFILE=""
fi
;;
esac

if [ -z "$PROFILE" ]; then
echo "No profile found for target: $TARGET, using default"
echo "profile=" >> $GITHUB_OUTPUT
echo "use_profile=false" >> $GITHUB_OUTPUT
else
# Check if profile exists in tket1-passes/conan-profiles directory
if [ -f "tket1-passes/conan-profiles/$PROFILE" ]; then
PROFILE_PATH="tket1-passes/conan-profiles/$PROFILE"
echo "profile=$PROFILE_PATH" >> $GITHUB_OUTPUT
echo "use_profile=true" >> $GITHUB_OUTPUT
echo "Selected profile: $PROFILE_PATH"
else
echo "Profile $PROFILE not found in tket1-passes/conan-profiles/, using default"
echo "profile=" >> $GITHUB_OUTPUT
echo "use_profile=false" >> $GITHUB_OUTPUT
fi
fi

- name: Build and install tket-c-api
if: steps.cache.outputs.cache-hit != 'true' && runner.os != 'Windows'
shell: bash
run: |
cd tket1-passes
mkdir -p ${{ inputs.install-path }}

# Set up cross-compilation environment variables if needed
TARGET="${{ inputs.target }}"
export CC=""
export CXX=""

case "$TARGET" in
aarch64-unknown-linux-gnu|aarch64-unknown-linux-musl)
export CC="aarch64-linux-gnu-gcc"
export CXX="aarch64-linux-gnu-g++"
;;
armv7-unknown-linux-gnueabihf|armv7-unknown-linux-musleabihf)
export CC="arm-linux-gnueabihf-gcc"
export CXX="arm-linux-gnueabihf-g++"
;;
i686-unknown-linux-gnu|i686-unknown-linux-musl)
# For i686, conan profile with arch=x86 should handle -m32 automatically
# No need to set CC/CXX explicitly
;;
esac

if [ -n "$CC" ]; then
echo "Using cross-compiler: CC=$CC, CXX=$CXX"
# Verify cross-compiler is available and working
$CC --version || echo "Warning: Failed to get $CC version"
fi

# Build conan install command
CONAN_CMD="conan install . --build=missing --options=\"tket-c-api/*:shared=True\""

if [ "${{ steps.conan-profile.outputs.use_profile }}" == "true" ]; then
CONAN_CMD="$CONAN_CMD --profile=${{ github.workspace }}/${{ steps.conan-profile.outputs.profile }}"
echo "Using profile: ${{ steps.conan-profile.outputs.profile }}"
else
echo "Using default conan profile"
fi

CONAN_CMD="$CONAN_CMD --format=json"
echo "Running: $CONAN_CMD"

CONAN_OUTPUT=$(eval $CONAN_CMD)
CONAN_LIB_FOLDER=$(echo "$CONAN_OUTPUT" | jq -r ".graph.nodes.\"1\".package_folder")
echo "CONAN_LIB_FOLDER: $CONAN_LIB_FOLDER"
cp -r "$CONAN_LIB_FOLDER/"* "${{ inputs.install-path }}/"

- name: Build and install tket-c-api (Windows)
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
shell: pwsh
run: |
Set-Location tket1-passes
New-Item -ItemType Directory -Force -Path "${{ inputs.install-path }}" | Out-Null

# Build conan install command
$conanCmd = "conan install . --build=missing --options=`"tket-c-api/*:shared=True`""

if ("${{ steps.conan-profile.outputs.use_profile }}" -eq "true") {
$profilePath = "${{ github.workspace }}/${{ steps.conan-profile.outputs.profile }}"
$conanCmd = "$conanCmd --profile=$profilePath"
Write-Host "Using profile: $profilePath"
} else {
Write-Host "Using default conan profile"
}

Write-Host "CMake option CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON will be passed to the build"

$conanCmd = "$conanCmd --format=json"
Write-Host "Running: $conanCmd"

$conanOutput = Invoke-Expression $conanCmd
$conanJson = $conanOutput | ConvertFrom-Json
$conanLibFolder = $conanJson.graph.nodes.'1'.package_folder

Write-Host "CONAN_LIB_FOLDER: $conanLibFolder"
Write-Host "Files in CONAN_LIB_FOLDER:"

# Copy the built library files to the install path
Get-ChildItem -Path "$conanLibFolder" -Recurse -File | ForEach-Object { Write-Output $_.FullName }
Copy-Item -Recurse -Force -Path "$conanLibFolder\*" -Destination "${{ inputs.install-path }}"
Write-Host "tket-c-api library files:"
Get-ChildItem -Path "${{ inputs.install-path }}" -Recurse -File | ForEach-Object { Write-Output $_.FullName }
tket1-passes/scripts/build.sh \
"${{ inputs.target }}" \
"${{ inputs.compatibility }}" \
"${{ inputs.install-path }}"

- name: Upload compiled library to cache
- name: Save the cached tket-c-api
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28

- name: Install uv
uses: astral-sh/setup-uv@v7
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- name: Check formatting
run: cargo fmt -- --check
- name: Install LLVM and Clang
Expand Down Expand Up @@ -103,6 +105,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- name: Install Python ${{ env.PYTHON_HIGHEST }}
run: uv python install ${{ env.PYTHON_HIGHEST }}
- name: Setup dependencies
Expand Down Expand Up @@ -130,6 +134,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- uses: cargo-bins/cargo-binstall@main
- name: Install cargo-codspeed
run: cargo binstall cargo-codspeed --force
Expand Down Expand Up @@ -163,6 +169,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- uses: taiki-e/install-action@nextest
- name: Build with no features
run: cargo nextest r --verbose -p tket -p tket-py -p tket-qsystem --no-default-features --no-run
Expand Down Expand Up @@ -192,6 +200,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- uses: taiki-e/install-action@nextest
- name: Build with all features
run: cargo nextest r --verbose --workspace --all-features --no-run
Expand Down Expand Up @@ -226,6 +236,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- name: Configure default rust toolchain
run: rustup override set ${{steps.toolchain.outputs.name}}
- uses: taiki-e/install-action@nextest
Expand Down Expand Up @@ -260,6 +272,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run tests with coverage instrumentation
Expand Down Expand Up @@ -307,6 +321,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- uses: cargo-bins/cargo-binstall@main
- name: Install cargo-minimal-versions
run: |
Expand Down Expand Up @@ -348,6 +364,8 @@ jobs:
uses: ./.github/actions/tket-c-api
with:
install-path: ${{ env.TKET_C_API_PATH }}
target: x86_64-unknown-linux-gnu
compatibility: manylinux_2_28
- name: Install Python ${{ env.PYTHON_LOWEST }}
run: uv python install ${{ env.PYTHON_LOWEST }}
- name: Setup dependencies
Expand Down
Loading
Loading