Skip to content

Commit 932bbef

Browse files
committed
fix build scripts and support linux build
1 parent 25e60c5 commit 932bbef

File tree

8 files changed

+61
-19
lines changed

8 files changed

+61
-19
lines changed

Diff for: mars/build_android.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,18 @@ def main(incremental, archs, target_option='', tag=''):
165165
main(False, archs, tag=sys.argv[1])
166166
break
167167
else:
168-
archs = {'armeabi-v7a', 'arm64-v8a'}
169-
num = raw_input('Enter menu:\n1. Clean && build mars.\n2. Build incrementally mars.\n3. Clean && build xlog.\n4. Exit\n')
170-
if num == '1':
168+
archs = {'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'}
169+
num = input('Enter menu:\n1. Clean && build mars.\n2. Build incrementally mars.\n3. Clean && build xlog.\n4. Exit\n')
170+
if num == 1:
171171
main(False, archs)
172172
break
173-
elif num == '2':
173+
elif num == 2:
174174
main(True, archs)
175175
break
176-
elif num == '3':
176+
elif num == 3:
177177
main(False, archs, '--target libzstd_static marsxlog')
178178
break
179-
elif num == '4':
179+
elif num == 4:
180180
break
181181
else:
182182
main(False, archs)

Diff for: mars/build_ios.py

+29-11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
BUILD_OUT_PATH = 'cmake_build/iOS'
1212
INSTALL_PATH = BUILD_OUT_PATH + '/Darwin.out'
1313

14+
IOS_BUILD_ARM_SIMULATOR_CMD = 'cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR -DIOS_ARCH="arm64" -DENABLE_ARC=0 -DENABLE_BITCODE=0 -DENABLE_VISIBILITY=1 && make -j8 && make install'
1415
IOS_BUILD_SIMULATOR_CMD = 'cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR -DIOS_ARCH="x86_64" -DENABLE_ARC=0 -DENABLE_BITCODE=0 -DENABLE_VISIBILITY=1 && make -j8 && make install'
1516
IOS_BUILD_OS_CMD = 'cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DIOS_PLATFORM=OS -DIOS_ARCH="arm64" -DENABLE_ARC=0 -DENABLE_BITCODE=0 -DENABLE_VISIBILITY=1 && make -j8 && make install'
1617

@@ -87,14 +88,19 @@ def build_ios_xlog(tag=''):
8788
print('!!!!!!!!!!!build os fail!!!!!!!!!!!!!!!')
8889
return False
8990

90-
libtool_os_dst_lib = INSTALL_PATH + '/os'
91+
libtool_os_dst_lib = INSTALL_PATH + '/mars'
9192
libtool_src_libs = [INSTALL_PATH + '/libcomm.a',
9293
INSTALL_PATH + '/libmars-boost.a',
9394
INSTALL_PATH + '/libxlog.a',
9495
BUILD_OUT_PATH + '/zstd/libzstd.a']
9596
if not libtool_libs(libtool_src_libs, libtool_os_dst_lib):
9697
return False
9798

99+
os_dst_framework_path = INSTALL_PATH + '/os/mars.framework'
100+
make_static_framework(libtool_os_dst_lib, os_dst_framework_path, XLOG_COPY_HEADER_FILES, '../')
101+
print('==================Output========================')
102+
print(os_dst_framework_path)
103+
98104
clean(BUILD_OUT_PATH)
99105
os.chdir(BUILD_OUT_PATH)
100106
ret = os.system(IOS_BUILD_SIMULATOR_CMD)
@@ -103,24 +109,36 @@ def build_ios_xlog(tag=''):
103109
print('!!!!!!!!!!!build simulator fail!!!!!!!!!!!!!!!')
104110
return False
105111

106-
libtool_simulator_dst_lib = INSTALL_PATH + '/simulator'
112+
libtool_simulator_dst_lib = INSTALL_PATH + '/sim-x64'
107113
if not libtool_libs(libtool_src_libs, libtool_simulator_dst_lib):
108114
return False
109115

116+
clean(BUILD_OUT_PATH)
117+
os.chdir(BUILD_OUT_PATH)
118+
ret = os.system(IOS_BUILD_ARM_SIMULATOR_CMD)
119+
os.chdir(SCRIPT_PATH)
120+
if ret != 0:
121+
print('!!!!!!!!!!!build arm simulator fail!!!!!!!!!!!!!!!')
122+
return False
123+
124+
libtool_arm_simulator_dst_lib = INSTALL_PATH + '/sim-arm64'
125+
if not libtool_libs(libtool_src_libs, libtool_arm_simulator_dst_lib):
126+
return False
127+
110128
lipo_src_libs = []
111-
lipo_src_libs.append(libtool_os_dst_lib)
112129
lipo_src_libs.append(libtool_simulator_dst_lib)
130+
lipo_src_libs.append(libtool_arm_simulator_dst_lib)
113131
lipo_dst_lib = INSTALL_PATH + '/mars'
114132

