diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml deleted file mode 100644 index c9a3650..0000000 --- a/.github/workflows/artifacts.yml +++ /dev/null @@ -1,146 +0,0 @@ -name: Artifacts - -on: - push: - tags: - - "v*" - workflow_dispatch: - -jobs: - build: - runs-on: ${{ matrix.target.os }} - strategy: - matrix: - target: - - os: ubuntu-latest - cpu: amd64 - lib_ext: so - - - os: ubuntu-24.04-arm - cpu: arm64 - lib_ext: so - - - os: macos-latest - lib_ext: dylib - cpu: arm64 - - - os: windows-latest - cpu: amd64 - lib_ext: dll - - steps: - - name: Enable long paths (Windows) - if: matrix.target.os == 'windows-latest' - shell: powershell - run: | - Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 - git config --system core.longpaths true - - - name: Check out sources - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Install Rust 1.85.0 - if: matrix.target.os != 'windows-latest' - uses: dtolnay/rust-toolchain@master - with: - toolchain: 1.85.0 - - - name: Record submodule commit - run: git -C vendor/logos-storage-nim rev-parse HEAD > vendor/logos-storage-nim/.storage-commit - - - name: Cache libstorage build - id: cache-libstorage - uses: actions/cache@v4 - with: - path: vendor/logos-storage-nim/build - key: ${{ runner.os }}-${{ matrix.target.cpu }}-libstorage-${{ hashFiles('vendor/logos-storage-nim/.storage-commit') }} - - - name: MSYS2 (Windows amd64) - if: matrix.target.os == 'windows-latest' && matrix.target.cpu == 'amd64' - uses: msys2/setup-msys2@v2 - with: - path-type: inherit - msystem: UCRT64 - install: >- - base-devel - git - mingw-w64-ucrt-x86_64-toolchain - mingw-w64-ucrt-x86_64-cmake - mingw-w64-ucrt-x86_64-ntldd-git - mingw-w64-ucrt-x86_64-rust - - - name: Build libstorage (Linux) - if: matrix.target.lib_ext == 'so' && steps.cache-libstorage.outputs.cache-hit != 'true' - run: | - make update - make libstorage - - - name: Build libstorage (MacOS) - if: matrix.target.os == 'macos-latest' && steps.cache-libstorage.outputs.cache-hit != 'true' - run: | - make update - STORAGE_LIB_PARAMS="--passL:\"-Wl,-install_name,@rpath/libstorage.dylib\"" make libstorage - - - name: Build libstorage (Windows) - if: matrix.target.os == 'windows-latest' && steps.cache-libstorage.outputs.cache-hit != 'true' - shell: msys2 {0} - run: | - pacman -Sy --noconfirm make - git config --global core.symlinks false - make update - make libstorage - - - name: Package artifacts Linux - if: matrix.target.os == 'ubuntu-latest' || matrix.target.os == 'ubuntu-24.04-arm' - run: | - sudo apt-get update && sudo apt-get install -y zip - ZIPFILE=storage-linux-${{ matrix.target.cpu }}.zip - zip -j $ZIPFILE vendor/logos-storage-nim/build/libstorage.${{ matrix.target.lib_ext }} vendor/logos-storage-nim/library/libstorage.h - echo "ZIPFILE=$ZIPFILE" >> $GITHUB_ENV - - - name: Package artifacts MacOS - if: matrix.target.os == 'macos-latest' - run: | - ZIPFILE=storage-macos-${{ matrix.target.cpu }}.zip - zip -j $ZIPFILE vendor/logos-storage-nim/build/libstorage.${{ matrix.target.lib_ext }} vendor/logos-storage-nim/library/libstorage.h - echo "ZIPFILE=$ZIPFILE" >> $GITHUB_ENV - - - name: Package artifacts (Windows) - if: matrix.target.os == 'windows-latest' - shell: msys2 {0} - run: | - ZIPFILE=storage-windows-${{ matrix.target.cpu }}.zip - (cd vendor/logos-storage-nim/build && 7z a -tzip "${GITHUB_WORKSPACE}/${ZIPFILE}" libstorage.dll) - (cd vendor/logos-storage-nim/library && 7z a -tzip "${GITHUB_WORKSPACE}/${ZIPFILE}" libstorage.h) - echo "ZIPFILE=$ZIPFILE" >> $GITHUB_ENV - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: ${{ env.ZIPFILE }} - path: ${{ env.ZIPFILE }} - if-no-files-found: error - - publish-release: - needs: build - runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') - steps: - - name: Check out sources - uses: actions/checkout@v4 - - name: Download artifacts - uses: actions/download-artifact@v5 - with: - path: dist - - name: Create release - uses: softprops/action-gh-release@v2 - with: - files: dist/** - draft: true diff --git a/README.md b/README.md index 8d0958f..97d1c0b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ CGO_LDFLAGS := -L$(LIBS_DIR) -lstorage -Wl,-rpath,$(LIBS_DIR) OS ?= "linux" ARCH ?= "amd64" VERSION ?= "v0.0.21" -DOWNLOAD_URL := "https://github.com/logos-storage/logos-storage-go-bindings/releases/download/$(VERSION)/storage-${OS}-${ARCH}.zip" +DOWNLOAD_URL := "https://github.com/logos-storage/logos-storage-nim/releases/download/$(VERSION)/storage-${OS}-${ARCH}.zip" # Edit your binary name here ifeq ($(OS),Windows_NT) diff --git a/storage/node.go b/storage/node.go index 6db55fa..c470cb7 100644 --- a/storage/node.go +++ b/storage/node.go @@ -31,16 +31,16 @@ package storage return storage_close(storageCtx, (StorageCallback) callback, resp); } - static int cGoStorageDestroy(void* storageCtx, void* resp) { - return storage_destroy(storageCtx, (StorageCallback) callback, resp); + static int cGoStorageDestroy(void* storageCtx) { + return storage_destroy(storageCtx); } - static int cGoStorageVersion(void* storageCtx, void* resp) { - return storage_version(storageCtx, (StorageCallback) callback, resp); + static char* cGoStorageVersion(void* storageCtx) { + return storage_version(storageCtx); } - static int cGoStorageRevision(void* storageCtx, void* resp) { - return storage_revision(storageCtx, (StorageCallback) callback, resp); + static char* cGoStorageRevision(void* storageCtx) { + return storage_revision(storageCtx); } static int cGoStorageRepo(void* storageCtx, void* resp) { @@ -276,7 +276,7 @@ func (node StorageNode) Destroy() error { return err } - if C.cGoStorageDestroy(node.ctx, bridge.resp) != C.RET_OK { + if C.cGoStorageDestroy(node.ctx) != C.RET_OK { return bridge.callError("cGoStorageDestroy") } @@ -289,26 +289,18 @@ func (node StorageNode) Destroy() error { } // Version returns the version of the Logos Storage node. -func (node StorageNode) Version() (string, error) { - bridge := newBridgeCtx() - defer bridge.free() +func (node StorageNode) Version() string { + cStr := C.cGoStorageVersion(node.ctx) + defer C.free(unsafe.Pointer(cStr)) - if C.cGoStorageVersion(node.ctx, bridge.resp) != C.RET_OK { - return "", bridge.callError("cGoStorageVersion") - } - - return bridge.wait() + return C.GoString(cStr) } -func (node StorageNode) Revision() (string, error) { - bridge := newBridgeCtx() - defer bridge.free() +func (node StorageNode) Revision() string { + cStr := C.cGoStorageRevision(node.ctx) + defer C.free(unsafe.Pointer(cStr)) - if C.cGoStorageRevision(node.ctx, bridge.resp) != C.RET_OK { - return "", bridge.callError("cGoStorageRevision") - } - - return bridge.wait() + return C.GoString(cStr) } // Repo returns the path of the data dir folder. diff --git a/storage/node_test.go b/storage/node_test.go index ebf29c2..782db11 100644 --- a/storage/node_test.go +++ b/storage/node_test.go @@ -13,10 +13,8 @@ func TestStorageVersion(t *testing.T) { t.Fatalf("Failed to create Logos Storage node: %v", err) } - version, err := node.Version() - if err != nil { - t.Fatalf("Failed to get Logos Storage version: %v", err) - } + version := node.Version() + if version == "" { t.Fatal("Logos Storage version is empty") } @@ -31,10 +29,8 @@ func TestStorageRevision(t *testing.T) { t.Fatalf("Failed to create Logos Storage node: %v", err) } - revision, err := node.Revision() - if err != nil { - t.Fatalf("Failed to get Logos Storage revision: %v", err) - } + revision := node.Revision() + if revision == "" { t.Fatal("Logos Storage revision is empty") } diff --git a/vendor/logos-storage-nim b/vendor/logos-storage-nim index 3c09f00..3bc6aa8 160000 --- a/vendor/logos-storage-nim +++ b/vendor/logos-storage-nim @@ -1 +1 @@ -Subproject commit 3c09f008bb5266a669fd19f18368f9e8b861b664 +Subproject commit 3bc6aa8b8d5ee72d23d793a0e909016214cdd599