Skip to content

Commit 992d0ad

Browse files
authored
Support static compilation (swoole#4153)
* Support static compilation * Support static compilation[2] * fix
1 parent 1982bb0 commit 992d0ad

File tree

9 files changed

+81
-58
lines changed

9 files changed

+81
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.so
88
*.loT
99
*.pid
10+
*.dep
1011
/Debug/*
1112
modules/*
1213
/.deps

config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ if test "$PHP_SWOOLE" != "no"; then
730730
AC_DEFINE(SW_USE_ASM_CONTEXT, 1, [use boost asm context])
731731
fi
732732

733-
PHP_NEW_EXTENSION(swoole, $swoole_source_file, $ext_shared,,$EXTRA_CFLAGS, cxx)
733+
PHP_NEW_EXTENSION(swoole, $swoole_source_file, $ext_shared,, "$EXTRA_CFLAGS -DENABLE_PHP_SWOOLE", cxx)
734734

735735
PHP_ADD_INCLUDE([$ext_srcdir])
736736
PHP_ADD_INCLUDE([$ext_srcdir/include])

ext-src/php_swoole_cxx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#pragma once
1818

19-
#include "php_swoole.h"
19+
#include "php_swoole_private.h"
2020
#include "php_swoole_coroutine.h"
2121
#include "swoole_util.h"
2222

ext-src/php_swoole.h renamed to ext-src/php_swoole_private.h

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,15 @@
1414
+----------------------------------------------------------------------+
1515
*/
1616

17-
#ifndef PHP_SWOOLE_H
18-
#define PHP_SWOOLE_H
17+
#ifndef PHP_SWOOLE_PRIVATE_H
18+
#define PHP_SWOOLE_PRIVATE_H
1919

2020
// C++ build format macros must defined earlier
2121
#ifdef __cplusplus
2222
#define __STDC_FORMAT_MACROS
2323
#endif
2424

25-
#include "php.h"
26-
#include "php_ini.h"
27-
#include "php_globals.h"
28-
#include "php_main.h"
29-
30-
#include "php_streams.h"
31-
#include "php_network.h"
32-
33-
#include "zend_variables.h"
34-
#include "zend_interfaces.h"
35-
#include "zend_closures.h"
36-
#include "zend_exceptions.h"
37-
38-
#ifdef HAVE_CONFIG_H
39-
#include "config.h"
40-
#endif
25+
#include "php_swoole.h"
4126

4227
#define SW_HAVE_COUNTABLE 1
4328

@@ -62,8 +47,6 @@ BEGIN_EXTERN_C()
6247

6348
extern PHPAPI int php_array_merge(zend_array *dest, zend_array *src);
6449

65-
extern zend_module_entry swoole_module_entry;
66-
6750
#ifdef PHP_WIN32
6851
#define PHP_SWOOLE_API __declspec(dllexport)
6952
#elif defined(__GNUC__) && __GNUC__ >= 4
@@ -152,13 +135,13 @@ enum php_swoole_fd_type {
152135
PHP_SWOOLE_FD_CO_CURL,
153136
};
154137
//---------------------------------------------------------
155-
typedef enum {
138+
enum php_swoole_req_status {
156139
PHP_SWOOLE_RINIT_BEGIN,
157140
PHP_SWOOLE_RINIT_END,
158141
PHP_SWOOLE_CALL_USER_SHUTDOWNFUNC_BEGIN,
159142
PHP_SWOOLE_RSHUTDOWN_BEGIN,
160143
PHP_SWOOLE_RSHUTDOWN_END,
161-
} php_swoole_req_status;
144+
};
162145
//---------------------------------------------------------
163146

164147
static sw_inline enum swSocket_type php_swoole_socktype(long type) {
@@ -184,12 +167,6 @@ extern zend_class_entry *swoole_exception_ce;
184167
extern zend_object_handlers swoole_exception_handlers;
185168
extern zend_class_entry *swoole_error_ce;
186169

187-
PHP_MINIT_FUNCTION(swoole);
188-
PHP_MSHUTDOWN_FUNCTION(swoole);
189-
PHP_RINIT_FUNCTION(swoole);
190-
PHP_RSHUTDOWN_FUNCTION(swoole);
191-
PHP_MINFO_FUNCTION(swoole);
192-
193170
PHP_FUNCTION(swoole_clear_dns_cache);
194171
PHP_FUNCTION(swoole_last_error);
195172
PHP_FUNCTION(swoole_set_process_name);
@@ -313,27 +290,6 @@ php_socket *php_swoole_convert_to_socket(int sock);
313290

314291
zend_bool php_swoole_signal_isset_handler(int signo);
315292

316-
// clang-format off
317-
ZEND_BEGIN_MODULE_GLOBALS(swoole)
318-
zend_bool display_errors;
319-
zend_bool cli;
320-
zend_bool use_shortname;
321-
zend_bool enable_coroutine;
322-
zend_bool enable_preemptive_scheduler;
323-
zend_bool enable_library;
324-
long socket_buffer_size;
325-
php_swoole_req_status req_status;
326-
ZEND_END_MODULE_GLOBALS(swoole)
327-
// clang-format on
328-
329-
extern ZEND_DECLARE_MODULE_GLOBALS(swoole);
330-
331-
#ifdef ZTS
332-
#define SWOOLE_G(v) TSRMG(swoole_globals_id, zend_swoole_globals *, v)
333-
#else
334-
#define SWOOLE_G(v) (swoole_globals.v)
335-
#endif
336-
337293
/* PHP 7 compatibility patches */
338294
#define sw_zend_bailout() zend_bailout()
339295

@@ -1126,4 +1082,4 @@ static sw_inline char *php_swoole_http_build_query(zval *zdata, size_t *length,
11261082

11271083
END_EXTERN_C()
11281084

1129-
#endif /* PHP_SWOOLE_H */
1085+
#endif /* PHP_SWOOLE_PRIVATE_H */

ext-src/swoole_atomic.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
+----------------------------------------------------------------------+
1515
*/
1616

17-
#include "php_swoole.h"
17+
#include "php_swoole_private.h"
1818
#include "swoole_memory.h"
1919

2020
#ifdef HAVE_FUTEX

ext-src/swoole_lock.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
+----------------------------------------------------------------------+
1515
*/
1616

17-
#include "php_swoole.h"
17+
#include "php_swoole_private.h"
1818
#include "swoole_memory.h"
1919
#include "swoole_lock.h"
2020

include/swoole.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#pragma once
1919

20-
#if defined(HAVE_CONFIG_H) && !defined(COMPILE_DL_SWOOLE)
20+
#ifdef HAVE_CONFIG_H
2121
#include "config.h"
22-
#elif defined(PHP_ATOM_INC) || defined(ZEND_SIGNALS)
22+
#elif defined(ENABLE_PHP_SWOOLE)
2323
#include "php_config.h"
2424
#endif
2525

php_swoole.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Swoole |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 2.0 of the Apache license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.apache.org/licenses/LICENSE-2.0.html |
9+
| If you did not receive a copy of the Apache2.0 license and are unable|
10+
| to obtain it through the world-wide-web, please send a note to |
11+
| license@swoole.com so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Author: Tianfeng Han <mikan.tenny@gmail.com> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#ifndef PHP_SWOOLE_H
18+
#define PHP_SWOOLE_H
19+
20+
#include "php.h"
21+
#include "php_ini.h"
22+
#include "php_globals.h"
23+
#include "php_main.h"
24+
25+
#include "php_streams.h"
26+
#include "php_network.h"
27+
28+
#include "zend_variables.h"
29+
#include "zend_interfaces.h"
30+
#include "zend_closures.h"
31+
#include "zend_exceptions.h"
32+
33+
#ifdef HAVE_CONFIG_H
34+
#include "config.h"
35+
#endif
36+
37+
extern zend_module_entry swoole_module_entry;
38+
#define phpext_swoole_ptr &swoole_module_entry
39+
40+
PHP_MINIT_FUNCTION(swoole);
41+
PHP_MSHUTDOWN_FUNCTION(swoole);
42+
PHP_RINIT_FUNCTION(swoole);
43+
PHP_RSHUTDOWN_FUNCTION(swoole);
44+
PHP_MINFO_FUNCTION(swoole);
45+
46+
// clang-format off
47+
ZEND_BEGIN_MODULE_GLOBALS(swoole)
48+
zend_bool display_errors;
49+
zend_bool cli;
50+
zend_bool use_shortname;
51+
zend_bool enable_coroutine;
52+
zend_bool enable_preemptive_scheduler;
53+
zend_bool enable_library;
54+
long socket_buffer_size;
55+
int req_status;
56+
ZEND_END_MODULE_GLOBALS(swoole)
57+
// clang-format on
58+
59+
extern ZEND_DECLARE_MODULE_GLOBALS(swoole);
60+
61+
#ifdef ZTS
62+
#define SWOOLE_G(v) TSRMG(swoole_globals_id, zend_swoole_globals *, v)
63+
#else
64+
#define SWOOLE_G(v) (swoole_globals.v)
65+
#endif
66+
67+
#endif /* PHP_SWOOLE_H */

thirdparty/php/standard/var_decoder.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ BEGIN_EXTERN_C()
44
#include "ext/standard/php_var.h"
55
#ifdef SW_USE_JSON
66
#include "ext/json/php_json.h"
7-
8-
PHP_JSON_API zend_class_entry *php_json_exception_ce;
7+
extern PHP_JSON_API zend_class_entry *php_json_exception_ce;
98
#endif
109
END_EXTERN_C()
1110

0 commit comments

Comments
 (0)