Alejandro Cabeza Romero de11d81252
Update lib names.
2026-04-27 15:34:41 +02:00

155 lines
6.8 KiB
YAML

name: "Compile Witness Generator"
description: "Compiles the witness generator of a Circom Circuit"
branding:
icon: "package"
color: "blue"
inputs:
circuit-name-display:
description: "The name of the Circom circuit to compile."
required: true
circuit-name-binary:
description: "The name used for artifact labelling. Should match the circuit's canonical name (e.g. pol, poq)."
required: true
circuit-path:
description: "The path to the Circom circuit file relative to the repository root."
required: true
resources-path:
description: "The path to the CI resources directory relative to the repository root."
required: false
default: ".github/resources"
version:
description: "The version of the bundle. E.g.: v1.0.0."
required: true
os:
description: "The target operating system for the bundle (linux, windows, macos)."
required: true
arch:
description: "The target architecture for the bundle (x86_64, aarch64)."
required: true
runs:
using: "composite"
steps:
- name: Parse Circuit Path
id: parse-circuit-path
shell: bash
env:
CIRCUIT_PATH: ${{ inputs.circuit-path }}
BUNDLE_TRIPLET: ${{ inputs.version }}-${{ inputs.os }}-${{ inputs.arch }}
CIRCUIT_NAME_BINARY: ${{ inputs.circuit-name-binary }}
RESOURCES_PATH: ${{ inputs.resources-path }}
OS: ${{ inputs.os }}
run: |
CIRCUIT_DIRECTORY="$(dirname ${CIRCUIT_PATH})"
CIRCUIT_FILENAME="$(basename ${CIRCUIT_PATH})"
CIRCUIT_FILESTEM="${CIRCUIT_FILENAME%.circom}"
CIRCUIT_CPP_DIRNAME="${CIRCUIT_FILESTEM}_cpp"
if [ "${OS}" = "windows" ]; then
LIB_EXT=".lib"
LIB_PREFIX=""
else
LIB_EXT=".a"
LIB_PREFIX="lib"
fi
{
echo "CIRCUIT_DIRECTORY=${CIRCUIT_DIRECTORY}"
echo "CIRCUIT_FILENAME=${CIRCUIT_FILENAME}"
echo "CIRCUIT_FILESTEM=${CIRCUIT_FILESTEM}"
echo "CIRCUIT_CPP_DIRNAME=${CIRCUIT_CPP_DIRNAME}"
echo "CIRCUIT_CPP_PATH=${CIRCUIT_DIRECTORY}/${CIRCUIT_CPP_DIRNAME}"
echo "WITNESS_GENERATOR_RESOURCES_PATH=${RESOURCES_PATH}/witness-generator"
echo "BUNDLE_TRIPLET=${BUNDLE_TRIPLET}"
echo "LIB_NAME=${LIB_PREFIX}${CIRCUIT_FILESTEM}${LIB_EXT}"
} >> "${GITHUB_OUTPUT}"
- name: Generate ${{ inputs.circuit-name-display }}
shell: bash
working-directory: ${{ steps.parse-circuit-path.outputs.CIRCUIT_DIRECTORY }}
env:
CIRCUIT_FILENAME: ${{ steps.parse-circuit-path.outputs.CIRCUIT_FILENAME }}
run: circom --c --r1cs --no_asm --O2 "${CIRCUIT_FILENAME}"
- name: Copy ${{ inputs.circuit-name-display }} FFI Sources
shell: bash
env:
SOURCES_ROOT: ${{ github.workspace }}/src
CIRCUIT_CPP_PATH: ${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}
CIRCUIT_FILESTEM: ${{ steps.parse-circuit-path.outputs.CIRCUIT_FILESTEM }}
run: |
cp -r "${SOURCES_ROOT}/${CIRCUIT_FILESTEM}" "${CIRCUIT_CPP_PATH}/${CIRCUIT_FILESTEM}"
cp "${SOURCES_ROOT}/circom_adapter.cpp" "${CIRCUIT_CPP_PATH}/circom_adapter.cpp"
cp "${SOURCES_ROOT}/circom_adapter.hpp" "${CIRCUIT_CPP_PATH}/circom_adapter.hpp"
cp "${SOURCES_ROOT}/circom_fwd.hpp" "${CIRCUIT_CPP_PATH}/circom_fwd.hpp"
cp "${SOURCES_ROOT}/types.hpp" "${CIRCUIT_CPP_PATH}/types.hpp"
# TODO: Instead of replace, make a fork that generates the appropriate Makefile
- name: Replace ${{ inputs.circuit-name-display }}'s Makefile
shell: bash
env:
WITNESS_GENERATOR_RESOURCES_PATH: ${{ steps.parse-circuit-path.outputs.WITNESS_GENERATOR_RESOURCES_PATH }}
CIRCUIT_CPP_PATH: ${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}
run: cp "${WITNESS_GENERATOR_RESOURCES_PATH}/Makefile" "${CIRCUIT_CPP_PATH}/Makefile"
# circom-generated main() has no return on the success path; patch it before -O3 turns it into an infinite loop
- name: Patch ${{ inputs.circuit-name-display }} Missing Return
shell: bash
env:
CIRCUIT_CPP_PATH: ${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}
OS: ${{ inputs.os }}
run: |
SED_I="sed -i"
if [ "$OS" = "macos" ]; then SED_I="sed -i ''"; fi
$SED_I ':a;N;$!ba;s/\n}\n\n*$/\n return 0;\n}/' "${CIRCUIT_CPP_PATH}/main.cpp"
# TODO: Instead of insertion, make a fork that includes the appropriate patch (or the actual fix)
- name: Patch MacOS GMP
shell: bash
if: ${{ inputs.os == 'macos' }}
env:
WITNESS_GENERATOR_RESOURCES_PATH: ${{ steps.parse-circuit-path.outputs.WITNESS_GENERATOR_RESOURCES_PATH }}
CIRCUIT_CPP_PATH: ${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}
OS: ${{ inputs.os }}
run: cp "${WITNESS_GENERATOR_RESOURCES_PATH}/${{ env.OS }}.gmp_patch.hpp" "${CIRCUIT_CPP_PATH}/gmp_patch.hpp"
- name: Compile ${{ inputs.circuit-name-display }}
if: ${{ inputs.os != 'windows' }}
shell: bash
working-directory: ${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}
env:
CIRCUIT_FILESTEM: ${{ steps.parse-circuit-path.outputs.CIRCUIT_FILESTEM }}
OS: ${{ inputs.os }}
run: make PROJECT="${CIRCUIT_FILESTEM}" "${OS}-lib"
- name: Compile ${{ inputs.circuit-name-display }}
if: ${{ inputs.os == 'windows' }}
shell: msys2 {0}
working-directory: ${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}
env:
CIRCUIT_FILESTEM: ${{ steps.parse-circuit-path.outputs.CIRCUIT_FILESTEM }}
OS: ${{ inputs.os }}
run: make PROJECT="${CIRCUIT_FILESTEM}" "${OS}-lib"
- name: Stage ${{ inputs.circuit-name-display }} Headers
shell: bash
env:
CIRCUIT_CPP_PATH: ${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}
CIRCUIT_FILESTEM: ${{ steps.parse-circuit-path.outputs.CIRCUIT_FILESTEM }}
run: |
mkdir -p "${CIRCUIT_CPP_PATH}/include"
mv "${CIRCUIT_CPP_PATH}/calcwit.hpp" "${CIRCUIT_CPP_PATH}/include/"
mv "${CIRCUIT_CPP_PATH}/circom.hpp" "${CIRCUIT_CPP_PATH}/include/"
mv "${CIRCUIT_CPP_PATH}/fr.hpp" "${CIRCUIT_CPP_PATH}/include/"
mv "${CIRCUIT_CPP_PATH}/${CIRCUIT_FILESTEM}/ffi.hpp" "${CIRCUIT_CPP_PATH}/include/"
mv "${CIRCUIT_CPP_PATH}/types.hpp" "${CIRCUIT_CPP_PATH}/include/"
- name: Upload ${{ inputs.circuit-name-display }}
uses: actions/upload-artifact@de65e23aa2b7e23d713bb51fbfcb6d502f8667d8
with:
name: ${{ inputs.circuit-name-binary }}-${{ inputs.version }}-${{ inputs.os }}-${{ inputs.arch }}
path: |
${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}/${{ steps.parse-circuit-path.outputs.LIB_NAME }}
${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}/${{ steps.parse-circuit-path.outputs.CIRCUIT_FILESTEM }}.dat
${{ steps.parse-circuit-path.outputs.CIRCUIT_CPP_PATH }}/include