115133
if not lipo_libs(lipo_src_libs, lipo_dst_lib):
116134
return False
117135

118-
dst_framework_path = INSTALL_PATH + '/mars.framework'
119-
make_static_framework(lipo_dst_lib, dst_framework_path, XLOG_COPY_HEADER_FILES, '../')
120-
136+
sim_dst_framework_path = INSTALL_PATH + '/sim/mars.framework'
137+
make_static_framework(lipo_dst_lib, sim_dst_framework_path, XLOG_COPY_HEADER_FILES, '../')
121138
print('==================Output========================')
122-
print(dst_framework_path)
139+
print(sim_dst_framework_path)
123140

141+
os.system('xcodebuild -create-xcframework -framework %s -framework %s -output %s/mars.xcframework' % (os_dst_framework_path, sim_dst_framework_path, INSTALL_PATH))
124142

125143

126144
def gen_ios_project():
@@ -147,16 +165,16 @@ def main():
147165
break
148166
else:
149167
num = input('Enter menu:\n1. Clean && build mars.\n2. Clean && build xlog.\n3. Gen iOS mars Project.\n4. Exit\n')
150-
if num == '1':
168+
if num == 1:
151169
build_ios()
152170
break
153-
if num == '2':
171+
elif num == 2:
154172
build_ios_xlog()
155173
break
156-
elif num == '3':
174+
elif num == 3:
157175
gen_ios_project()
158176
break
159-
elif num == '4':
177+
elif num == 4:
160178
break
161179
else:
162180
build_ios()

Diff for: mars/comm/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ if(ANDROID)
120120
jni/util/*.cc)
121121

122122
list(APPEND SELF_SRC_FILES ${SELF_ANDROID_SRC_FILES})
123+
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
124+
file(GLOB SELF_LINUX_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR}
125+
jni/xlogger_threadinfo.cc)
126+
127+
list(APPEND SELF_SRC_FILES ${SELF_LINUX_SRC_FILES})
123128
elseif(APPLE)
124129

125130
file(GLOB SELF_TEMP_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR} objc/*.mm objc/*.h)

Diff for: mars/comm/fd_info.cc

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <sys/stat.h>
1616
#include <sys/types.h>
1717
#include <unistd.h>
18+
#include <string.h>
1819
#endif
1920

2021

Diff for: mars/comm/jni/xlogger_threadinfo.cc

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
//
2020

2121
#include <unistd.h>
22+
#include <stdint.h>
23+
#ifndef ANDROID
24+
#include <sys/syscall.h>
25+
#define gettid() syscall(SYS_gettid)
26+
#endif
2227
#include "compiler_util.h"
2328

2429
extern "C"

Diff for: mars/comm/strutil.cc

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <locale>
2929

3030
#include "comm/xlogger/xlogger.h"
31-
#include "mars/openssl/include/openssl/md5.h"
3231

3332
#ifdef WIN32
3433
#define snprintf _snprintf

Diff for: mars/log/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ elseif(ANDROID)
5959

6060
get_filename_component(EXPORT_EXP_FILE jni/export.exp ABSOLUTE)
6161
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${EXPORT_EXP_FILE}")
62-
62+
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
63+
file(GLOB SELF_LINUX_SRC_FILES RELATIVE ${PROJECT_SOURCE_DIR}
64+
jni/ConsoleLog.cc)
65+
66+
list(APPEND SELF_SRC_FILES ${SELF_LINUX_SRC_FILES})
6367
endif()
6468

6569
# add_library(${PROJECT_NAME} STATIC ${SELF_SRC_FILES})

Diff for: mars/log/jni/ConsoleLog.cc

+10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#include <stdio.h>
1919
#include <string.h>
20+
#ifdef ANDROID
2021
#include <android/log.h>
22+
#endif
2123

2224
#include "mars/comm/xlogger/xloggerbase.h"
2325
#include "mars/comm/xlogger/loginfo_extract.h"
@@ -35,10 +37,18 @@ void ConsoleLog(const XLoggerInfo* _info, const char* _log) {
3537
const char* strFuncName = NULL == _info->func_name ? "" : _info->func_name;
3638

3739
snprintf(result_log, sizeof(result_log), "[%s:%d, %s]:%s", filename, _info->line, strFuncName, _log?_log:"NULL==log!!!");
40+
#ifdef ANDROID
3841
__android_log_write(_info->level+2, _info->tag?_info->tag:"", (const char*)result_log);
42+
#else
43+
printf("%s", (const char*)result_log);
44+
#endif
3945
} else {
4046
snprintf(result_log, sizeof(result_log) , "%s", _log?_log:"NULL==log!!!");
47+
#ifdef ANDROID
4148
__android_log_write(ANDROID_LOG_WARN, "", (const char*)result_log);
49+
#else
50+
printf("%s", (const char*)result_log);
51+
#endif
4252
}
4353

4454
}

0 commit comments

Comments
 (0)