Skip to content

Commit

Permalink
support vs 2022编译
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Nov 15, 2024
1 parent c5b8525 commit 7e18e9a
Show file tree
Hide file tree
Showing 707 changed files with 170,008 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ test/make
3rd/zlib/zlib.a

3rd/zlib/libz.a

build*
.vs
206 changes: 206 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
cmake_minimum_required(VERSION 3.10)
project(skynet_fly)

# 添加编译选项
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 把lua头文件添加到全局搜索路径
include_directories(skynet/3rd/lua/)

# Windows
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
message(STATUS "current platform: Windows")
add_compile_definitions(NOUSE_JEMALLOC LUA_BUILD_AS_DLL)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-int-conversion -Wno-implicit-function-declaration -Wno-deprecated-declarations")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

#设置输出目录
set(CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}/skynet_fly)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/skynet)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
message(STATUS "The value of CMAKE_BINARY_DIR is: ${CMAKE_BINARY_DIR}")

# 添加到全局搜索路径
include_directories(win3rd/posix win3rd/pthread-win32)
add_compile_options(/FI ${CMAKE_SOURCE_DIR}/win3rd/posix/unistd.h)

aux_source_directory(skynet/3rd/lua LUA_LIB_SRC)
list(REMOVE_ITEM LUA_LIB_SRC
"skynet/3rd/lua/lua.c"
"skynet/3rd/lua/luac.c"
"skynet/3rd/lua/onelua.c"
"skynet/3rd/lua/ltests.c")
message(STATUS "The value of LUA_LIB_SRC is: ${LUA_LIB_SRC}")

aux_source_directory(skynet/skynet-src LIB_SKYNET_SRC)
list(REMOVE_ITEM LIB_SKYNET_SRC skynet/skynet-src/skynet_main.c)
aux_source_directory(win3rd/posix POSIX_SRC)
add_subdirectory(win3rd/pthread-win32)
add_library(liblua SHARED ${LUA_LIB_SRC})
target_include_directories(liblua PRIVATE skynet/skynet-src)
add_library(libposix SHARED ${POSIX_SRC})
target_compile_definitions(libposix PRIVATE POSIX_LIBRARY)
target_link_libraries(libposix ws2_32)
add_library(libskynet SHARED ${LIB_SKYNET_SRC})
target_include_directories(libskynet PRIVATE skynet/skynet-src)
target_link_libraries(libskynet liblua libposix pthreadVC3)

# 编译 skynet 可执行文件
add_executable(skynet skynet/skynet-src/skynet_main.c)
target_link_libraries(skynet ws2_32 liblua libposix libskynet pthreadVC3)

# 重新设置动态库输出路径
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/skynet/luaclib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/skynet/luaclib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

# 生成动态库 skynet.so
set(LUA_CLIB_SKYNET_SRC
skynet/lualib-src/lua-skynet.c
skynet/lualib-src/lua-seri.c
skynet/lualib-src/lua-socket.c
skynet/lualib-src/lua-mongo.c
skynet/lualib-src/lua-netpack.c
skynet/lualib-src/lua-memory.c
skynet/lualib-src/lua-multicast.c
skynet/lualib-src/lua-cluster.c
skynet/lualib-src/lua-crypt.c
skynet/lualib-src/lsha1.c
skynet/lualib-src/lua-sharedata.c
skynet/lualib-src/lua-stm.c
skynet/lualib-src/lua-debugchannel.c
skynet/lualib-src/lua-datasheet.c
skynet/lualib-src/lua-sharetable.c
lualib-src/lua-frpcpack.c)
message(STATUS "The value of LIB_SKYNET_SRC is: ${LIB_SKYNET_SRC}")
add_library(skynetso SHARED ${LUA_CLIB_SKYNET_SRC})
target_include_directories(skynetso PRIVATE skynet/skynet-src)
target_compile_definitions(skynetso PUBLIC LUA_LIB)
set_target_properties(skynetso PROPERTIES OUTPUT_NAME skynet)
target_link_libraries(skynetso ws2_32 libskynet)

