blob: 094b9356d58452b5268c9e82b5e91b165d0bacb3 [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
.PHONY: tests bench clean help check-env generate-services run-tests run-bench
# Detect current OS and architecture
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
# Normalize architecture names
ifeq ($(ARCH),x86_64)
ARCH := amd64
endif
ifeq ($(ARCH),aarch64)
ARCH := arm64
endif
# Define file extensions for different OS
ifeq ($(OS),linux)
LIB_EXT := so
else ifeq ($(OS),darwin)
LIB_EXT := dylib
else
LIB_EXT := dll
OS := windows
endif
# Check if OPENDAL_TEST environment variable is set
check-env:
@if [ -z "$(OPENDAL_TEST)" ]; then \
echo "Error: OPENDAL_TEST environment variable is not set"; \
echo "Please set OPENDAL_TEST to the service you want to test (e.g., fs, s3, etc.)"; \
exit 1; \
fi
# Other variables
SERVICE := $(OPENDAL_TEST)
GITHUB_WORKSPACE := $(PWD)/opendal-go-services
VERSION := latest
MATRIX := '{"build": [{"target":"$(OS)", "goos":"$(OS)", "goarch": "$(ARCH)"}], "service": ["$(SERVICE)"]}'
# Define library file paths
C_LIB_FILE := opendal/bindings/c/target/debug/libopendal_c.$(LIB_EXT)
SERVICE_PKG := $(shell echo $(SERVICE) | tr '-' '_')
FINAL_LIB_FILE := $(GITHUB_WORKSPACE)/$(SERVICE_PKG)/libopendal_c.$(OS).$(ARCH).$(LIB_EXT).zst
# Build C library only when source files change
$(C_LIB_FILE): opendal/bindings/c/src/*.rs opendal/bindings/c/Cargo.toml
@echo "Building C library for service: $(SERVICE)"
cd opendal/bindings/c && cargo build --features "opendal/services-$(shell echo $(SERVICE) | tr '_' '-')"
ifeq ($(OS),windows)
@echo "Renaming opendal_c.$(LIB_EXT) to libopendal_c.$(LIB_EXT) on Windows"
mv opendal/bindings/c/target/debug/opendal_c.$(LIB_EXT) opendal/bindings/c/target/debug/libopendal_c.$(LIB_EXT)
endif
# Create compressed library and generate Go services
$(FINAL_LIB_FILE): $(C_LIB_FILE)
@echo "Compressing library and generating services for $(SERVICE) on $(OS)..."
@mkdir -p $(GITHUB_WORKSPACE)/libopendal_c_$(VERSION)_$(SERVICE)_$(OS)
zstd -19 $< -o $(GITHUB_WORKSPACE)/libopendal_c_$(VERSION)_$(SERVICE)_$(OS)/libopendal_c.$(OS).$(LIB_EXT).zst
@echo "Generating Go services..."
cd opendal-go-services/internal/generate && \
GITHUB_WORKSPACE="$(GITHUB_WORKSPACE)" \
VERSION="$(VERSION)" \
MATRIX=$(MATRIX) \
go run generate.go
@echo "Cleaning up intermediate directory..."
@rm -rf $(GITHUB_WORKSPACE)/libopendal_c_$(VERSION)_$(SERVICE)_$(OS)
# Setup Go workspace for the service
setup-workspace-$(SERVICE):
@echo "Setting up Go workspace for service: $(SERVICE)"
go work use $(GITHUB_WORKSPACE)/$(SERVICE)
@echo "Setting up Go module replacement for service: $(SERVICE)"
cd opendal/bindings/go/tests/behavior_tests && \
go mod edit -replace=github.com/apache/opendal-go-services/$(SERVICE)=$(GITHUB_WORKSPACE)/$(SERVICE) && \
go mod tidy
define SCHEME_TEST_CONTENT
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// generated by github.com/apache/opendal/bindings/go
package opendal_test
import (
opendal "github.com/apache/opendal/bindings/go"
"github.com/apache/opendal-go-services/$(SERVICE)"
)
// Add more schemes for behavior tests here.
var schemes = []opendal.Scheme{
$(SERVICE).Scheme,
}
endef
export SCHEME_TEST_CONTENT
# Generate scheme test file
generate-scheme-$(SERVICE):
@echo "Generating scheme test file..."
@mkdir -p opendal/bindings/go/tests/behavior_tests
@echo "$$SCHEME_TEST_CONTENT" > opendal/bindings/go/tests/behavior_tests/scheme_test.go
# Generate services target with all steps
generate-services: $(FINAL_LIB_FILE) setup-workspace-$(SERVICE) generate-scheme-$(SERVICE)
# Run tests
run-tests: generate-services
@echo "Running behavior tests..."
go test ./opendal/bindings/go/tests/behavior_tests -v -run TestBehavior
# Run benchmarks
run-bench: generate-services
@echo "Running benchmark tests..."
go test ./opendal/bindings/go/tests/behavior_tests -v -bench=. -run=^$$ -count=6 -benchmem
# Main target: run all tests
tests: check-env run-tests
@echo "All tests completed successfully!"
# Main target: run benchmarks only
bench: check-env run-bench
@echo "All benchmarks completed successfully!"
# Clean all generated files
clean:
@echo "Cleaning all generated files..."
rm -rf opendal/bindings/c/target
rm -rf opendal-go-services/*/libopendal_c.*
rm -rf opendal-go-services/*/opendal_c.*
rm -rf opendal-go-services/libopendal_c_*
rm -rf opendal-go-services/opendal_c_*
cd opendal/bindings/go/tests/behavior_tests && go clean -testcache
# Help target
help:
@echo "Available targets:"
@echo " tests - Run all tests (requires OPENDAL_TEST environment variable)"
@echo " bench - Run benchmarks only (requires OPENDAL_TEST environment variable)"
@echo " clean - Clean all generated files"
@echo " help - Show this help message"
@echo ""
@echo "Environment variables:"
@echo " OPENDAL_TEST - Required. The service to test (e.g., fs, s3, gcs, etc.)"
@echo ""
@echo "Example usage:"
@echo " OPENDAL_TEST=fs make tests"
@echo " OPENDAL_TEST=fs make bench"