Skip to content

Commit 6fcc512

Browse files
committed
Add aws-sdk-cpp
1 parent f40e764 commit 6fcc512

2 files changed

Lines changed: 96 additions & 11 deletions

File tree

benchmark/Makefile

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ BUILD_DIR := build
1313
IMPLEMENTATIONS_INC := $(BUILD_DIR)/implementations.inc
1414

1515
GO_LIB := $(BUILD_DIR)/libgo$(so_ext)
16-
CPP_LIB := $(BUILD_DIR)/libs3cpp$(so_ext)
16+
CPP_LIB := $(BUILD_DIR)/libawscpp$(so_ext)
1717
RUST_LIB := $(BUILD_DIR)/librust$(so_ext)
18+
S3CPP_LIB := $(BUILD_DIR)/libs3cpp$(so_ext)
1819

19-
all: $(GO_LIB) $(CPP_LIB) $(IMPLEMENTATIONS_INC)
20+
all: $(GO_LIB) $(CPP_LIB) $(RUST_LIB) $(S3CPP_LIB) $(IMPLEMENTATIONS_INC)
2021

2122
$(BUILD_DIR):
2223
mkdir -p $@
@@ -25,26 +26,49 @@ $(BUILD_DIR):
2526
$(GO_LIB): | $(BUILD_DIR)
2627
cd ./aws-sdk-go-v2 && go build -buildmode=c-shared -o ../$(BUILD_DIR)/libgo$(so_ext) .
2728

28-
$(CPP_LIB): | $(BUILD_DIR)
29-
cmake --build ../build
30-
c++ -std=c++26 -shared -fPIC -I../src s3cpp/task.cpp -o $(BUILD_DIR)/libs3cpp$(so_ext) \
31-
../build/lib/libs3cpp.a $(shell pkg-config --libs libcurl libcrypto)
29+
AWS_SDK_CPP_INSTALL := $(BUILD_DIR)/.aws-sdk-cpp-installed
30+
31+
$(CPP_LIB): $(AWS_SDK_CPP_INSTALL) | $(BUILD_DIR)
32+
c++ -std=c++26 -shared -fPIC \
33+
-I$(BUILD_DIR)/aws-sdk-cpp-install/include \
34+
aws-sdk-cpp/task.cpp \
35+
-o $@ \
36+
-L$(BUILD_DIR)/aws-sdk-cpp-install/lib \
37+
-laws-cpp-sdk-s3 -laws-cpp-sdk-core \
38+
-Wl,-rpath,$(BUILD_DIR)/aws-sdk-cpp-install/lib
39+
40+
$(AWS_SDK_CPP_INSTALL): | $(BUILD_DIR)
41+
# Build from source (perhaps we should use a prebuilt binary)
42+
[ -d $(BUILD_DIR)/aws-sdk-cpp ] || \
43+
git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp $(BUILD_DIR)/aws-sdk-cpp
44+
cmake -S $(BUILD_DIR)/aws-sdk-cpp -B $(BUILD_DIR)/aws-sdk-cpp-build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(BUILD_DIR)/aws-sdk-cpp-install -DBUILD_ONLY="s3" -DBUILD_TESTING=OFF
45+
cmake --build $(BUILD_DIR)/aws-sdk-cpp-build --config Release
46+
cmake --install $(BUILD_DIR)/aws-sdk-cpp-build --config Release
47+
touch $@
3248

3349
$(RUST_LIB): | $(BUILD_DIR)
3450
cargo build --release --manifest-path ./aws-sdk-rust/Cargo.toml
3551
mv ./aws-sdk-rust/target/release/librust$(so_ext) $(BUILD_DIR)/.
3652

37-
$(IMPLEMENTATIONS_INC): $(GO_LIB) $(CPP_LIB) $(RUST_LIB) | $(BUILD_DIR)
38-
printf '"./%s",\n' $(GO_LIB) $(CPP_LIB) $(RUST_LIB) > $@
53+
$(S3CPP_LIB): | $(BUILD_DIR)
54+
cmake --build ../build
55+
c++ -std=c++26 -shared -fPIC -I../src s3cpp/task.cpp -o $(BUILD_DIR)/libs3cpp$(so_ext) \
56+
../build/lib/libs3cpp.a $(shell pkg-config --libs libcurl libcrypto)
3957

