forked from arduino/nicla-sense-me-fw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DistTasks.yml
141 lines (124 loc) · 5.46 KB
/
DistTasks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/release-go-task/DistTasks.yml
version: "3"
# This taskfile is ideally meant to be project agnostic and could be dropped in
# on other Go projects with minimal or no changes.
#
# To use it simply add the following lines to your main taskfile:
# includes:
# dist: ./DistTasks.yml
#
# The following variables must be declared in the including taskfile for the
# build process to work correctly:
# * DIST_DIR: the folder that will contain the final binaries and packages
# * PROJECT_NAME: the name of the project, used in package name
# * VERSION: the version of the project, used in package name and checksum file
# * LD_FLAGS: flags used at build time
#
# The project MUST contain a LICENSE.txt file in the root folder or packaging will fail.
vars:
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
GO_VERSION: "1.16.4"
tasks:
Windows_32bit:
desc: Builds Windows 32 bit binaries
dir: "{{.TOOL_DIR}}/{{.DIST_DIR}}"
cmds:
- |
docker run -v {{ .TOOL_DIR }}:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_386"
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}"
BUILD_PLATFORM: "windows/386"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Windows_32bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip"
Windows_64bit:
desc: Builds Windows 64 bit binaries
dir: "{{.TOOL_DIR}}/{{.DIST_DIR}}"
cmds:
- |
docker run -v {{ .TOOL_DIR }}:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../LICENSE.txt -j
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_amd64"
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}"
BUILD_PLATFORM: "windows/amd64"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Windows_64bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip"
Linux_32bit:
desc: Builds Linux 32 bit binaries
dir: "{{.TOOL_DIR}}/{{.DIST_DIR}}"
cmds:
- |
docker run -v {{ .TOOL_DIR }}:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd32"
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
BUILD_PLATFORM: "linux/386"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Linux_32bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
Linux_64bit:
desc: Builds Linux 64 bit binaries
dir: "{{.TOOL_DIR}}/{{.DIST_DIR}}"
cmds:
- |
docker run -v {{ .TOOL_DIR }}:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd64"
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
BUILD_PLATFORM: "linux/amd64"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Linux_64bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
macOS_64bit:
desc: Builds Mac OS X 64 bit binaries
dir: "{{.TOOL_DIR}}/{{.DIST_DIR}}"
cmds:
- |
docker run -v {{ .TOOL_DIR }}:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_amd64"
BUILD_COMMAND: "go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}"
BUILD_PLATFORM: "darwin/amd64"
# We are experiencing the following error with macOS_64bit build:
#
# Undefined symbols for architecture x86_64:
# "_clock_gettime", referenced from:
# _runtime.walltime_trampoline in go.o
# ld: symbol(s) not found for architecture x86_64
# clang: error: linker command failed with exit code 1 (use -v to see invocation)
#
# The reason seems that go 1.16.x use a macos API which is available since 10.12
# https://github.com/techknowlogick/xgo/issues/100#issuecomment-780894190
#
# To compile it we need an SDK >=10.12 so we use the debian10 based container that
# has the SDK 10.14 installed.
CONTAINER_TAG: "{{.GO_VERSION}}-darwin-debian10"
PACKAGE_PLATFORM: "macOS_64bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"