Skip to content

Instantly share code, notes, and snippets.

@sparrowhe
Last active November 16, 2022 06:03
Show Gist options
  • Save sparrowhe/4ade497ef38bcfe144cdcadeda3f16b8 to your computer and use it in GitHub Desktop.
Save sparrowhe/4ade497ef38bcfe144cdcadeda3f16b8 to your computer and use it in GitHub Desktop.
使用 Github Action 编译 fsd
name: CMake
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build-windows:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- name: Configure CMake & Build
run: $env:CXXFLAGS="-DWIN32" ; cmake -B ${{github.workspace}}/build ; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.1
with:
# Artifact name
name: fsd-windows
# A file, directory or wildcard pattern that describes what to upload
path: ${{github.workspace}}/build/Release/fsd.exe
build-linux:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.1
with:
# Artifact name
name: fsd-unix
# A file, directory or wildcard pattern that describes what to upload
path: ${{github.workspace}}/build/fsd

Github Action 是一个可以白嫖的 CI/CD 服务,同时提供 Win/Linux/MacOS 支持。具体软件详情可以参考官方页面。

FSD编译一直是一个头疼问题,尤其是 Windows 系统,你不得不安装VS全家桶才能编译。

为了能顺利编译,首先要对代码进行一些调整

调整代码

  1. support.cpp void dolog(int level, const char *string, ...) 将其中 long secs=time(NULL); 替换为
#ifdef WIN32
    time_t secs=time(NULL);
#else
    long secs=time(NULL);
#endif
  1. global.h 在 #ifdef WIN32#else 之间插入
#pragma comment(lib,"ws2_32.lib")
#define M_PI 3.14159265358

处理完成后:

#ifdef WIN32
	#define STRCASECMP(a,b)	_stricmp(a,b)
	#define WRITESOCK(a,b,c) send(a,b,c,0) 
	#define READSOCK(a,b,c) recv(a,b,c,0) 
	#define socklen_t	int
	#define CLOSESOCKET(a) closesocket(a) 
	#pragma comment(lib,"ws2_32.lib")
	#define M_PI 3.14159265358
#else
	#define STRCASECMP(a,b)	strcasecmp(a,b)
	#define WRITESOCK(a,b,c) write(a,b,c) 
	#define READSOCK(a,b,c) read(a,b,c) 
	#define CLOSESOCKET(a) close(a) 
#endif

配置 Action

上面提供了一份完整的配置文件,你也可以根据你的需要自行修改。将 cmake.yml 放进 .github/workflows 目录即可使用,构建完成后,文件将会上传到对应的 Action 主页 image

常见问题

如果推送后没有正常触发,请检查你的源码是否在 main 分支,如果不是,请更改配置文件中 L5 和 L7 中的触发条件

若遇其他问题,可联系 sparrowhe#gmail.com / QQ 1441373096。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment