Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve static lib #38

Merged
merged 2 commits into from
Jul 17, 2024
Merged
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
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.vscode/settings.json

# static lib files
.lib/
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Utils/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions Utils/Sources/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module blst {
header "blst/bindings/blst.h"
link "blst"
}
17 changes: 5 additions & 12 deletions scripts/deps.sh → scripts/blst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOL > include/module.modulemap
module blst {
header "../bindings/blst.h"
link "blst"
export *
}
EOL
cp libblst.a ${CWD}/.lib

echo "Setup blst successfully."
Loading