Skip to content

Commit 1736879

Browse files
committed
Add PIE extension support via separate repository
- Update release.sh to automate extension repo releases - Clone extension repo to .ext directory - Update submodule reference after main release - Create matching release in extension repo - Include safety checks and error handling - Create php_maxminddb-{version}-src.tgz from submodule ext/ directory - Upload as GitHub release asset - Update README.md to promote PIE as recommended installation method - Add maxmind-db/reader-ext to composer.json suggest section - Add .ext to .gitignore - Document implementation plan in plan.md References: - php/pie#39
1 parent 62cdd95 commit 1736879

File tree

4 files changed

+192
-6
lines changed

4 files changed

+192
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.sublime-*
77
*.sw?
88
.deps
9+
.ext
910
.gh-pages
1011
/.idea
1112
/.php-cs-fixer.cache

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@
55
This is the PHP API for reading MaxMind DB files. MaxMind DB is a binary file
66
format that stores data indexed by IP address subnets (IPv4 or IPv6).
77

8-
## Installation (Composer) ##
8+
## Installation ##
99

10-
We recommend installing this package with [Composer](https://getcomposer.org/).
10+
### C Extension (Recommended for Performance) ###
11+
12+
For significantly faster IP lookups, we recommend installing the C extension via
13+
[PIE](https://github.com/php/pie):
14+
15+
```bash
16+
pie install maxmind-db/reader-ext
17+
```
18+
19+
The C extension requires the [libmaxminddb](https://github.com/maxmind/libmaxminddb)
20+
C library. See the [installation instructions](https://github.com/maxmind/MaxMind-DB-Reader-php-ext#prerequisites)
21+
for your platform.
22+
23+
### Pure PHP (No Compilation Required) ###
24+
25+
If you prefer not to compile a C extension or need maximum portability, you can
26+
install the pure PHP implementation with [Composer](https://getcomposer.org/).
1127

1228
### Download Composer ###
1329

@@ -108,18 +124,31 @@ MaxMind provides an optional C extension that is a drop-in replacement for
108124
Reader API as described above and install the extension as described below. If
109125
you are using an autoloader, no changes to your code should be necessary.
110126

111-
### Installing Extension ###
127+
### Installing Extension via PIE (Recommended) ###
128+
129+
We recommend installing the extension via [PIE](https://github.com/php/pie):
130+
131+
```bash
132+
pie install maxmind-db/reader-ext
133+
```
134+
135+
See the [extension repository](https://github.com/maxmind/MaxMind-DB-Reader-php-ext#prerequisites)
136+
for prerequisites including libmaxminddb installation instructions.
137+
138+
### Installing Extension via PECL (Legacy) ###
112139

113140
First install [libmaxminddb](https://github.com/maxmind/libmaxminddb) as
114141
described in its [README.md
115142
file](https://github.com/maxmind/libmaxminddb/blob/main/README.md#installing-from-a-tarball).
116143
After successfully installing libmaxmindb, you may install the extension
117-
from [pecl](https://pecl.php.net/package/maxminddb):
144+
from [PECL](https://pecl.php.net/package/maxminddb):
118145

119146
```
120147
pecl install maxminddb
121148
```
122149

150+
### Installing Extension from Source ###
151+
123152
Alternatively, you may install it from the source. To do so, run the following
124153
commands from the top-level directory of this distribution:
125154

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"suggest": {
1919
"ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
2020
"ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
21-
"ext-maxminddb": "A C-based database decoder that provides significantly faster lookups"
21+
"ext-maxminddb": "A C-based database decoder that provides significantly faster lookups",
22+
"maxmind-db/reader-ext": "C extension for significantly faster IP lookups (install via PIE: pie install maxmind-db/reader-ext)"
2223
},
2324
"conflict": {
2425
"ext-maxminddb": "<1.11.1 || >=2.0.0"

dev-bin/release.sh

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ echo "$notes"
7070

7171
pecl package
7272

73+
package="maxminddb-$version.tgz"
74+
7375
read -p "Push to origin? (y/n) " should_push
7476

7577
if [ "$should_push" != "y" ]; then
@@ -83,4 +85,157 @@ git push
8385

8486
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag"
8587

86-
echo "Upload PECL package to pecl.php.net!"
88+
# =============================================================================
89+
# EXTENSION REPOSITORY RELEASE AUTOMATION
90+
# =============================================================================
91+
92+
ext_repo_dir=".ext"
93+
ext_repo_url="[email protected]:maxmind/MaxMind-DB-Reader-php-ext.git"
94+
95+
echo ""
96+
echo "==================================================================="
97+
echo "UPDATING EXTENSION REPOSITORY"
98+
echo "==================================================================="
99+
100+
# Check if extension repository exists locally
101+
if [ ! -d "$ext_repo_dir" ]; then
102+
echo "Extension repository not found at: $ext_repo_dir"
103+
echo "Cloning extension repository..."
104+
git clone --recurse-submodules "$ext_repo_url" "$ext_repo_dir"
105+
106+
if [ $? -ne 0 ]; then
107+
echo "ERROR: Failed to clone extension repository"
108+
echo "Please clone manually: git clone --recurse-submodules $ext_repo_url $ext_repo_dir"
109+
exit 1
110+
fi
111+
fi
112+
113+
# Navigate to extension repository
114+
pushd "$ext_repo_dir" > /dev/null
115+
116+
# Safety check: ensure working directory is clean
117+
if [ -n "$(git status --porcelain)" ]; then
118+
echo "ERROR: Extension repository has uncommitted changes"
119+
echo "Please commit or stash changes in: $ext_repo_dir"
120+
popd > /dev/null
121+
exit 1
122+
fi
123+
124+
# Ensure we're on main branch
125+
current_branch=$(git rev-parse --abbrev-ref HEAD)
126+
if [ "$current_branch" != "main" ]; then
127+
echo "Switching to main branch..."
128+
git checkout main
129+
fi
130+
131+
# Pull latest changes
132+
echo "Pulling latest changes from origin..."
133+
git pull origin main
134+
135+
# Update submodule to the new tag
136+
echo "Updating submodule to $tag..."
137+
cd MaxMind-DB-Reader-php
138+
git fetch --tags origin
139+
git checkout "$tag"
140+
141+
if [ $? -ne 0 ]; then
142+
echo "ERROR: Failed to checkout tag $tag in submodule"
143+
popd > /dev/null
144+
exit 1
145+
fi
146+
147+
cd ..
148+
149+
# Stage submodule update
150+
git add MaxMind-DB-Reader-php
151+
152+
# Check if there are actual changes
153+
if [ -z "$(git status --porcelain)" ]; then
154+
echo "No changes needed in extension repository (already at $tag)"
155+
popd > /dev/null
156+
echo "Extension repository is up to date"
157+
else
158+
# Commit submodule update
159+
echo "Committing submodule update..."
160+
git commit -m "Update to MaxMind-DB-Reader-php $version
161+
162+
This updates the submodule reference to track the $tag release.
163+
164+
Release notes from main repository:
165+
$notes"
166+
167+
# Push changes
168+
echo "Pushing to origin..."
169+
git push origin main
170+
171+
if [ $? -ne 0 ]; then
172+
echo "ERROR: Failed to push to extension repository"
173+
popd > /dev/null
174+
exit 1
175+
fi
176+
177+
# Create pre-packaged source tarball for PIE
178+
# PIE needs this because it doesn't handle git submodules automatically
179+
echo "Creating pre-packaged source tarball for PIE..."
180+
pie_tarball="maxminddb-${tag}.tgz"
181+
182+
# Create tarball with files at root level (PIE requirement)
183+
# Note: naming must be {extension-name}-v{version}.tgz
184+
pushd MaxMind-DB-Reader-php/ext > /dev/null
185+
tar -czf "../../$pie_tarball" *
186+
popd > /dev/null
187+
188+
if [ ! -f "$pie_tarball" ]; then
189+
echo "ERROR: Failed to create source tarball"
190+
popd > /dev/null
191+
exit 1
192+
fi
193+
194+
echo "Created $pie_tarball"
195+
196+
# Create corresponding release in extension repo with same tag
197+
echo "Creating release $tag in extension repository..."
198+
gh release create "$tag" \
199+
--repo maxmind/MaxMind-DB-Reader-php-ext \
200+
--title "$version" \
201+
--notes "Extension release for MaxMind-DB-Reader-php $version
202+
203+
This release tracks the $tag tag of the main repository.
204+
205+
## Release notes from main repository
206+
207+
$notes" \
208+
"$pie_tarball"
209+
210+
if [ $? -ne 0 ]; then
211+
echo "ERROR: Failed to create release in extension repository"
212+
echo "You may need to create it manually at:"
213+
echo "https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/new?tag=$tag"
214+
popd > /dev/null
215+
exit 1
216+
fi
217+
218+
# Clean up tarball
219+
rm -f "$pie_tarball"
220+
221+
echo ""
222+
echo "✓ Extension repository updated successfully!"
223+
echo "✓ Release created: https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/tag/$tag"
224+
echo "✓ Pre-packaged source uploaded: $pie_tarball"
225+
fi
226+
227+
popd > /dev/null
228+
229+
echo ""
230+
echo "==================================================================="
231+
echo "RELEASE COMPLETE"
232+
echo "==================================================================="
233+
echo ""
234+
echo "Main repository: https://github.com/maxmind/MaxMind-DB-Reader-php/releases/tag/$tag"
235+
echo "Extension repository: https://github.com/maxmind/MaxMind-DB-Reader-php-ext/releases/tag/$tag"
236+
echo ""
237+
echo "Action items:"
238+
echo "1. Upload PECL package to pecl.php.net: https://pecl.php.net/package-new.php"
239+
echo " File: $package"
240+
echo "2. Verify PIE installation: pie install maxmind-db/reader-ext:^$version"
241+
echo "3. Announce release"

0 commit comments

Comments
 (0)