# 生成动态库 bson.so
add_library(bson SHARED skynet/lualib-src/lua-bson.c)
target_include_directories(bson PRIVATE skynet/skynet-src)
target_link_libraries(bson ws2_32 liblua)

# 生成动态库 md5.so
aux_source_directory(skynet/3rd/lua-md5 LUA_MD5_SRC)
add_library(md5 SHARED ${LUA_MD5_SRC})
target_link_libraries(md5 liblua)

# 生成动态库 client.so
add_library(client SHARED skynet/lualib-src/lua-clientsocket.c
skynet/lualib-src/lua-crypt.c
skynet/lualib-src/lsha1.c)
target_include_directories(client PRIVATE skynet/skynet-src)
target_link_libraries(client ws2_32 liblua libposix pthreadVC3)

# 生成动态库 sproto.so
aux_source_directory(skynet/lualib-src/sproto SPROTO_SRC)
add_library(sproto SHARED ${SPROTO_SRC})
target_link_libraries(sproto liblua)

# 生成动态库 lpeg.so
aux_source_directory(skynet/3rd/lpeg LPEG_SRC)
add_library(lpeg SHARED ${LPEG_SRC})
target_link_libraries(lpeg liblua)

# 生成动态库 ltls.so
add_library(ltls SHARED skynet/lualib-src/ltls.c)
target_include_directories(ltls PRIVATE skynet/skynet-src)
target_include_directories(ltls PRIVATE win3rd/openssl/include/)
target_link_directories(ltls PRIVATE win3rd/openssl/lib/windows/)
target_link_libraries(ltls ws2_32 mswsock liblua libposix pthreadVC3 libssl libcrypto Crypt32)

# 重新设置动态库输出路径
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/luaclib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/luaclib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

# 生成动态库 pb.so
aux_source_directory(3rd/lua-protobuf-0.4.0 PB_SRC)
add_library(pb SHARED ${PB_SRC})
target_link_libraries(pb liblua)

# 生成动态库 lfs.so
aux_source_directory(3rd/luafilesystem-1_8_0/src LFS_SRC)
add_library(lfs SHARED ${LFS_SRC})
target_link_libraries(lfs liblua)

# 生成动态库 cjson.so
add_library(cjson SHARED 3rd/lua-cjson/lua_cjson.c 3rd/lua-cjson/strbuf.c 3rd/lua-cjson/fpconv.c)
target_include_directories(cjson PRIVATE 3rd/lua-cjson)
target_link_libraries(cjson liblua)

# 生成动态库 skiplist.so
aux_source_directory(3rd/lua-zset ZSET_SRC)
add_library(skiplist SHARED ${ZSET_SRC})
target_link_libraries(skiplist liblua)

# 生成动态库 chat_filter.so
aux_source_directory(3rd/lua-chat_filter CHAT_FILTER_SRC)
add_library(chat_filter SHARED ${CHAT_FILTER_SRC})
target_link_libraries(chat_filter liblua)

# 生成动态库 snapshot.so
add_library(snapshot SHARED 3rd/lua-snapshot/snapshot.c)
target_link_libraries(snapshot liblua)

# 生成动态库 openssl.so
aux_source_directory(3rd/lua-openssl-0.9.0-0 OPENSSL_SRC)
aux_source_directory(3rd/lua-openssl-0.9.0-0/deps/auxiliar OPENSSL_AUX_SRC)
aux_source_directory(3rd/lua-openssl-0.9.0-0/deps/lua-compat OPENSSL_COMPAT_SRC)
add_library(openssl SHARED ${OPENSSL_COMPAT_SRC} ${OPENSSL_AUX_SRC} ${OPENSSL_SRC})
target_include_directories(openssl PRIVATE win3rd/openssl/include/ 3rd/lua-openssl-0.9.0-0 3rd/lua-openssl-0.9.0-0/deps/auxiliar 3rd/lua-openssl-0.9.0-0/deps/lua-compat)
target_link_directories(openssl PRIVATE win3rd/openssl/lib/windows/)
target_link_libraries(openssl ws2_32 mswsock liblua libposix pthreadVC3 libssl libcrypto Crypt32)

