Skip to content

Commit

Permalink
Add zts support on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Dec 24, 2023
1 parent 97e0a97 commit 201dd6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ On GitHub Actions you can assign the `setup-php` step an `id`, you can use the s

#### `phpts` (optional)

- Specify to set up a thread-safe build of PHP on Linux and Windows.
- Specify to set up a thread-safe build of PHP.
- Accepts `nts` for non-thread-safe and `zts` or `ts` for thread-safe.
- By default, it is set to `nts`.
- See [thread safe setup](#thread-safe-setup) for more info.
Expand Down Expand Up @@ -571,16 +571,14 @@ steps:

### Thread Safe Setup

> Set up `TS` or `NTS` PHP on `Linux` and `Windows`.
> Set up `TS` or `NTS` PHP.
- `NTS` versions are set up by default.
- On `macOS` only `NTS` versions are supported currently.
- On `Linux` and `Windows` both `TS` and `NTS` versions are supported.

```yaml
jobs:
run:
runs-on: [ubuntu-latest, windows-latest]
runs-on: [ubuntu-latest, windows-latest, macos-latest]
name: Setup PHP TS
steps:
- name: Setup PHP
Expand Down
24 changes: 21 additions & 3 deletions src/scripts/darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,21 @@ add_brew_extension() {
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
brew_opts=(-f)
add_brew_tap "$php_tap"
add_brew_tap "$ext_tap"
if [ "${ts:?}" = "zts" ]; then
brew_opts=(-sf)
suffix="$(get_php_formula_suffix)"
abstract_path="$tap_dir"/"$ext_tap"/Abstract/abstract-php-extension.rb
if [ -f "$abstract_path" ]; then
grep -q zts "$abstract_path" || sed -i '' "s/php@${version}/php@${version}$suffix/" "$abstract_path"
fi
fi
sudo mv "$tap_dir"/"$ext_tap"/.github/deps/"$formula"/* "${core_repo:?}/Formula/" 2>/dev/null || true
update_dependencies >/dev/null 2>&1
disable_dependency_extensions "$extension" >/dev/null 2>&1
(brew install -f "$ext_tap/$formula@$version" >/dev/null 2>&1 && copy_brew_extensions "$formula") || pecl_install "$extension" >/dev/null 2>&1
(brew install "${brew_opts[@]}" "$ext_tap/$formula@$version" >/dev/null 2>&1 && copy_brew_extensions "$formula") || pecl_install "$extension" >/dev/null 2>&1
add_extension_log "$extension" "Installed and enabled"
fi
}
Expand Down Expand Up @@ -181,15 +190,24 @@ add_php() {
existing_version=$2
add_brew_tap "$php_tap"
update_dependencies
[ "${debug:?}" = "debug" ] && php_formula="$php_formula-debug"
if [ "$existing_version" != "false" ]; then
suffix="$(get_php_formula_suffix)"
php_formula="shivammathur/php/php@$version$suffix"
if [[ "$existing_version" != "false" && -z "$suffix" ]]; then
([ "$action" = "upgrade" ] && brew upgrade -f "$php_formula") || brew unlink "$php_formula"
else
brew install -f "$php_formula"
fi
brew link --force --overwrite "$php_formula"
}

# Function to get formula suffix
get_php_formula_suffix() {
local suffix
[ "${debug:?}" = "debug" ] && suffix="-debug"
[ "${ts:?}" = "zts" ] && suffix="$suffix-zts"
echo "$suffix"
}

# Function to get extra version.
php_extra_version() {
php_formula_file="$tap_dir"/"$php_tap"/Formula/php@"$version".rb
Expand Down

0 comments on commit 201dd6c

Please sign in to comment.