Skip to content

Commit 1460e83

Browse files
committed
make: auto-install required scarb versions for contracts
1 parent e4e7585 commit 1460e83

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

Makefile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ AVNU_DIR := $(CONTRACTS_DIR)/avnu/contracts
3030
# The scarb version required by the AVNU contracts (no .tool-versions in that directory)
3131
AVNU_SCARB_VERSION := 2.11.4
3232

33-
# The `scarb` version that is required to compile the feature contracts in katana-contracts
34-
SCARB_VERSION := 2.8.4
33+
# The scarb version required by the main contracts.
34+
SCARB_VERSION := $(shell awk '$$1 == "scarb" { print $$2 }' $(CONTRACTS_DIR)/.tool-versions 2>/dev/null)
35+
36+
# The scarb version required by VRF contracts, if specified in its .tool-versions.
37+
VRF_SCARB_VERSION := $(shell if [ -f $(VRF_DIR)/.tool-versions ]; then awk '$$1 == "scarb" { print $$2 }' $(VRF_DIR)/.tool-versions; fi)
38+
39+
# All scarb versions needed for `make contracts`.
40+
SCARB_REQUIRED_VERSIONS := $(sort $(SCARB_VERSION) $(AVNU_SCARB_VERSION) $(VRF_SCARB_VERSION))
3541

3642
.DEFAULT_GOAL := usage
3743
.SILENT: clean
@@ -58,13 +64,20 @@ deps: install-scarb native-deps snos-deps
5864
@echo "All dependencies installed successfully."
5965

6066
install-scarb:
61-
@if scarb --version 2>/dev/null | grep -q "^scarb $(SCARB_VERSION)"; then \
62-
echo "scarb $(SCARB_VERSION) is already installed."; \
63-
else \
64-
echo "Installing scarb $(SCARB_VERSION)..."; \
65-
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v $(SCARB_VERSION) || { echo "Failed to install scarb!"; exit 1; }; \
66-
echo "scarb $(SCARB_VERSION) installed successfully."; \
67-
fi
67+
@command -v asdf >/dev/null 2>&1 || { echo "Error: asdf is required but not installed."; exit 1; }
68+
@asdf plugin list 2>/dev/null | grep -qx scarb || { \
69+
echo "Adding asdf scarb plugin..."; \
70+
asdf plugin add scarb || { echo "Failed to add asdf scarb plugin!"; exit 1; }; \
71+
}
72+
@for version in $(SCARB_REQUIRED_VERSIONS); do \
73+
if asdf where scarb "$$version" >/dev/null 2>&1; then \
74+
echo "scarb $$version is already installed."; \
75+
else \
76+
echo "Installing scarb $$version..."; \
77+
asdf install scarb "$$version" || { echo "Failed to install scarb $$version!"; exit 1; }; \
78+
echo "scarb $$version installed successfully."; \
79+
fi; \
80+
done
6881

6982
snos-artifacts: $(SNOS_OUTPUT)
7083
@echo "SNOS test artifacts prepared successfully."
@@ -79,7 +92,7 @@ build-explorer:
7992
@which bun >/dev/null 2>&1 || { echo "Error: bun is required but not installed. Please install bun first."; exit 1; }
8093
@$(MAKE) $(EXPLORER_UI_DIST)
8194

82-
contracts: $(CONTRACTS_BUILD_DIR)
95+
contracts: install-scarb $(CONTRACTS_BUILD_DIR)
8396

8497
# Generate the list of sources dynamically to make sure Make can track all files in all nested subdirs
8598
$(CONTRACTS_BUILD_DIR): $(shell find $(CONTRACTS_DIR) -type f)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ Follow the installation steps here: https://www.rust-lang.org/tools/install
1616

1717
### Scarb
1818

19-
Scarb is the Cairo package manager required for building the feature contracts in [`katana-contracts`](https://github.com/dojoengine/katana/tree/main/crates/contracts). The project requires a specific version of Scarb (2.8.4) to ensure compatibility.
19+
Scarb is the Cairo package manager required for building the feature contracts in [`katana-contracts`](https://github.com/dojoengine/katana/tree/main/crates/contracts). The project requires multiple specific Scarb versions (for main, VRF, and AVNU contracts) to ensure compatibility.
2020

21-
To install the required version of `scarb`:
21+
To install the required versions of `scarb`:
2222

2323
```bash
2424
make install-scarb
2525
```
2626

27-
This command will check if the correct version is already installed and only install it if necessary. For further information on `scarb`, check its [documentations page](https://docs.swmansion.com/scarb/docs.html).
27+
This command will check each required version and only install missing ones. `make contracts` also runs this check automatically before building contracts. For further information on `scarb`, check its [documentations page](https://docs.swmansion.com/scarb/docs.html).
2828

2929
### LLVM Dependencies
3030

0 commit comments

Comments
 (0)