Skip to content

Expose os, compiler, arch in php -v #19328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,16 @@ AC_ARG_VAR([PHP_UNAME],
AS_VAR_IF([PHP_UNAME],, [PHP_UNAME=$(uname -a | xargs)])
AC_DEFINE_UNQUOTED([PHP_UNAME], ["$PHP_UNAME"], [The 'uname -a' output.])

AC_ARG_VAR([PHP_UNAME_S],
[Operating system name (defaults to the 'uname -s' output)])
AS_VAR_IF([PHP_UNAME_S],, [PHP_UNAME_S=$(uname -s | xargs)])
AC_DEFINE_UNQUOTED([PHP_UNAME_S], ["$PHP_UNAME_S"], [The 'uname -s' output.])

AC_ARG_VAR([PHP_UNAME_R],
[Operating system version (defaults to the 'uname -r' output)])
AS_VAR_IF([PHP_UNAME_R],, [PHP_UNAME_R=$(uname -r | xargs)])
AC_DEFINE_UNQUOTED([PHP_UNAME_R], ["$PHP_UNAME_R"], [The 'uname -r' output.])

PHP_OS=$(uname | xargs)
AC_DEFINE_UNQUOTED([PHP_OS], ["$PHP_OS"], [The 'uname' output.])

Expand Down
26 changes: 17 additions & 9 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,31 @@ PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
#else
"NTS"
#endif
#ifdef PHP_BUILD_COMPILER
" " PHP_BUILD_COMPILER
#endif
#ifdef PHP_BUILD_ARCH
" " PHP_BUILD_ARCH
#endif
#if ZEND_DEBUG
" DEBUG"
#endif
#ifdef HAVE_GCOV
" GCOV"
#endif
#ifdef PHP_BUILD_ARCH
" " PHP_BUILD_ARCH
#else
" Unknown arch"
#endif
);
smart_string_appends(&version_info, "Copyright (c) The PHP Group\n");
if (php_build_provider()) {
smart_string_append_printf(&version_info, "Built by %s\n", php_build_provider());
}
smart_string_append_printf(&version_info, "Built %s\n",
#ifdef PHP_BUILD_PROVIDER
"by " PHP_BUILD_PROVIDER
Copy link
Member

@remicollet remicollet Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP_BUILD_PROVIDER should always be there (built by)

And condition for PHP_BUILD_SYSTEM or PHP_UNAME_S + PHP_UNAME_R (built on)

#else
"on " PHP_UNAME_S " " PHP_UNAME_R
#endif
#ifdef PHP_BUILD_COMPILER
" (" PHP_BUILD_COMPILER ")"
#else
""
#endif
);
smart_string_appends(&version_info, get_zend_version());
smart_string_0(&version_info);

Expand Down
21 changes: 21 additions & 0 deletions main/php_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ PHPAPI bool php_tsrm_startup(void);
#define PHP_OS_STR PHP_OS
#endif

#define _PHP_STRINGIFY(s) #s
#define PHP_STRINGIFY(s) _PHP_STRINGIFY(s)

#ifndef PHP_BUILD_COMPILER
# if defined(__clang__)
# define PHP_BUILD_COMPILER "Clang " PHP_STRINGIFY(__clang_major__)
# elif defined(__GNUC__)
# define PHP_BUILD_COMPILER "GCC " PHP_STRINGIFY(__GNUC__)
# endif
#endif

#ifndef PHP_BUILD_ARCH
# if defined(__x86_64__)
# define PHP_BUILD_ARCH "x64"
# elif defined(__i386__)
# define PHP_BUILD_ARCH "x86"
# elif defined(__aarch64__)
# define PHP_BUILD_ARCH "aarch64"
# endif
#endif

END_EXTERN_C()

#endif
2 changes: 2 additions & 0 deletions win32/build/confutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ extension_module_ptrs = "";
var oss = wmiservice.ExecQuery("Select * from Win32_OperatingSystem");
var os = oss.ItemIndex(0);
AC_DEFINE("PHP_BUILD_SYSTEM", os.Caption + " [" + os.Version + "]", "The system that PHP was built on.");
AC_DEFINE("PHP_UNAME_S", os.Caption, "The system name that PHP was built on.");
AC_DEFINE("PHP_UNAME_R", os.Version, "The system version that PHP was built on.");
var build_provider = WshShell.Environment("Process").Item("PHP_BUILD_PROVIDER");
if (build_provider) {
AC_DEFINE("PHP_BUILD_PROVIDER", build_provider, "The PHP build provider information.");
Expand Down
Loading