Skip to content

Commit

Permalink
ABI WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Woz committed Oct 31, 2024
1 parent 763e1dc commit 497ccb2
Show file tree
Hide file tree
Showing 31 changed files with 1,626 additions and 1,101 deletions.
1,486 changes: 743 additions & 743 deletions .github/workflows/tests.yml

Large diffs are not rendered by default.

186 changes: 186 additions & 0 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
name: versions

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
source_abi:
runs-on: ubuntu-22.04
outputs:
extension_version: ${{ steps.build_extension.outputs.extension_version }}
abi_version: ${{ steps.build_extension.outputs.abi_version }}
alternate_abi_version: ${{ steps.build_extension.outputs.alternate_abi_version }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
fetch-tags: true
- uses: hendrikmuhs/[email protected]
with:
max-size: 2G
key: ${{ github.job }}
- name: Build
id: build_extension
run: |
gem install --no-document --user-install nokogiri
export COMMITS_SINCE_LAST_TAG=$(git describe --tags --always --long | awk -F '-' '{print $2}')
EXTENSION_VERSION=$(ruby -e 'print [ARGF.read[/PHP_COUCHBASE_VERSION "(\d+\.\d+\.\d+)"/, 1], ENV["COMMITS_SINCE_LAST_TAG"].to_i > 0 ? ENV["COMMITS_SINCE_LAST_TAG"] : nil].compact.join(".")' src/php_couchbase.hxx)
echo "extension_version=${EXTENSION_VERSION}" >> "$GITHUB_OUTPUT"
ABI_VERSION=$(ruby -e 'print ARGF.read[/PHP_COUCHBASE_VERSION "(\d+\.\d+\.\d+)"/, 1].gsub(".", "_")' src/php_couchbase.hxx)
ALTERNATE_ABI_VERSION=$(ruby -e 'print ARGF.read[/PHP_COUCHBASE_VERSION "(\d+\.\d+\.\d+)"/, 1].gsub(".", "_").succ' src/php_couchbase.hxx)
echo "abi_version=${ABI_VERSION}" >> "$GITHUB_OUTPUT"
echo "alternate_abi_version=${ALTERNATE_ABI_VERSION}" >> "$GITHUB_OUTPUT"
export BUILD_NUMBER="${COMMITS_SINCE_LAST_TAG}"
ruby ./bin/package.rb
- name: PHPDoc
run: |
ruby ./bin/docs.rb
- uses: actions/upload-artifact@v4
with:
name: couchbase-${{ steps.build_extension.outputs.extension_version }}
path: |
couchbase-*.tgz
- uses: actions/upload-artifact@v4
with:
retention-days: 1
name: scripts-${{ steps.build_extension.outputs.extension_version }}
path: |
bin/**/*
90-couchbase.ini
phpcs.xml
- uses: actions/upload-artifact@v4
with:
retention-days: 1
name: tests-${{ steps.build_extension.outputs.extension_version }}
path: |
tests/**/*
- uses: actions/upload-artifact@v4
with:
name: docs-${{ steps.build_extension.outputs.extension_version }}
path: |
build/couchbase-php-client-*/**/*
abi_linux_build:
needs: source_abi
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
version:
- unversioned
- ${{ needs.source_abi.outputs.abi_version }}
- ${{ needs.source_abi.outputs.alternate_abi_version }}
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: json, mbstring, intl
env:
phpts: nts
- uses: actions/download-artifact@v4
with:
name: couchbase-${{ needs.source_abi.outputs.extension_version }}
- uses: actions/download-artifact@v4
with:
name: scripts-${{ needs.source_abi.outputs.extension_version }}
- uses: hendrikmuhs/[email protected]
with:
max-size: 2G
key: ${{ github.job }}-${{ matrix.version }}
- name: Set env variable
run: |
if [ "${{ matrix.version }}" != "unversioned" ]; then
echo "CB_ABI_VERSION=${{ matrix.version }}" >> $GITHUB_ENV
else
echo "Building unversioned extension"
fi
- name: Build
run: |
echo "Building versioned extension: ${CB_ABI_VERSION}"
pecl bundle couchbase-${{ needs.source_abi.outputs.extension_version }}.tgz
(
cd couchbase
phpize
./configure --enable-couchbase
mkdir target
make INSTALL_ROOT="$(realpath target)" install
)
DIST_NAME=couchbase-${{ matrix.version }}-linux-x86_64
mkdir ${DIST_NAME}
cp -av couchbase/LICENSE 90-couchbase.ini couchbase/Couchbase couchbase/GPBMetadata ${DIST_NAME}/
find couchbase/target -name couchbase.so -exec cp -v {} ${DIST_NAME}/ \;
strip --strip-all ${DIST_NAME}/couchbase.so
if [ -n "${CB_ABI_VERSION}" ]; then
echo "Renaming so file to couchbase_${CB_ABI_VERSION}.so"
mv ${DIST_NAME}/couchbase.so ${DIST_NAME}/couchbase_${CB_ABI_VERSION}.so
else
echo "CB_ABI_VERSION not set, keeping couchbase.so"
fi
tar cv ${DIST_NAME}/ | gzip -9 > ${DIST_NAME}.tgz
- uses: actions/upload-artifact@v4
with:
name: couchbase-${{ matrix.version }}-linux-x86_64
path: |
couchbase-*-linux-x86_64.tgz
abi_linux_x86_64_test:
needs:
- source_abi
- abi_linux_build
runs-on: ubuntu-22.04
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: json, mbstring, intl
env:
phpts: nts
- uses: actions/download-artifact@v4
with:
name: couchbase-${{ needs.source_abi.outputs.extension_version }}
- uses: actions/download-artifact@v4
with:
name: scripts-${{ needs.source_abi.outputs.extension_version }}
- uses: actions/download-artifact@v4
with:
path: tests
name: tests-${{ needs.source_abi.outputs.extension_version }}
- uses: actions/download-artifact@v4
with:
name: couchbase-${{ needs.source_abi.outputs.abi_version }}-linux-x86_64
- uses: actions/download-artifact@v4
with:
name: couchbase-${{ needs.source_abi.outputs.alternate_abi_version }}-linux-x86_64
- uses: actions/download-artifact@v4
with:
name: couchbase-unversioned-linux-x86_64
- name: Test
env:
CB_ABI_VERSION: ${{ needs.source_abi.outputs.abi_version }}
run: |
tar xf couchbase-unversioned-linux-x86_64.tgz
tar xf couchbase-${{ needs.source_abi.outputs.abi_version }}-linux-x86_64.tgz
tar xf couchbase-${{ needs.source_abi.outputs.alternate_abi_version }}-linux-x86_64.tgz
TEST_ABI=both ruby ./bin/test.rb -v ${{ needs.source_abi.outputs.abi_version }} -v ${{ needs.source_abi.outputs.alternate_abi_version }} -v unversioned
TEST_ABI=versioned ruby ./bin/test.rb -v ${{ needs.source_abi.outputs.abi_version }}
ruby -e '
file_paths = [
"couchbase-unversioned-linux-x86_64/Couchbase/ExtensionNamespaceResolver.php",
"couchbase-${{ needs.source_abi.outputs.abi_version }}-linux-x86_64/Couchbase/ExtensionNamespaceResolver.php",
"couchbase-${{ needs.source_abi.outputs.alternate_abi_version }}-linux-x86_64/Couchbase/ExtensionNamespaceResolver.php"
]
file_paths.each do |file_name|
text = File.read(file_name)
new_contents = text.gsub("${{ needs.source_abi.outputs.abi_version }}", "${{ needs.source_abi.outputs.alternate_abi_version }}")
File.open(file_name, "w") { |file| file.puts new_contents }
end
'
TEST_ABI=both ruby ./bin/test.rb -v ${{ needs.source_abi.outputs.abi_version }} -v ${{ needs.source_abi.outputs.alternate_abi_version }} -v unversioned
TEST_ABI=versioned ruby ./bin/test.rb -v ${{ needs.source_abi.outputs.alternate_abi_version }}
12 changes: 8 additions & 4 deletions Couchbase/BinaryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function name(): string
*/
public function append(string $id, string $value, ?AppendOptions $options = null): MutationResult
{
$response = Extension\documentAppend(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentAppend';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -107,7 +108,8 @@ public function append(string $id, string $value, ?AppendOptions $options = null
*/
public function prepend(string $id, string $value, ?PrependOptions $options = null): MutationResult
{
$response = Extension\documentPrepend(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentPrepend';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -133,7 +135,8 @@ public function prepend(string $id, string $value, ?PrependOptions $options = nu
*/
public function increment(string $id, ?IncrementOptions $options = null): CounterResult
{
$response = Extension\documentIncrement(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentIncrement';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -158,7 +161,8 @@ public function increment(string $id, ?IncrementOptions $options = null): Counte
*/
public function decrement(string $id, ?DecrementOptions $options = null): CounterResult
{
$response = Extension\documentDecrement(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentDecrement';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down
14 changes: 10 additions & 4 deletions Couchbase/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function __construct(string $name, $core)
{
$this->name = $name;
$this->core = $core;
Extension\openBucket($this->core, $this->name);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\openBucket';
$function($this->core, $this->name);
}

/**
Expand Down Expand Up @@ -128,7 +129,9 @@ public function viewQuery(string $designDoc, string $viewName, ?ViewOptions $opt
$opts = ViewOptions::export($options);
$namespace = $opts["namespace"];

$result = Extension\viewQuery($this->core, $this->name, $designDoc, $viewName, $namespace, $opts);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\viewQuery';

$result = $function($this->core, $this->name, $designDoc, $viewName, $namespace, $opts);

return new ViewResult($result);
}
Expand Down Expand Up @@ -183,7 +186,9 @@ public function ping($services = null, $reportId = null)
if ($reportId != null) {
$options['reportId'] = $reportId;
}
return Extension\ping($this->core, $options);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\ping';

return $function($this->core, $options);
}

/**
Expand All @@ -200,6 +205,7 @@ public function diagnostics(?string $reportId = null)
if ($reportId == null) {
$reportId = uniqid();
}
return Extension\diagnostics($this->core, $reportId);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\diagnostics';
return $function($this->core, $reportId);
}
}
36 changes: 24 additions & 12 deletions Couchbase/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public function __construct(string $connectionString, ClusterOptions $options)
) {
throw new InvalidArgumentException("Please use Cluster::connect() to connect to CNG.");
}
$this->connectionHash = hash("sha256", sprintf("--%s--%s--", $connectionString, $options->authenticatorHash()));
$this->core = Extension\createConnection($this->connectionHash, $connectionString, $options->export());
ExtensionNamespaceResolver::defineExtensionNamespace();
$this->connectionHash = hash("sha256", sprintf("--%s--%s--%s--", $connectionString, $options->authenticatorHash(), COUCHBASE_EXTENSION_NAMESPACE));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\createConnection';
$this->core = $function($this->connectionHash, $connectionString, $options->export());
$this->options = $options;
}

Expand Down Expand Up @@ -136,7 +138,8 @@ function (string $connectionString, ClusterOptions $options) {
*/
public static function notifyFork(string $event)
{
return Extension\notifyFork($event);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\notifyFork';
return $function($event);
}

/**
Expand Down Expand Up @@ -167,7 +170,8 @@ public function bucket(string $name): BucketInterface
*/
public function query(string $statement, ?QueryOptions $options = null): QueryResult
{
$result = Extension\query($this->core, $statement, QueryOptions::export($options));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\query';
$result = $function($this->core, $statement, QueryOptions::export($options));

return new QueryResult($result, QueryOptions::getTranscoder($options));
}
Expand All @@ -186,7 +190,8 @@ public function query(string $statement, ?QueryOptions $options = null): QueryRe
*/
public function analyticsQuery(string $statement, ?AnalyticsOptions $options = null): AnalyticsResult
{
$result = Extension\analyticsQuery($this->core, $statement, AnalyticsOptions::export($options));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\analyticsQuery';
$result = $function($this->core, $statement, AnalyticsOptions::export($options));

return new AnalyticsResult($result, AnalyticsOptions::getTranscoder($options));
}
Expand All @@ -204,7 +209,8 @@ public function analyticsQuery(string $statement, ?AnalyticsOptions $options = n
*/
public function searchQuery(string $indexName, SearchQuery $query, ?SearchOptions $options = null): SearchResult
{
$result = Extension\searchQuery($this->core, $indexName, json_encode($query), SearchOptions::export($options));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\searchQuery';
$result = $function($this->core, $indexName, json_encode($query), SearchOptions::export($options));

return new SearchResult($result);
}
Expand All @@ -230,12 +236,14 @@ public function search(string $indexName, SearchRequest $request, ?SearchOptions
$query = $exportedRequest['searchQuery'];

if (!$exportedRequest['vectorSearch']) {
$result = Extension\searchQuery($this->core, $indexName, json_encode($query), $exportedOptions);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\searchQuery';
$result = $function($this->core, $indexName, json_encode($query), $exportedOptions);
return new SearchResult($result);
}

$vectorSearch = $exportedRequest['vectorSearch'];
$result = Extension\vectorSearch($this->core, $indexName, json_encode($query), json_encode($vectorSearch), $exportedOptions, VectorSearchOptions::export($vectorSearch->options()));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\vectorSearch';
$result = $function($this->core, $indexName, json_encode($query), json_encode($vectorSearch), $exportedOptions, VectorSearchOptions::export($vectorSearch->options()));
return new SearchResult($result);
}

Expand Down Expand Up @@ -318,7 +326,8 @@ public function ping($services = null, $reportId = null)
if ($reportId != null) {
$options['reportId'] = $reportId;
}
return Extension\ping($this->core, $options);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\ping';
return $function($this->core, $options);
}

/**
Expand All @@ -334,7 +343,8 @@ public function diagnostics(?string $reportId = null)
if ($reportId == null) {
$reportId = uniqid();
}
return Extension\diagnostics($this->core, $reportId);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\diagnostics';
return $function($this->core, $reportId);
}

/**
Expand All @@ -359,7 +369,8 @@ public function transactions(?TransactionsConfiguration $config = null): Transac
*/
public function version(string $bucketName): ?string
{
return Extension\clusterVersion($this->core, $bucketName);
$function = COUCHBASE_EXTENSION_NAMESPACE . "\\clusterVersion";
return $function($this->core, $bucketName);
}

/**
Expand All @@ -371,7 +382,8 @@ public function version(string $bucketName): ?string
*/
public function replicasConfiguredFor(string $bucketName): bool
{
return Extension\replicasConfiguredForBucket($this->core, $bucketName);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\replicasConfiguredForBucket';
return $function($this->core, $bucketName);
}

/**
Expand Down
Loading

0 comments on commit 497ccb2

Please sign in to comment.