Skip to content

Commit 5125350

Browse files
authored
enable users to prepare the flutter engine within docker image without building first. (#214)
* create prepare-engine subcommand and use it in the dockerfile * fix(deps): github.com/otiai10/copy@v1.6.0: missing go.sum entry * fix(deps): go mod tidy * fix: swap engine prep to debug mode * fix: add missing ~ to CGO_LDFLAGS * remove support for multiple target OSes in prepare-engine. remove the prepare step within the docker image, users can prepare which ever engines they need on the fly add all supported engines to the CGO_LDFLAGS of the docker image * FEAT: add profile mode FIX: ensure exactly one mode is set at a time * FIX: don't check for darling within prepare-engine, simply fail for darwin releases * FIX: fail to prepare engine in release mode if on darwin * FIX: add profile for windows and linux * REQUEST: rework prepare mode validation logic FEAT: debug mode is default again
1 parent dbe2dbe commit 5125350

File tree

3 files changed

+113
-5
lines changed

3 files changed

+113
-5
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,13 @@ RUN go install -v ./... 2>&1
121121

122122
COPY docker/hover-safe.sh /usr/local/bin/hover-safe.sh
123123

124+
# Prepare engines
125+
ENV CGO_LDFLAGS="-L~/.cache/hover/engine/linux-release"
126+
ENV CGO_LDFLAGS="$CGO_LDFLAGS -L~/.cache/hover/engine/linux-debug_unopt"
127+
ENV CGO_LDFLAGS="$CGO_LDFLAGS -L~/.cache/hover/engine/linux-profile"
128+
ENV CGO_LDFLAGS="$CGO_LDFLAGS -L~/.cache/hover/engine/windows-release"
129+
ENV CGO_LDFLAGS="$CGO_LDFLAGS -L~/.cache/hover/engine/windows-debug_unopt"
130+
ENV CGO_LDFLAGS="$CGO_LDFLAGS -L~/.cache/hover/engine/windows-profile"
131+
ENV CGO_LDFLAGS="$CGO_LDFLAGS -L~/.cache/hover/engine/darwin-debug_unopt"
132+
124133
WORKDIR /app

cmd/prepare-engine.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
"runtime"
6+
7+
"github.com/go-flutter-desktop/hover/internal/build"
8+
"github.com/go-flutter-desktop/hover/internal/config"
9+
"github.com/go-flutter-desktop/hover/internal/enginecache"
10+
"github.com/go-flutter-desktop/hover/internal/log"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var (
15+
prepareCachePath string
16+
prepareEngineVersion string
17+
prepareReleaseMode bool
18+
prepareDebugMode bool
19+
prepareProfileMode bool
20+
prepareBuildModes []build.Mode
21+
)
22+
23+
func init() {
24+
prepareEngineCmd.PersistentFlags().StringVar(&prepareCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll")
25+
prepareEngineCmd.PersistentFlags().StringVar(&prepareEngineVersion, "engine-version", config.BuildEngineDefault, "The flutter engine version to use.")
26+
prepareEngineCmd.PersistentFlags().BoolVar(&prepareDebugMode, "debug", false, "Prepare the flutter engine for debug mode")
27+
prepareEngineCmd.PersistentFlags().BoolVar(&prepareReleaseMode, "release", false, "Prepare the flutter engine for release mode.")
28+
prepareEngineCmd.PersistentFlags().BoolVar(&prepareProfileMode, "profile", false, "Prepare the flutter engine for profile mode.")
29+
prepareEngineCmd.AddCommand(prepareEngineLinuxCmd)
30+
prepareEngineCmd.AddCommand(prepareEngineDarwinCmd)
31+
prepareEngineCmd.AddCommand(prepareEngineWindowsCmd)
32+
rootCmd.AddCommand(prepareEngineCmd)
33+
}
34+
35+
var prepareEngineCmd = &cobra.Command{
36+
Use: "prepare-engine",
37+
Short: "Validates or updates the flutter engine on this machine for a given platform",
38+
}
39+
40+
var prepareEngineLinuxCmd = &cobra.Command{
41+
Use: "linux",
42+
Short: "Validates or updates the flutter engine on this machine for a given platform",
43+
Run: func(cmd *cobra.Command, args []string) {
44+
initPrepareEngineParameters("linux")
45+
subcommandPrepare("linux")
46+
},
47+
}
48+
49+
var prepareEngineDarwinCmd = &cobra.Command{
50+
Use: "darwin",
51+
Short: "Validates or updates the flutter engine on this machine for a given platform",
52+
Run: func(cmd *cobra.Command, args []string) {
53+
initPrepareEngineParameters("darwin")
54+
subcommandPrepare("darwin")
55+
},
56+
}
57+
58+
var prepareEngineWindowsCmd = &cobra.Command{
59+
Use: "windows",
60+
Short: "Validates or updates the flutter engine on this machine for a given platform",
61+
Run: func(cmd *cobra.Command, args []string) {
62+
initPrepareEngineParameters("windows")
63+
subcommandPrepare("windows")
64+
},
65+
}
66+
67+
func initPrepareEngineParameters(targetOS string) {
68+
validatePrepareEngineParameters(targetOS)
69+
if prepareDebugMode {
70+
prepareBuildModes = append(prepareBuildModes, build.DebugMode)
71+
}
72+
if prepareReleaseMode {
73+
prepareBuildModes = append(prepareBuildModes, build.ReleaseMode)
74+
}
75+
if prepareProfileMode {
76+
prepareBuildModes = append(prepareBuildModes, build.ProfileMode)
77+
}
78+
}
79+
80+
func validatePrepareEngineParameters(targetOS string) {
81+
numberOfPrepareModeFlagsSet := 0
82+
for _, flag := range []bool{prepareProfileMode, prepareProfileMode, prepareDebugMode} {
83+
if flag {
84+
numberOfPrepareModeFlagsSet++
85+
}
86+
}
87+
if numberOfPrepareModeFlagsSet > 1 {
88+
log.Errorf("Only one of --debug, --release or --profile can be set at one time")
89+
os.Exit(1)
90+
}
91+
if numberOfPrepareModeFlagsSet == 0 {
92+
prepareDebugMode = true
93+
}
94+
if targetOS == "darwin" && runtime.GOOS != targetOS && (prepareReleaseMode || prepareProfileMode) {
95+
log.Errorf("It is not possible to prepare the flutter engine in release mode for darwin using docker")
96+
os.Exit(1)
97+
}
98+
}
99+
100+
func subcommandPrepare(targetOS string) {
101+
for _, mode := range prepareBuildModes {
102+
enginecache.ValidateOrUpdateEngine(targetOS, prepareCachePath, prepareEngineVersion, mode)
103+
}
104+
}

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
6767
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6868
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
6969
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
70-
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
7170
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
7271
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
7372
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -151,8 +150,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6
151150
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
152151
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
153152
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
154-
github.com/otiai10/copy v1.5.1 h1:a/cs2E1/1V0az8K5nblbl+ymEa4E11AfaOLMar8V34w=
155-
github.com/otiai10/copy v1.5.1/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
156153
github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ=
157154
github.com/otiai10/copy v1.6.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
158155
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
@@ -201,7 +198,6 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
201198
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
202199
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
203200
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
204-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
205201
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
206202
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
207203
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
@@ -319,7 +315,6 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn
319315
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
320316
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
321317
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
322-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
323318
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
324319
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
325320
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=

0 commit comments

Comments
 (0)