Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/release-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
build-and-test:
uses: "./.github/workflows/wasix-pr.yaml"
needs: version-check
secrets:
SENDMAIL_DEFAULT_USERNAME: ${{ secrets.SENDMAIL_DEFAULT_USERNAME }}
SENDMAIL_DEFAULT_PASSWORD: ${{ secrets.SENDMAIL_DEFAULT_PASSWORD }}

release:
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
build-and-test:
uses: "./.github/workflows/wasix-pr.yaml"
needs: version-check
secrets:
SENDMAIL_DEFAULT_USERNAME: ${{ secrets.SENDMAIL_DEFAULT_USERNAME }}
SENDMAIL_DEFAULT_PASSWORD: ${{ secrets.SENDMAIL_DEFAULT_PASSWORD }}

release:
runs-on: ubuntu-latest
Expand Down
67 changes: 18 additions & 49 deletions .github/workflows/wasix-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ name: WASIX build and test

on:
workflow_call:
secrets:
SENDMAIL_DEFAULT_USERNAME:
required: true
SENDMAIL_DEFAULT_PASSWORD:
required: true
pull_request:
branches:
- "*-wasix"

permissions:
contents: read

jobs:
build-and-test:
name: Build and Test
Expand All @@ -35,65 +33,41 @@ jobs:
- name: OS Setup (Ubuntu)
run: |
sudo apt-get update
sudo apt-get install -y build-essential wabt re2c
sudo apt-get install -y build-essential wabt re2c curl xz-utils tar
npm i -g pnpm concurrently

wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 21

wget https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-x86_64-linux.tar.gz
tar -xzf binaryen-version_123-x86_64-linux.tar.gz
sudo cp binaryen-version_123/bin/* /usr/bin/

sudo rm -f /usr/bin/clang
sudo rm -f /usr/bin/clang++
sudo ln -s /usr/bin/clang-21 /usr/bin/clang
sudo ln -s /usr/bin/clang++-21 /usr/bin/clang++
sudo ln -s /usr/bin/llvm-ar-21 /usr/bin/llvm-ar
sudo ln -s /usr/bin/llvm-nm-21 /usr/bin/llvm-nm
sudo ln -s /usr/bin/llvm-ranlib-21 /usr/bin/llvm-ranlib
sudo ln -s /usr/bin/llvm-objdump-21 /usr/bin/llvm-objdump
- name: Install wasixcc
uses: wasix-org/wasixcc@main
Comment thread
zebreus marked this conversation as resolved.
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
sysroot-tag: v2026-02-16.1
version: v0.3.0

- name: Tool Versions
run: |
echo clang
clang -v
echo wasixcc
wasixcc -v
echo '####################'
echo llvm-ar
llvm-ar -V
echo wasixar
wasixar -V
echo '####################'
echo llvm-nm
llvm-nm -V
echo wasixnm
wasixnm -V
echo '####################'
echo llvm-ranlib
llvm-ranlib -V
echo wasixranlib
wasixranlib -V
echo '####################'
echo wasm-opt
wasm-opt --version
echo '####################'
echo wasm-strip
wasm-strip --version

- name: Download wasix-libc
uses: dsaltares/fetch-gh-release-asset@1.1.2
with:
repo: wasix-org/wasix-libc
file: sysroot-eh.tar.gz
target: sysroot/wasix-libc.tar.gz

- name: Unpack wasix-libc
run: |
cd sysroot
tar xzf wasix-libc.tar.gz
sudo mkdir -p /usr/lib/llvm-21/lib/clang/21/lib/wasm32-unknown-wasi
sudo cp wasix-sysroot-eh/sysroot/lib/wasm32-wasi/libclang_rt.builtins-wasm32.a \
/usr/lib/llvm-21/lib/clang/21/lib/wasm32-unknown-wasi/libclang_rt.builtins.a

- name: Build
env:
SENDMAIL_DEFAULT_USERNAME: ${{ secrets.SENDMAIL_DEFAULT_USERNAME }}
SENDMAIL_DEFAULT_PASSWORD: ${{ secrets.SENDMAIL_DEFAULT_PASSWORD }}
run: |
export SYSROOT=$(pwd)/sysroot/wasix-sysroot-eh/sysroot
export PHP_WASIX_DEPS=$(pwd)/php-wasix-deps
Expand All @@ -104,11 +78,6 @@ jobs:
uses: wasmerio/setup-wasmer@v3.1

- name: Run WASIX tests
env:
MAIL_USERNAME: ${{ secrets.SENDMAIL_DEFAULT_USERNAME }}
MAIL_PASSWORD: ${{ secrets.SENDMAIL_DEFAULT_PASSWORD }}
MAIL_HOST: smtp.mailgun.org
MAIL_PORT: 587
run: |
cd php
bash wasix-test-start-containers.sh
Expand Down
2 changes: 1 addition & 1 deletion build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ AC_DEFUN([PHP_REQUIRE_CXX],[
if test -z "$php_cxx_done"; then
AC_PROG_CXX
AC_PROG_CXXCPP
PHP_ADD_LIBRARY(stdc++)
PHP_ADD_LIBRARY(c++)
Comment thread
zebreus marked this conversation as resolved.
php_cxx_done=yes
fi
])
Expand Down
9 changes: 0 additions & 9 deletions ext/standard/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,6 @@ else
AC_MSG_RESULT(no)
fi

dnl
dnl Include libwasix_sendmail when building to WASIX
dnl
if test "$ac_cv_have_decl___wasi__" == "yes"; then
if test -n "$WASIX_SENDMAIL_LIBS"; then
PHP_EVAL_LIBLINE($WASIX_SENDMAIL_LIBS)
fi
fi

dnl
dnl Whether to enable 64-bit long ints when building to WASIX;
dnl wasm32 uses 32-bit pointers but supports 64-bit int operations.
Expand Down
122 changes: 1 addition & 121 deletions ext/standard/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,21 +407,6 @@ static int php_mail_detect_multiple_crlf(const char *hdr) {
return 0;
}

// The Rust source for this function is in https://github.com/wasix-org/php-wasix-sendmail
// As for why the code is in rust, well, because it's much easier to have it there than in C.
#ifdef __wasi__
int wasix_sendmail(const char *host, uint16_t port, const char* username, const char* password, char **error_message,
const char *headers, const char *subject, const char *mail_from, const char *mail_to, const char *data);
#endif

#ifdef __wasi__
#define NO_REPLY "no-reply@"
#define MAIL_USERNAME "MAIL_USERNAME"
#define MAIL_PASSWORD "MAIL_PASSWORD"
#define MAIL_HOST "MAIL_HOST"
#define MAIL_PORT "MAIL_PORT"
#define MAIL_FROM_ADDRESS "MAIL_FROM_ADDRESS"
#endif

/* {{{ php_mail */
PHPAPI int php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd)
Expand All @@ -430,17 +415,7 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
int tsm_err;
char *tsm_errmsg = NULL;
#endif
#ifdef __wasi__
int wasix_sendmail_result;
char *wasi_errmsg = NULL;
char *sendmail_from = NULL;
bool sendmail_from_alloc = false;
char *smtp = NULL;
char *username = NULL;
char *password = NULL;
int smtp_port;
#endif
FILE * sendmail;
FILE *sendmail;
int ret;
char *sendmail_path = INI_STR("sendmail_path");
char *sendmail_cmd = NULL;
Expand Down Expand Up @@ -515,101 +490,6 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
MAIL_RET(0);
}