# 设置动态库属性
set_target_properties(
lpeg sproto client md5 bson skynetso ltls
pb lfs skiplist chat_filter snapshot openssl cjson
PROPERTIES
PREFIX ""
SUFFIX .so )

# 重新设置动态库输出路径
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/skynet/cservice)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/skynet/cservice)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

# 生成c服务
file(GLOB CSERVICE_FILE_LIST "skynet/service-src/*.c")
message(STATUS "The value of CSERVICE_FILE_LIST is: ${CSERVICE_FILE_LIST}")
foreach(FILE_PATH IN LISTS CSERVICE_FILE_LIST)
message(STATUS "Processing file: ${FILE_PATH}")
string(REGEX REPLACE ".*skynet/service-src/service_" "" LIB_NAME "${FILE_PATH}")
string(REGEX REPLACE ".c$" "" LIB_NAME "${LIB_NAME}")
message(STATUS "The value of LIB_NAME is: ${LIB_NAME}")
add_library(${LIB_NAME} SHARED ${FILE_PATH})
target_include_directories(${LIB_NAME} PRIVATE skynet/skynet-src)
target_link_libraries(${LIB_NAME} ws2_32 libskynet)
set_target_properties(${LIB_NAME} PROPERTIES PREFIX "" SUFFIX .so ENABLE_EXPORTS ON)
endforeach()
endif ()

# 拷贝其他文件
message(STATUS "The value of CMAKE_SOURCE_DIR is: ${CMAKE_SOURCE_DIR}")
file(COPY ${CMAKE_SOURCE_DIR}/skynet/lualib/ DESTINATION skynet_fly/skynet/lualib NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/skynet/test/ DESTINATION skynet_fly/skynet/test NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/skynet/service/ DESTINATION skynet_fly/skynet/service NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/skynet/examples/ DESTINATION skynet_fly/skynet/examples NO_SOURCE_PERMISSIONS)

file(COPY ${CMAKE_SOURCE_DIR}/lualib/ DESTINATION skynet_fly/lualib NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/test/ DESTINATION skynet_fly/test NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/service/ DESTINATION skynet_fly/service NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/examples/ DESTINATION skynet_fly/examples NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/module/ DESTINATION skynet_fly/module NO_SOURCE_PERMISSIONS)
file(COPY ${CMAKE_SOURCE_DIR}/script/ DESTINATION skynet_fly/script NO_SOURCE_PERMISSIONS)
15 changes: 15 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "x64-Clang-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64" ]
}
]
}
16 changes: 9 additions & 7 deletions lualib/skynet-fly/hotfix/hotfix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function M.hotfix(hotfixmods)

if skynet.is_write_record() and base_info.index == 1 then --第一个启动记录下就行
local patch_dir = get_patch_dir()
local pathcmd = ""
local copy_file_obj = file_util.new_copy_file()
local dir_path_map = {}
for i, info in ipairs(sort_list) do
local name = info.name
Expand All @@ -218,17 +218,19 @@ function M.hotfix(hotfixmods)
local filename = string.match(path, "([^/]+%.lua)$")
local dir_path = sgsub(new_path, filename, '', 1)
dir_path_map[dir_path] = true
pathcmd = pathcmd .. string.format('cp %s %s;\n', path, new_path)
copy_file_obj.set_source_target(path, new_path)
end

local mkcmd = "mkdir -p "
for dir_path in pairs(dir_path_map) do
mkcmd = mkcmd .. dir_path .. ' '
local isok, err = file_util.mkdir(dir_path)
if not isok then
log.error("hotfix mkdir err ", dir_path, err)
end
end
mkcmd = mkcmd .. ';' .. pathcmd
local isok, err = os.execute(mkcmd)

