diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 75e39ff..e32aa97 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,42 +1,93 @@ name: libgoldilocks pipeline -on: [push, pull_request] +on: push jobs: build: + strategy: + matrix: + platform: [ubuntu-latest, windows-latest, raspbian-private, macos-private] + runs-on: ${{ matrix.platform }} + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build Linux + if: ${{ matrix.platform == 'ubuntu-latest' || matrix.platform == 'raspbian-private'}} + run: | + mkdir -p src/.libs + docker build . -t libgoldilocks:${{matrix.platform}} + docker create -it --name dummy libgoldilocks:${{matrix.platform}} bash + docker cp dummy:/usr/local/bin/libgoldilocks.a src/.libs/libgoldilocks.a + docker rm -f dummy + - name: Build Mac + if: ${{ matrix.platform == 'macos-private' }} + run: | + autoreconf --install && ./configure && make all + - name: Setup Win + if: ${{ matrix.platform == 'windows-latest' }} + uses: msys2/setup-msys2@v2 + with: + msystem: mingw64 + update: true + install: > + base-devel + mingw-w64-x86_64-toolchain + - name: Build Windows + if: ${{ matrix.platform == 'windows-latest' }} + shell: msys2 {0} + run: | + autoreconf --install && ./configure && make all + - name: Upload + uses: actions/upload-artifact@v2 + with: + name: libgoldilocks-${{matrix.platform}} + path: src/.libs/libgoldilocks.a + release: runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' + needs: build steps: - name: Checkout uses: actions/checkout@v1 - - name: Build + - name: Download Linux lib + uses: actions/download-artifact@v2 + with: + name: libgoldilocks-ubuntu-latest + path: linux-x86_64 + - name: Download Raspbian lib + uses: actions/download-artifact@v2 + with: + name: libgoldilocks-raspbian-private + path: linux-arm64 + - name: Download Mac lib + uses: actions/download-artifact@v2 + with: + name: libgoldilocks-macos-private + path: darwin-x86_64 + - name: Download Win lib + uses: actions/download-artifact@v2 + with: + name: libgoldilocks-windows-latest + path: windows-x86_64 + - name: Create zip run: | - autoreconf --install - ./configure - make lib - - name: Test - run: make test - - name: Zip - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - run: zip -r -j libgoldilocks build/lib + zip -r libgoldilocks * - name: Bump version - if: github.event_name == 'push' && github.ref == 'refs/heads/master' id: version_bump uses: anothrNick/github-tag-action@1.13.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DEFAULT_BUMP: "patch" RELEASE_BRANCHES: "master" - - name: Create Release - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + - name: Create release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ steps.version_bump.outputs.tag }} - release_name: Release libgoldilocks ${{ steps.version_bump.outputs.tag }} + release_name: libgoldilocks ${{ steps.version_bump.outputs.tag }} draft: false prerelease: false - - name: Upload Release Asset - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + - name: Upload release assets uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 3e18310..df5c234 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ -FROM alpine:3 +FROM alpine:3 as builder WORKDIR libgoldilocks COPY . libgoldilocks RUN apk add automake autoconf libtool make gcc g++ -RUN cd libgoldilocks && autoreconf --install && ./configure && make lib +RUN cd libgoldilocks && autoreconf --install && ./configure && make all + +FROM alpine:3 +COPY --from=builder /libgoldilocks/libgoldilocks/src/.libs/libgoldilocks.a /usr/local/bin/ CMD ["tail", "-f"] diff --git a/src/arch_x86_64/f_impl.c b/src/arch_x86_64/f_impl.c index bf3e384..a4a0d63 100644 --- a/src/arch_x86_64/f_impl.c +++ b/src/arch_x86_64/f_impl.c @@ -16,10 +16,10 @@ void gf_mul (gf_s *__restrict__ cs, const gf as, const gf bs) { /* For some reason clang doesn't vectorize this without prompting? */ unsigned int i; - for (i=0; i #include -#include "field.h" +#include "include/field.h" #include "f_field.h" -#include "goldilocks.h" -#include "api.h" +#include "public_include/goldilocks.h" +#include "include/api.h" static const unsigned char base_point_ser_for_pregen[SER_BYTES] = { 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33 @@ -102,7 +102,12 @@ int main(int argc, char **argv) { output = (const gf_s *)pre; printf("const gf API_NS(precomputed_base_as_fe)[%d]\n", (int)(API_NS(sizeof_precomputed_s) / sizeof(gf))); + +#ifdef __MINGW32__ + printf("VECTOR_ALIGNED = {\n "); +#else printf("VECTOR_ALIGNED __attribute__((visibility(\"hidden\"))) = {\n "); +#endif for (i=0; i < API_NS(sizeof_precomputed_s); i+=sizeof(gf)) { if (i) printf(",\n "); @@ -113,7 +118,13 @@ int main(int argc, char **argv) { output = (const gf_s *)pre_wnaf; printf("const gf API_NS(precomputed_wnaf_as_fe)[%d]\n", (int)(API_NS(sizeof_precomputed_wnafs) / sizeof(gf))); + +#ifdef __MINGW32__ + printf("VECTOR_ALIGNED = {\n "); +#else printf("VECTOR_ALIGNED __attribute__((visibility(\"hidden\"))) = {\n "); +#endif + for (i=0; i < API_NS(sizeof_precomputed_wnafs); i+=sizeof(gf)) { if (i) printf(",\n "); field_print(output++); diff --git a/src/include/word.h b/src/include/word.h index 0d4fb4e..a6d2cbe 100644 --- a/src/include/word.h +++ b/src/include/word.h @@ -6,6 +6,10 @@ #ifndef __WORD_H__ #define __WORD_H__ +#ifdef __MINGW32__ +#define posix_memalign(p, a, s) (((*(p)) = _aligned_malloc((s), (a))), *(p) ?0 :errno) +#endif + /* for posix_memalign */ #define _XOPEN_SOURCE 600 #define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s */