40-
bench: $(IMPLEMENTATIONS_INC) $(GO_LIB) $(CPP_LIB) $(RUST_LIB) | $(BUILD_DIR)
58+
$(IMPLEMENTATIONS_INC): $(GO_LIB) $(CPP_LIB) $(RUST_LIB) $(S3CPP_LIB) | $(BUILD_DIR)
59+
printf '"./%s",\n' $(GO_LIB) $(CPP_LIB) $(RUST_LIB) $(S3CPP_LIB) > $@
60+
61+
bench: $(IMPLEMENTATIONS_INC) $(GO_LIB) $(CPP_LIB) $(RUST_LIB) $(S3CPP_LIB) | $(BUILD_DIR)
4162
c++ -std=c++26 main.cpp -o $(BUILD_DIR)/bench
4263

43-
test: $(IMPLEMENTATIONS_INC) $(GO_LIB) $(CPP_LIB) $(RUST_LIB) | $(BUILD_DIR)
64+
test: $(IMPLEMENTATIONS_INC) $(GO_LIB) $(S3CPP_LIB) $(RUST_LIB) | $(BUILD_DIR)
4465
c++ -std=c++26 -I../src test.cpp -o $(BUILD_DIR)/test ../build/lib/libs3cpp.a $(shell pkg-config --libs libcurl libcrypto)
4566

4667

47-
.PHONY: all clean
68+
.PHONY: all clean aws-sdk-cpp
69+
aws-sdk-cpp: $(CPP_LIB)
70+
4871
clean:
4972
rm -rf $(BUILD_DIR)
5073
rm -rf ./aws-sdk-rust/target
74+
rm -rf $(BUILD_DIR)/aws-sdk-cpp $(BUILD_DIR)/aws-sdk-cpp-build $(BUILD_DIR)/aws-sdk-cpp-install

benchmark/aws-sdk-cpp/task.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "../tasks.h"
2+
#include <aws/core/Aws.h>
3+
#include <aws/core/auth/AWSCredentials.h>
4+
#include <aws/s3/S3Client.h>
5+
#include <aws/s3/model/GetObjectRequest.h>
6+
#include <print>
7+
#include <sstream>
8+
#include <string>
9+
10+
static bench::ClientHandle initialize_client(const char *access,
11+
const char *secret,
12+
const char *endpoint) {
13+
Aws::SDKOptions options;
14+
Aws::InitAPI(options);
15+
16+
Aws::S3::S3ClientConfiguration clientConfig;
17+
clientConfig.endpointOverride = "http://127.0.0.1:9000/";
18+
clientConfig.region = "eu-west-1";
19+
clientConfig.scheme = Aws::Http::Scheme::HTTP;
20+
21+
Aws::Auth::AWSCredentials credentials(access, secret);
22+
23+
auto client = new Aws::S3::S3Client(
24+
credentials, clientConfig,
25+
Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never,
26+
false);
27+
return reinterpret_cast<bench::ClientHandle>(client);
28+
}
29+
30+
static std::string do_get_object(bench::ClientHandle handle, const char *key) {
31+
auto client = reinterpret_cast<Aws::S3::S3Client *>(handle);
32+
33+
Aws::S3::Model::GetObjectRequest request;
34+
request.SetBucket("bucket");
35+
request.SetKey(key);
36+
37+
auto outcome = client->GetObject(request);
38+
if (!outcome.IsSuccess()) {
39+
std::println("fatal: aws-sdk-cpp get_object {}",
40+
outcome.GetError().GetMessage());
41+
std::exit(1);
42+
}
43+
44+
std::ostringstream ss;
45+
ss << outcome.GetResult().GetBody().rdbuf();
46+
return ss.str();
47+
}
48+
49+
// ABI
50+
extern "C" bench::ClientHandle initClient(const char *access,
51+
const char *secret,
52+
const char *endpoint) noexcept {
53+
auto handle = initialize_client(access, secret, endpoint);
54+
return handle;
55+
}
56+
57+
extern "C" const char *get_object(bench::ClientHandle handle,
58+
const char *key) noexcept {
59+
static thread_local std::string result = do_get_object(handle, key);
60+
return result.c_str();
61+
}

0 commit comments

Comments
 (0)