Skip to content

Commit b9e156b

Browse files
author
jayeshmepani
committed
fix: unignore build scripts in .gitignore
1 parent 3348757 commit b9e156b

7 files changed

Lines changed: 188 additions & 1 deletion

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ __pycache__/
88

99
# Distribution / packaging
1010
.Python
11-
build/
11+
build/*
12+
!build/*.sh
13+
!build/*.ps1
14+
!build/*.py
15+
!build/*.php
1216
develop-eggs/
1317
dist/
1418
downloads/

build/compile-linux.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
DIR="$(cd "$(dirname "$0")" && pwd)"
4+
ROOT_DIR="$(dirname "$DIR")"
5+
6+
ARCH=$(uname -m)
7+
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
8+
TARGET="linux-x64"
9+
else
10+
TARGET="linux-arm64"
11+
fi
12+
13+
echo "Building for $TARGET"
14+
cd "$DIR"
15+
if [ ! -d "libpostal" ]; then
16+
git clone https://github.com/openvenues/libpostal.git
17+
fi
18+
cd libpostal
19+
./bootstrap.sh
20+
./configure --disable-data-download
21+
make -j4
22+
23+
mkdir -p "$ROOT_DIR/postalkit/libs/$TARGET"
24+
cp src/.libs/libpostal.so "$ROOT_DIR/postalkit/libs/$TARGET/"
25+
echo "Success: Compiled to $ROOT_DIR/postalkit/libs/$TARGET/libpostal.so"

build/compile-macos.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
DIR="$(cd "$(dirname "$0")" && pwd)"
4+
ROOT_DIR="$(dirname "$DIR")"
5+
6+
ARCH=$(uname -m)
7+
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
8+
TARGET="macos-x64"
9+
else
10+
TARGET="macos-arm64"
11+
fi
12+
13+
echo "Building for $TARGET"
14+
cd "$DIR"
15+
if [ ! -d "libpostal" ]; then
16+
git clone https://github.com/openvenues/libpostal.git
17+
fi
18+
cd libpostal
19+
./bootstrap.sh
20+
./configure --disable-data-download
21+
make -j4
22+
23+
mkdir -p "$ROOT_DIR/postalkit/libs/$TARGET"
24+
cp src/.libs/libpostal.dylib "$ROOT_DIR/postalkit/libs/$TARGET/"
25+
echo "Success: Compiled to $ROOT_DIR/postalkit/libs/$TARGET/libpostal.dylib"

build/compile-windows.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$ErrorActionPreference = "Stop"
2+
$DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
3+
$ROOT_DIR = Split-Path -Parent $DIR
4+
$TARGET = "windows-x64"
5+
6+
Write-Host "Building for $TARGET"
7+
Set-Location $DIR
8+
if (-not (Test-Path "libpostal")) {
9+
git clone https://github.com/openvenues/libpostal.git
10+
}
11+
Set-Location "libpostal"
12+
Copy-Item -Recurse -Force windows\* .\
13+
bash ./bootstrap.sh
14+
bash ./configure --disable-data-download
15+
make -j4
16+
17+
$TARGET_DIR = "$ROOT_DIR\postalkit\libs\$TARGET"
18+
if (-not (Test-Path $TARGET_DIR)) {
19+
New-Item -ItemType Directory -Force -Path $TARGET_DIR
20+
}
21+
Copy-Item src\.libs\libpostal-1.dll "$TARGET_DIR\postal.dll" -Force
22+
Write-Host "Success: Compiled to $TARGET_DIR\postal.dll"

build/compile.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
DIR="$(cd "$(dirname "$0")" && pwd)"
4+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
5+
6+
if [[ "$OS" == *"linux"* ]]; then
7+
bash "$DIR/compile-linux.sh"
8+
elif [[ "$OS" == *"darwin"* ]]; then
9+
bash "$DIR/compile-macos.sh"
10+
else
11+
echo "Unsupported OS. Use compile-windows.ps1 for Windows."
12+
exit 1
13+
fi

build/fetch-prebuilt.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$postalkitVersion = "v0.1.0";
5+
$repoUrl = "https://github.com/jayeshmepani/libpostal-ffi-python/releases/download/{$postalkitVersion}";
6+
7+
$targets = [
8+
'linux-x64' => 'libpostal-linux-x64.tar.gz',
9+
'linux-arm64' => 'libpostal-linux-arm64.tar.gz',
10+
'macos-x64' => 'libpostal-macos-x64.tar.gz',
11+
'macos-arm64' => 'libpostal-macos-arm64.tar.gz',
12+
'windows-x64' => 'libpostal-windows-x64.zip',
13+
];
14+
15+
$libsDir = dirname(__DIR__) . '/postalkit/libs';
16+
17+
foreach ($targets as $target => $filename) {
18+
$targetDir = "{$libsDir}/{$target}";
19+
if (!is_dir($targetDir)) {
20+
mkdir($targetDir, 0777, true);
21+
}
22+
23+
$url = "{$repoUrl}/{$filename}";
24+
$dest = "{$targetDir}/{$filename}";
25+
26+
echo "Downloading {$url}...\n";
27+
$content = file_get_contents($url);
28+
if ($content === false) {
29+
echo "Failed to download {$url}. Skipping.\n";
30+
continue;
31+
}
32+
33+
file_put_contents($dest, $content);
34+
35+
echo "Extracting {$dest}...\n";
36+
if (str_ends_with($filename, '.zip')) {
37+
$zip = new ZipArchive;
38+
if ($zip->open($dest) === TRUE) {
39+
$zip->extractTo($targetDir);
40+
$zip->close();
41+
} else {
42+
echo "Failed to extract zip.\n";
43+
}
44+
} else {
45+
exec("tar -xzf " . escapeshellarg($dest) . " -C " . escapeshellarg($targetDir));
46+
}
47+
48+
unlink($dest);
49+
echo "Successfully setup {$target}\n";
50+
}

build/fetch-prebuilt.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import urllib.request
2+
import tarfile
3+
import zipfile
4+
import os
5+
import sys
6+
from pathlib import Path
7+
8+
POSTALKIT_VERSION = "v0.1.0"
9+
REPO_URL = f"https://github.com/jayeshmepani/libpostal-ffi-python/releases/download/{POSTALKIT_VERSION}"
10+
11+
TARGETS = {
12+
'linux-x64': 'libpostal-linux-x64.tar.gz',
13+
'linux-arm64': 'libpostal-linux-arm64.tar.gz',
14+
'macos-x64': 'libpostal-macos-x64.tar.gz',
15+
'macos-arm64': 'libpostal-macos-arm64.tar.gz',
16+
'windows-x64': 'libpostal-windows-x64.zip',
17+
}
18+
19+
def fetch_prebuilt():
20+
libs_dir = Path(__file__).parent.parent / "postalkit" / "libs"
21+
22+
for target, filename in TARGETS.items():
23+
target_dir = libs_dir / target
24+
target_dir.mkdir(parents=True, exist_ok=True)
25+
26+
url = f"{REPO_URL}/{filename}"
27+
dest = target_dir / filename
28+
29+
print(f"Downloading {url}...")
30+
try:
31+
urllib.request.urlretrieve(url, dest)
32+
except Exception as e:
33+
print(f"Failed to download {url}: {e}")
34+
continue
35+
36+
print(f"Extracting {dest}...")
37+
if filename.endswith('.zip'):
38+
with zipfile.ZipFile(dest, 'r') as zip_ref:
39+
zip_ref.extractall(target_dir)
40+
else:
41+
with tarfile.open(dest, "r:gz") as tar:
42+
tar.extractall(path=target_dir)
43+
44+
os.remove(dest)
45+
print(f"Successfully setup {target}")
46+
47+
if __name__ == "__main__":
48+
fetch_prebuilt()

0 commit comments

Comments
 (0)