From 8140ea827eabc564debe0132e4648f042ebb64fc Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Wed, 17 Jul 2024 01:00:06 +0800 Subject: [PATCH 1/2] improve static lib --- .github/workflows/ci.yml | 10 +++++++++- .gitignore | 3 +++ Makefile | 6 +++--- Utils/Package.swift | 4 ++-- Utils/Sources/module.modulemap | 4 ++++ scripts/{deps.sh => blst.sh} | 17 +++++------------ 6 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 Utils/Sources/module.modulemap rename scripts/{deps.sh => blst.sh} (57%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10bfcd3c..e257492b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,12 +31,20 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/cache@v4 + - 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-${{ hashFiles('.lib/*.a') }} + 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." From 40cf6791cac77fadbd83e21b4d19dd37f8b85222 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Wed, 17 Jul 2024 20:13:52 +0800 Subject: [PATCH 2/2] fix ci --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e257492b..456c341d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,10 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive + - 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: @@ -42,7 +46,7 @@ jobs: uses: actions/cache@v4 with: path: .lib - key: ${{ runner.os }}-libs-${{ hashFiles('.lib/*.a') }} + key: ${{ runner.os }}-libs-${{ steps.blst-commit-hash.outputs.commit-hash }} restore-keys: | ${{ runner.os }}-libs- - name: Setup Swift