-
-
Notifications
You must be signed in to change notification settings - Fork 48
181 lines (149 loc) · 5.65 KB
/
build-widechar.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Build widecharwidth library
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch: # Allow manual triggering
jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
include:
- os: ubuntu-latest
output_name: libwidecharwidth.so
lib_dir: linux
- os: macos-latest
output_name: libwidecharwidth.dylib
lib_dir: macos
- os: windows-latest
output_name: widecharwidth.dll
lib_dir: windows
steps:
- name: Checkout main repository
uses: actions/checkout@v4
- name: Create libs directory structure
run: mkdir -p libs/${{ matrix.lib_dir }}
- name: Checkout widecharwidth repository
uses: actions/checkout@v4
with:
repository: ridiculousfish/widecharwidth
path: widecharwidth-src
- name: Set up GCC (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential
- name: Set up GCC (macOS)
if: runner.os == 'macOS'
run: |
brew install gcc
- name: Set up MinGW (Windows)
if: runner.os == 'Windows'
run: |
choco install mingw --version=8.1.0 -y
# Create a simple C file that includes the C header
- name: Create C wrapper file
shell: bash
run: |
echo '#include "widecharwidth-src/widechar_width_c.h"' > wrapper.c
echo '' >> wrapper.c
echo '// The function is already available from the header' >> wrapper.c
echo '// We just need to compile it into a shared library' >> wrapper.c
- name: Build shared library (Linux)
if: runner.os == 'Linux'
run: |
gcc -shared -fPIC -o ${{ matrix.output_name }} wrapper.c
- name: Build shared library (macOS)
if: runner.os == 'macOS'
run: |
gcc -shared -fPIC -o ${{ matrix.output_name }} wrapper.c
- name: Build shared library (Windows)
if: runner.os == 'Windows'
run: |
gcc -shared -o ${{ matrix.output_name }} wrapper.c
- name: Move library to libs directory
run: |
mv ${{ matrix.output_name }} libs/${{ matrix.lib_dir }}/
- name: Upload library artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.lib_dir }}-${{ matrix.output_name }}
path: libs/${{ matrix.lib_dir }}/${{ matrix.output_name }}
# Combine all libraries and commit back to the repo
commit:
name: Commit Libraries to Repository
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create libs directory
run: mkdir -p libs/{linux,macos,windows}
- name: Download Linux library
uses: actions/download-artifact@v4
with:
name: linux-libwidecharwidth.so
path: libs/linux
- name: Download macOS library
uses: actions/download-artifact@v4
with:
name: macos-libwidecharwidth.dylib
path: libs/macos
- name: Download Windows library
uses: actions/download-artifact@v4
with:
name: windows-widecharwidth.dll
path: libs/windows
- name: List contents of libs directory
run: |
ls -la libs/
ls -la libs/linux/ || echo "Linux library missing"
ls -la libs/macos/ || echo "macOS library missing"
ls -la libs/windows/ || echo "Windows library missing"
- name: Create README for libs directory
run: |
cat > libs/README.md << 'EOL'
# Widecharwidth Library Binaries
This directory contains pre-compiled binaries of the [widecharwidth](https://github.com/ridiculousfish/widecharwidth) library for:
- Linux: `linux/libwidecharwidth.so`
- macOS: `macos/libwidecharwidth.dylib`
- Windows: `windows/widecharwidth.dll`
These libraries are automatically compiled by GitHub Actions from the original source code.
## Usage with PHP FFI
```php
<?php
// Load the appropriate library based on the OS
if (PHP_OS_FAMILY === 'Darwin') {
$lib = __DIR__ . '/libs/macos/libwidecharwidth.dylib';
} elseif (PHP_OS_FAMILY === 'Windows') {
$lib = __DIR__ . '/libs/windows/widecharwidth.dll';
} else {
$lib = __DIR__ . '/libs/linux/libwidecharwidth.so';
}
// Define the function signature
$ffi = FFI::cdef("int widechar_wcwidth(unsigned int code_point);", $lib);
// Example usage - handle special return values appropriately
$width = $ffi->widechar_wcwidth(0x1F600); // 😀
echo "Width: " . ($width > 0 ? $width : 0) . "\n"; // Convert negative values to 0
```
EOL
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Commit files
run: |
git add libs/
git commit -m "Update widecharwidth libraries" -m "Automatically compiled by GitHub Actions" || echo "No changes to commit"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}