diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10bfcd3c..456c341d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,12 +31,24 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/cache@v4 + - name: Get blst submodule commit hash + id: blst-commit-hash + run: | + echo "::set-output name=commit-hash::$(git submodule status Utils/Sources/blst/ | cut -c2-41)" + - name: Cache SPM + uses: actions/cache@v4 with: path: '**/.build' key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} restore-keys: | ${{ runner.os }}-spm- + - name: Cache static lib files + uses: actions/cache@v4 + with: + path: .lib + key: ${{ runner.os }}-libs-${{ steps.blst-commit-hash.outputs.commit-hash }} + restore-keys: | + ${{ runner.os }}-libs- - name: Setup Swift uses: SwiftyLab/setup-swift@latest with: diff --git a/.gitignore b/.gitignore index 8ca94566..e1c849fa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ DerivedData/ .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc .vscode/settings.json + +# static lib files +.lib/ diff --git a/Makefile b/Makefile index 366d0a0e..0c0821b2 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,10 @@ default: build githooks: .git/hooks/pre-commit .PHONY: deps -deps: Utils/Sources/blst/lib/libblst.a +deps: .lib/libblst.a -Utils/Sources/blst/lib/libblst.a: - ./scripts/deps.sh +.lib/libblst.a: + ./scripts/blst.sh .PHONY: test test: githooks deps diff --git a/Utils/Package.swift b/Utils/Package.swift index bc3c09a4..6c631524 100644 --- a/Utils/Package.swift +++ b/Utils/Package.swift @@ -33,12 +33,12 @@ let package = Package( "blst", ], linkerSettings: [ - .unsafeFlags(["-L../Utils/Sources/blst/lib"]), + .unsafeFlags(["-L../.lib"]), ] ), .systemLibrary( name: "blst", - path: "Sources/blst/include" + path: "Sources" ), .testTarget( name: "UtilsTests", diff --git a/Utils/Sources/module.modulemap b/Utils/Sources/module.modulemap new file mode 100644 index 00000000..be2b8124 --- /dev/null +++ b/Utils/Sources/module.modulemap @@ -0,0 +1,4 @@ +module blst { + header "blst/bindings/blst.h" + link "blst" +} diff --git a/scripts/deps.sh b/scripts/blst.sh similarity index 57% rename from scripts/deps.sh rename to scripts/blst.sh index e2a6d9fd..efc20977 100755 --- a/scripts/deps.sh +++ b/scripts/blst.sh @@ -2,21 +2,14 @@ # Setup blst C module -cd Utils/Sources/blst || { echo "Submodule directory not found"; exit 1; } +CWD=$(pwd) -./build.sh || { echo "Build blst library failed"; exit 1; } +mkdir -p .lib -mkdir -p include -mkdir -p lib +cd Utils/Sources/blst || { echo "Submodule directory not found"; exit 1; } -cp libblst.a lib/ +./build.sh || { echo "Build blst library failed"; exit 1; } -cat < include/module.modulemap -module blst { - header "../bindings/blst.h" - link "blst" - export * -} -EOL +cp libblst.a ${CWD}/.lib echo "Setup blst successfully."