Skip to content

Commit c8b4113

Browse files
committed
driver(build): update Makefile to build drivers as internal or external
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent f2cd7f0 commit c8b4113

File tree

12 files changed

+56
-21
lines changed

12 files changed

+56
-21
lines changed

Makefile

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ binaries: limactl helpers guestagents \
167167
################################################################################
168168
# _output/bin
169169
.PHONY: limactl lima helpers
170-
limactl: _output/bin/limactl$(exe) lima
170+
limactl: _output/bin/limactl$(exe) external-drivers lima
171171

172172
### Listing Dependencies
173173

@@ -241,18 +241,46 @@ endif
241241
# calls the native resolver library and not the simplistic version in the Go library.
242242
ENVS__output/bin/limactl$(exe) = CGO_ENABLED=1 GOOS="$(GOOS)" GOARCH="$(GOARCH)" CC="$(CC)"
243243

244+
LIMACTL_DRIVER_TAGS :=
245+
ifneq (,$(findstring vz,$(EXTERNAL_DRIVERS)))
246+
LIMACTL_DRIVER_TAGS += external_vz
247+
endif
248+
ifneq (,$(findstring qemu,$(EXTERNAL_DRIVERS)))
249+
LIMACTL_DRIVER_TAGS += external_qemu
250+
endif
251+
ifneq (,$(findstring wsl2,$(EXTERNAL_DRIVERS)))
252+
LIMACTL_DRIVER_TAGS += external_wsl2
253+
endif
254+
255+
GO_BUILDTAGS ?=
256+
GO_BUILDTAGS_LIMACTL := $(strip $(GO_BUILDTAGS) $(LIMACTL_DRIVER_TAGS))
257+
244258
_output/bin/limactl$(exe): $(LIMACTL_DEPS) $$(call force_build,$$@)
245-
# If the previous cross-compilation was for GOOS=windows, limactl.exe might still be present.
246259
ifneq ($(GOOS),windows) #
247260
@rm -rf _output/bin/limactl.exe
248261
else
249262
@rm -rf _output/bin/limactl
250263
endif
251-
$(ENVS_$@) $(GO_BUILD) -o $@ ./cmd/limactl
264+
$(ENVS_$@) $(GO_BUILD) -tags '$(GO_BUILDTAGS_LIMACTL)' -o $@ ./cmd/limactl
252265
ifeq ($(GOOS),darwin)
253266
codesign -f -v --entitlements vz.entitlements -s - $@
254267
endif
255268

269+
DRIVER_INSTALL_DIR := _output/libexec/lima
270+
271+
.PHONY: external-drivers
272+
external-drivers:
273+
ifneq ($(EXTERNAL_DRIVERS),)
274+
@mkdir -p $(DRIVER_INSTALL_DIR)
275+
@for drv in $(EXTERNAL_DRIVERS); do \
276+
echo "Building $$drv as external"; \
277+
$(GO_BUILD) -o $(DRIVER_INSTALL_DIR)/lima-driver-$$drv ./cmd/lima-driver-$$drv; \
278+
if [ "$$drv" = "vz" ]; then \
279+
codesign -f -v --entitlements vz.entitlements -s - $(DRIVER_INSTALL_DIR)/lima-driver-vz; \
280+
fi; \
281+
done
282+
endif
283+
256284
LIMA_CMDS = $(sort lima lima$(bat)) # $(sort ...) deduplicates the list
257285
LIMA_DEPS = $(addprefix _output/bin/,$(LIMA_CMDS))
258286
lima: $(LIMA_DEPS)

cmd/lima-driver-qemu/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ import (
1010

1111
// To be used as an external driver for Lima.
1212
func main() {
13-
driver := qemu.New()
14-
server.Serve(driver)
13+
server.Serve(qemu.New())
1514
}

cmd/lima-driver-vz/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ import (
1212

1313
// To be used as an external driver for Lima.
1414
func main() {
15-
driver := vz.New()
16-
server.Serve(driver)
15+
server.Serve(vz.New())
1716
}

cmd/lima-driver-wsl2/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build windows && !no_wsl
1+
//go:build windows
22

33
// SPDX-FileCopyrightText: Copyright The Lima Authors
44
// SPDX-License-Identifier: Apache-2.0
@@ -12,6 +12,5 @@ import (
1212

1313
// To be used as an external driver for Lima.
1414
func main() {
15-
driver := wsl2.New()
16-
server.Serve(driver)
15+
server.Serve(wsl2.New())
1716
}

cmd/limactl/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"github.com/lima-vm/lima/pkg/debugutil"
1919
"github.com/lima-vm/lima/pkg/driver/external/server"
20-
_ "github.com/lima-vm/lima/pkg/driver/qemu" // register qemu driver for all platforms
2120
"github.com/lima-vm/lima/pkg/fsutil"
2221
"github.com/lima-vm/lima/pkg/osutil"
2322
"github.com/lima-vm/lima/pkg/store/dirnames"

cmd/limactl/main_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//go:build darwin && !no_vz
1+
//go:build !external_vz
22

33
// SPDX-FileCopyrightText: Copyright The Lima Authors
44
// SPDX-License-Identifier: Apache-2.0
55

66
package main
77

88
// Import vz driver to register it in the registry on darwin.
9-
// import _ "github.com/lima-vm/lima/pkg/driver/vz"
9+
import _ "github.com/lima-vm/lima/pkg/driver/vz"

cmd/limactl/main_qemu.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !external_qemu
2+
3+
// SPDX-FileCopyrightText: Copyright The Lima Authors
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package main
7+
8+
// Import qemu driver to register it in the registry on all platforms.
9+
import _ "github.com/lima-vm/lima/pkg/driver/qemu"

cmd/limactl/main_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build windows && !no_wsl
1+
//go:build !external_wsl2
22

33
// SPDX-FileCopyrightText: Copyright The Lima Authors
44
// SPDX-License-Identifier: Apache-2.0

pkg/driver/qemu/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !external_qemu
2+
13
// SPDX-FileCopyrightText: Copyright The Lima Authors
24
// SPDX-License-Identifier: Apache-2.0
35

pkg/driver/vz/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build darwin && !no_vz
1+
//go:build darwin && !external_vz
22

33
// SPDX-FileCopyrightText: Copyright The Lima Authors
44
// SPDX-License-Identifier: Apache-2.0

0 commit comments

Comments
 (0)