local isok, err = copy_file_obj:execute()
if not isok then
log.error("record cp file err ", err)
log.error("hotfix cp file err ", err)
end
end

Expand Down
12 changes: 9 additions & 3 deletions lualib/skynet-fly/sharedata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ local function add_patch(file_path)
local new_path = get_patch_file_path(file_path, patch_dir)
local filename = string.match(file_path, "([^/]+%.lua)$")
local dir_path = string.gsub(new_path, filename, '', 1)
local cmd = string.format("mkdir -p %s;\ncp %s %s;", dir_path, file_path, new_path)
local isok, err = os.execute(cmd)
local isok, err = file_util.mkdir(dir_path)
if not isok then
log.error("record cp file err ", err)
log.error("record mkdir err ", err)
else
local copy_file_obj = file_util.new_copy_file()
copy_file_obj.set_source_target(file_path, new_path)
local isok, err = copy_file_obj:execute()
if not isok then
log.error("record cp file err ", err)
end
end
end

Expand Down
58 changes: 58 additions & 0 deletions lualib/skynet-fly/utils/file_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,62 @@ function M.convert_path(path)
return path
end

--递归创建文件夹
function M.mkdir(path)
-- 逐层获取并创建每个文件夹
local current_path = ""

for part in path:gmatch("([^/\\]+)") do
current_path = current_path .. part .. "/"

-- 检查当前路径是否存在
if lfs.attributes(current_path) == nil then
-- 如果不存在,则创建目录
local success, err = lfs.mkdir(current_path)
if not success then
return nil, "Error creating directory: " .. current_path .. " - " .. err
end
end
end

return true
end

function M.new_copy_file(is_dir)
local cmd = nil
--windows
local is_window = false
if package.config:sub(1, 1) == '\\' then
is_window = true
if is_dir then
cmd = "xcopy "
else
cmd = "copy "
end
else
if is_dir then
cmd = "cp -r "
else
cmd = "cp "
end
end

local list = {}
return {
set_source_target = function(source, target)
table.insert(list, cmd .. source .. ' ' .. target)
end,

execute = function()
local excute_cmd = nil
if is_window then
excute_cmd = table.concat(list, " && ")
else
excute_cmd = table.concat(list, ";")
end
return os.execute(excute_cmd)
end
}
end

return M
6 changes: 4 additions & 2 deletions lualib/skynet-fly/write_mod_required.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local skynet = require "skynet"
local lfs = require "lfs"
local log = require "skynet-fly.log"
local file_util = require "skynet-fly.utils.file_util"
local os = os
local io = io
local pairs = pairs
Expand All @@ -10,8 +11,9 @@ local loadmodsfile = skynet.getenv("loadmodsfile")

return function(headname, mod_name, loaded)
local write_dir = headname .. "." .. loadmodsfile
if not os.execute("mkdir -p " .. write_dir) then
log.error("write_mod_required mkdir err ", headname)
local isok, err = file_util.mkdir(write_dir)
if not isok then
log.error("write_mod_required mkdir err ", headname, err)
return
end
local info_file_name = mod_name .. '.required'
Expand Down
10 changes: 8 additions & 2 deletions module/logrotate_m.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ local function create_rotate(cfg)
for i = #back_list,m_max_backups + 1, -1 do
--删除文件
local f = tremove(back_list,i)
os_execute("rm -f " .. f.file_path)
local success, err = os.remove(f.file_path)
if not success then
log.warn("remove file err ", f.file_path, err)
end
end

local cur_time = os.time()
Expand All @@ -128,7 +131,10 @@ local function create_rotate(cfg)
local f = back_list[i]
--过期了
if cur_time - f.time > max_age_time then
os_execute("rm -f " .. f.file_path)
local success, err = os.remove(f.file_path)
if not success then
log.warn("remove file err ", f.file_path, err)
end
else
--有序的,当前这个没过期,前面的肯定也没有过期
break
Expand Down
Loading

0 comments on commit 7e18e9a

Please sign in to comment.