Skip to content

Commit 8599d10

Browse files
committed
build: isolate machine CGo artifacts
1 parent b527f97 commit 8599d10

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

Makefile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ endif
6161
# Go artifacts
6262
GO_ARTIFACTS := $(addprefix cartesi-rollups-,node cli evm-reader advancer validator claimer jsonrpc-api prt machine-tool)
6363

64+
# These artifacts embed the machine runtime and therefore require libcartesi.
65+
# Keep this list explicit: every other artifact is built with CGO_ENABLED=0, so
66+
# the normal build fails if a C dependency leaks into a pure service or tool.
67+
MACHINE_GO_ARTIFACTS := cartesi-rollups-node cartesi-rollups-advancer
68+
PURE_GO_ARTIFACTS := $(filter-out $(MACHINE_GO_ARTIFACTS),$(GO_ARTIFACTS))
69+
6470
# fixme(vfusco): path on all oses
6571
CGO_CFLAGS:= -I$(PREFIX)/include
6672
CGO_LDFLAGS:= -L$(PREFIX)/lib
@@ -70,17 +76,25 @@ export CGO_LDFLAGS
7076
CARTESI_TEST_MACHINE_IMAGES_PATH:= $(PREFIX)/share/cartesi-machine/images/
7177
export CARTESI_TEST_MACHINE_IMAGES_PATH
7278

73-
GO_BUILD_PARAMS := -ldflags "-s -w -X 'github.com/cartesi/rollups-node/internal/version.BuildVersion=$(ROLLUPS_NODE_VERSION)' -r $(PREFIX)/lib"
79+
GO_VERSION_LDFLAGS := -s -w -X 'github.com/cartesi/rollups-node/internal/version.BuildVersion=$(ROLLUPS_NODE_VERSION)'
80+
PURE_GO_BUILD_PARAMS := -ldflags "$(GO_VERSION_LDFLAGS)"
81+
MACHINE_GO_BUILD_PARAMS := -ldflags "$(GO_VERSION_LDFLAGS) -r $(PREFIX)/lib"
7482
ifeq ($(BUILD_TYPE),debug)
75-
GO_BUILD_PARAMS += -gcflags "all=-N -l"
83+
PURE_GO_BUILD_PARAMS += -gcflags "all=-N -l"
84+
MACHINE_GO_BUILD_PARAMS += -gcflags "all=-N -l"
7685
endif
7786

87+
# Tests and Go development tools cover machine packages, so retain the
88+
# machine-capable parameters for those existing recipes.
89+
GO_BUILD_PARAMS = $(MACHINE_GO_BUILD_PARAMS)
90+
7891
GO_TEST_PACKAGES ?= ./...
7992
GO_TEST_FLAGS ?=
8093

8194
VERBOSE ?=
8295
ifeq ($(VERBOSE),true)
83-
GO_BUILD_PARAMS += -v
96+
PURE_GO_BUILD_PARAMS += -v
97+
MACHINE_GO_BUILD_PARAMS += -v
8498
GO_TEST_FLAGS += -v
8599
endif
86100

@@ -147,9 +161,13 @@ env:
147161
# =============================================================================
148162
# Artifacts
149163
# =============================================================================
150-
$(GO_ARTIFACTS):
164+
$(PURE_GO_ARTIFACTS):
165+
@echo "Building pure Go artifact $@"
166+
CGO_ENABLED=0 go build $(PURE_GO_BUILD_PARAMS) ./cmd/$@
167+
168+
$(MACHINE_GO_ARTIFACTS):
151169
@echo "Building Go artifact $@"
152-
go build $(GO_BUILD_PARAMS) ./cmd/$@
170+
CGO_ENABLED=1 go build $(MACHINE_GO_BUILD_PARAMS) ./cmd/$@
153171

154172
tidy-go:
155173
@go mod tidy

0 commit comments

Comments
 (0)