This is an automated email from the ASF dual-hosted git repository. yuchanns pushed a commit to branch bindings-go-doc in repository https://gitbox.apache.org/repos/asf/opendal.git
commit aed487b6b84367b39237075cdebf61a352f4ee95 Author: Hanchin Hsieh <[email protected]> AuthorDate: Thu Apr 10 13:01:23 2025 +0800 doc(bindings/go): better Linux test script Hanchin Hsieh <[email protected]> --- bindings/go/README.md | 65 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/bindings/go/README.md b/bindings/go/README.md index e71bb6535..1863aa4b4 100644 --- a/bindings/go/README.md +++ b/bindings/go/README.md @@ -114,10 +114,10 @@ go test -bench . <details> <summary> - A benchmark between [purego+libffi](https://github.com/apache/opendal/commit/bf15cecd5e3be6ecaa7056b5594589c9f4d85673) vs [CGO](https://github.com/apache/opendal/commit/9ef494d6df2e9a13c4e5b9b03bcb36ec30c0a7c0) + A benchmark between purego+libffi vs CGO </summary> -**purego+libffi** (as `new.txt`) +[**purego+libffi**](https://github.com/apache/opendal/commit/bf15cecd5e3be6ecaa7056b5594589c9f4d85673) (as `new.txt`) ``` goos: linux goarch: arm64 @@ -134,7 +134,7 @@ PASS ok ``` -**CGO** (as `old.txt`) +[**CGO**](https://github.com/apache/opendal/commit/9ef494d6df2e9a13c4e5b9b03bcb36ec30c0a7c0) (as `old.txt`) ``` go test -bench=. -tags dynamic . goos: linux @@ -209,17 +209,22 @@ geomean 129.7ยต ## Development -The guide is based on Linux. For other platforms, please adjust the commands accordingly. +The guide is based on Linux and Windows. For other platforms, please adjust the commands accordingly. To develop the Go binding, you need to have the following dependencies installed: - zstd - Rust toolchain - Go +- (Optional for Windows) libffi-8.dll We use `go workspace` to manage and build the dependencies. To set up the workspace, run the following commands: -**Linux and macOS** +<details> + <summary> + **For Linux** + </summary> + ```bash mkdir opendal_workspace @@ -237,20 +242,56 @@ go work use ./opendal-go-services/memory cat <<EOF > ./make_test.sh #!/bin/bash +# Check if OPENDAL_TEST is set +if [ -z "\$OPENDAL_TEST" ]; then + echo "Error: OPENDAL_TEST environment variable is not set" + echo "Please set OPENDAL_TEST to specify which backend to test (e.g., fs or memory)" + exit 1 +fi + +# Specify the backend to test +export SERVICE="\$OPENDAL_TEST" + +# Get architecture architecture=\$(uname -m) -if [ "\$architecture" = "x86_64" ]\;\; then +if [ "\$architecture" = "x86_64" ]; then ARCH="x86_64" -elif [ "\$architecture" = "aarch64" ] || [ "\$architecture" = "arm64" ]\;\; then +elif [ "\$architecture" = "aarch64" ] || [ "\$architecture" = "arm64" ]; then ARCH="arm64" else ARCH="unknown" fi +# Build opendal cd opendal/bindings/c cargo build cd - -zstd -19 opendal/bindings/c/target/debug/libopendal_c.so -o opendal-go-services/fs/libopendal_c.linux.\$ARCH.so.zst +# Set environment variables +export GITHUB_WORKSPACE="\$PWD/opendal-go-services" +export VERSION="latest" +export TARGET="linux" +export DIR="\$GITHUB_WORKSPACE/libopendal_c_\$VERSION_\$SERVICE_\$TARGET" + +# Create directory if not exists +mkdir -p "\$DIR" + +export OUTPUT="\$DIR/libopendal_c_\$VERSION_\$SERVICE_\$TARGET.so" +# Compress with zstd +zstd -19 opendal/bindings/c/target/debug/libopendal_c.so -o \$OUTPUT + +# Generate code +cd opendal-go-services/internal/generate +go run generate.go +cd - + +# Delete unnecessary files +rm -rf \$DIR + +# Set environment variables for test +export MATRIX='{"build": [{"target":"linux", "goos":"linux", "goarch": "amd64"}], "service": ["fs"]}' + +# Run tests go test ./opendal/bindings/go/tests/behavior_tests -v -run TestBehavior EOF @@ -274,11 +315,14 @@ export OPENDAL_FS_ROOT=/tmp/opendal cd - ``` +</details> + <details> <summary> - For Windows + **For Windows** </summary> + ```powershell New-Item -ItemType Directory -Path opendal_workspace Set-Location -Path opendal_workspace @@ -294,7 +338,7 @@ go work use ./opendal-go-services/fs go work use ./opendal-go-services/memory @' -# Specify the backend to test\;Set-Item -Path Env:SERVICE -Value "$env:OPENDAL_TEST"\;# Get architecture\;$architecture = (Get-WmiObject Win32_OperatingSystem).OSArchitecture\;\;if ($architecture -like "*64*") {\; $ARCH = "x86_64"\;} else {\; $ARCH = "unknown" \;}\;\;# Build opendal\;Push-Location opendal/bindings/c\;cargo build\;Pop-Location\;\;# Rename dll file\;Rename-Item opendal/bindings/c/target/debug/opendal_c.dll libopendal_c.dll\;\;# Set environment variables\;Set-Item -Pa [...] +# Check if OPENDAL_TEST is set\;if (-not $env:OPENDAL_TEST) {\; Write-Error "OPENDAL_TEST environment variable is not set"\; Write-Host "Please set OPENDAL_TEST to specify which backend to test (e.g., fs or memory)"\; exit 1\;}\;# Specify the backend to test\;Set-Item -Path Env:SERVICE -Value "$env:OPENDAL_TEST"\;# Get architecture\;$architecture = (Get-WmiObject Win32_OperatingSystem).OSArchitecture\;\;if ($architecture -like "*64*") {\; $ARCH = "x86_64"\;} else {\; $ARCH [...] '@ -replace "\\;","`n" | Out-File -FilePath "MakeTest.ps1" -Encoding UTF8 Pop-Location @@ -313,6 +357,7 @@ $env:OPENDAL_FS_ROOT = $env:TEMP Pop-Location ``` + </details> ## License and Trademarks