#ifdef __wasi__
// Always prioritize the INI settings over the environment variables
smtp = INI_STR("SMTP");
if (!smtp) {
smtp = getenv(MAIL_HOST);
}

username = INI_STR("sendmail_username");
if (!username) {
username = getenv(MAIL_USERNAME);
}

password = INI_STR("sendmail_password");
if (!password) {
password = getenv(MAIL_PASSWORD);
}

smtp_port = INI_INT("smtp_port");
if (!smtp_port) {
char* port = getenv(MAIL_PORT);
if (port) {
smtp_port = atoi(port);
}
}
if (!smtp_port) {
smtp_port = 587; // Default SMTP port
}

sendmail_from = INI_STR("sendmail_from");
if (!sendmail_from) {
sendmail_from = getenv(MAIL_FROM_ADDRESS);
}
if (!sendmail_from) {
// Construct a from address from the host name
zval *server_array, *host;

if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY ||
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) &&
(server_array = &PG(http_globals)[TRACK_VARS_SERVER]) &&
(host = zend_hash_str_find(Z_ARRVAL_P(server_array), "HTTP_HOST", sizeof("HTTP_HOST") - 1)) &&
Z_TYPE_P(host) == IS_STRING)
{
char* host_str = Z_STRVAL_P(host);

// if the string has this format:
//
// host:port
//
// only copy the host part. if not, copy the whole string
char* colon_ptr = strchr(host_str, ':');
size_t host_len = colon_ptr ? colon_ptr - host_str : strlen(host_str);
size_t sendmail_from_len = strlen(NO_REPLY) + host_len + 1;

sendmail_from = malloc(sendmail_from_len);

if (sendmail_from == NULL) {
fprintf(stderr, "Memory allocation failed\n");
MAIL_RET(0);
}

sendmail_from_alloc = true;

strcpy(sendmail_from, NO_REPLY);
strncpy(sendmail_from + strlen(NO_REPLY), host_str, host_len);
sendmail_from[strlen(NO_REPLY) + host_len] = '\0';
}
}

if (!username || !password || !smtp || !sendmail_from) {
php_error(E_WARNING, "Username, password, or smtp server for mail not provided");
MAIL_RET(0);
}

wasix_sendmail_result = wasix_sendmail(
smtp,
smtp_port,
username,
password,
&wasi_errmsg, hdr, subject, sendmail_from, to, message);

if (sendmail_from_alloc)
free(sendmail_from);

if (wasix_sendmail_result == FAILURE)
{
if (wasi_errmsg) {
php_error(E_WARNING, "%s", wasi_errmsg);
// Error strings live in static data section of libwasix-sendmail.a, no need to free
}
MAIL_RET(0);
} else {
MAIL_RET(1);
}
#endif

if (!sendmail_path) {
#ifdef PHP_WIN32
/* handle old style win smtp sending */
Expand Down
2 changes: 0 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,6 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("sendmail_username", NULL, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("sendmail_password", NULL, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
Expand Down
11 changes: 0 additions & 11 deletions wasix-build.sh

This file was deleted.

31 changes: 12 additions & 19 deletions wasix-configure-eh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ if [ -f Makefile ]; then
make clean
fi

SYSROOT=${SYSROOT:-"/home/arshia/repos/wasmer/wasix-libc/sysroot32-eh"}
PHP_WASIX_DEPS=${PHP_WASIX_DEPS:-"../php-wasix-deps"}

export \
Expand Down Expand Up @@ -41,26 +40,20 @@ export \
ONIG_LIBS="-lonig" \
IM_IMAGEMAGICK_CFLAGS="-I$PHP_WASIX_DEPS/include/ImageMagick -DIM_MAGICKWAND_HEADER_STYLE_SEVEN -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32" \
IM_IMAGEMAGICK_LIBS="-lMagickCore-7.Q16HDRI -lMagickWand-7.Q16HDRI -ltiff" \
WASIX_SENDMAIL_LIBS="-lwasix_sendmail" \
PHP_BUILD_SYSTEM="clang(WASIX+WasmEH)" \
PHP_EXTRA_INCLUDES="" \
PHP_IPV6="yes" \
RANLIB=llvm-ranlib-21 \
AR=llvm-ar-21 \
NM=llvm-nm-21 \
CC="clang-21 --target=wasm32-wasi --sysroot=$SYSROOT" \
CXX="clang++-21 --target=wasm32-wasi --sysroot=$SYSROOT" \
CFLAGS="-matomics -mbulk-memory -mmutable-globals -pthread -mthread-model posix -ftls-model=local-exec \
-fno-trapping-math -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS \
-g -flto -O2 -fwasm-exceptions" \
CXXFLAGS="-matomics -mbulk-memory -mmutable-globals -pthread -mthread-model posix -ftls-model=local-exec \
-fno-trapping-math -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS \
-g -flto -O2 -fwasm-exceptions -mllvm --wasm-enable-eh" \
LIBS="-Wl,--shared-memory -Wl,--max-memory=4294967296 -Wl,--import-memory -Wl,--export-dynamic \
-Wl,--export=__heap_base -Wl,--export=__stack_pointer -Wl,--export=__data_end -Wl,--export=__wasm_init_tls \
-Wl,--export=__wasm_signal -Wl,--export=__tls_size -Wl,--export=__tls_align -Wl,--export=__tls_base \
-lwasi-emulated-mman -flto -g -Wl,-z,stack-size=8388608 -Wl,--error-limit=0 -L$PHP_WASIX_DEPS/lib-eh -v \
--no-wasm-opt -Wl,-mllvm,--wasm-enable-sjlj -Wl,-mllvm,--wasm-enable-eh -Wl,-lunwind"
RANLIB="wasixranlib" \
AR="wasixar" \
NM="wasixnm" \
CC="wasixcc" \
CXX="wasixcc++" \
CFLAGS="-g -flto -O2" \
Comment thread
zebreus marked this conversation as resolved.
CXXFLAGS="-g -flto -O2" \
Comment thread
Arshia001 marked this conversation as resolved.
LIBS="-L$PHP_WASIX_DEPS/lib-eh --no-wasm-opt" \
WASIXCC_INCLUDE_CPP_SYMBOLS="yes" \
WASIXCC_WASM_EXCEPTIONS="yes" \
PROG_SENDMAIL="/usr/bin/sendmail"

./buildconf --force

Expand All @@ -70,7 +63,7 @@ export \
--with-valgrind=no --with-pcre-jit=no --with-iconv --disable-huge-code-pages --disable-phpdbg \
--enable-bcmath --enable-tidy --enable-gd --enable-exif --with-jpeg --with-freetype --with-webp \
--enable-fiber-asm --with-curl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zip --with-sodium \
--with-pgsql=$PHP_WASIX_DEPS/pgsql-eh --with-pdo-pgsql=$PHP_WASIX_DEPS/pgsql-eh --enable-intl \
--with-pgsql="$PHP_WASIX_DEPS"/pgsql-eh --with-pdo-pgsql="$PHP_WASIX_DEPS"/pgsql-eh --enable-intl \
--with-pdo-sqlite --enable-ftp --enable-igbinary --with-imagick \
--program-suffix=".wasm"

Expand Down
Loading