Skip to content

Commit f1316f8

Browse files
Mohiiitheemankv
andauthored
Feat/cairo native on 0.14.0 (#832)
Co-authored-by: Heemank Verma <[email protected]>
1 parent 1cf0eef commit f1316f8

File tree

48 files changed

+6545
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6545
-253
lines changed

.github/actions/setup-rust/action.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,35 @@ runs:
5050
- name: Install dependencies
5151
shell: bash
5252
run: |
53-
sudo apt-get update -y && sudo apt-get install -y \
54-
clang llvm libudev-dev protobuf-compiler gcc g++ build-essential libssl-dev pkg-config curl wget git libgmp3-dev netcat-openbsd
53+
# Install LLVM 19 using Makefile target
54+
make install-llvm19 SUDO=sudo CODENAME=jammy
55+
56+
# Set LLVM environment variables for Cairo Native
57+
echo "MLIR_SYS_190_PREFIX=/usr/lib/llvm-19" >> $GITHUB_ENV
58+
echo "LLVM_SYS_191_PREFIX=/usr/lib/llvm-19" >> $GITHUB_ENV
59+
echo "TABLEGEN_190_PREFIX=/usr/lib/llvm-19" >> $GITHUB_ENV
60+
61+
# Configure linker search paths for Cairo Native runtime compilation
62+
echo "LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/lib:/lib/x86_64-linux-gnu:/lib" >> $GITHUB_ENV
63+
echo "LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/lib:/lib/x86_64-linux-gnu:/lib" >> $GITHUB_ENV
64+
65+
# Set up clang-19 as default clang for Cairo Native
66+
sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-19/bin/clang-19 100
67+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/lib/llvm-19/bin/clang++ 100
68+
69+
# Also set explicit compiler environment variables for Cairo Native runtime
70+
# Note: clang-19 handles both C and C++ compilation
71+
echo "CC=clang-19" >> $GITHUB_ENV
72+
echo "CXX=clang-19" >> $GITHUB_ENV
73+
74+
# Configure linker for clang - use lld-19 for Cairo Native runtime compilation
75+
# These flags are passed to clang when it invokes the linker
76+
echo "LDFLAGS=-fuse-ld=lld-19" >> $GITHUB_ENV
77+
78+
# Add LLVM 19 binaries to PATH
79+
echo "/usr/lib/llvm-19/bin" >> $GITHUB_PATH
5580
5681
- name: Setup mold
5782
uses: rui314/setup-mold@v1
5883
with:
59-
make-default: true
84+
make-default: false # Don't make mold the default - Cairo Native runtime compilation needs lld-19

.github/workflows/task-test-madara.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ jobs:
9494
PROPTEST_CASES: ${{ inputs.proptest-cases }}
9595
LLVM_PROFILE_FILE: "madara-%p-%m.profraw"
9696
ANVIL_URL: ${{ env.ANVIL_DEFAULT_URL }}
97+
# Cairo Native runtime compilation: use lld instead of mold
98+
LDFLAGS: "-fuse-ld=lld-19"
9799
run: |
98100
export COVERAGE_BIN=$(realpath target/release/madara)
99101
rm -f target/madara-* lcov.info

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ artifacts.tar.gz
2727
**/target/
2828
# These are backup files generated by rustfmt
2929
**/*.rs.bk
30+
# Cargo build cache files
31+
**/.rustc_info.json
32+
**/.future-incompat-report.json
3033

3134
# generated contracts for rpc-tests
3235
counter*/

Makefile

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Targets:
8080
Runs various code quality checks including formatting and linting.
8181

8282
- check Run code quality checks (fmt, clippy)
83+
Use NO_CAIRO_SETUP=1 to skip Cairo setup (e.g., make check NO_CAIRO_SETUP=1)
8384
- fmt Format code using taplo and cargo fmt
8485
- pre-push Run formatting and checks before committing / Pushing
8586

@@ -97,6 +98,7 @@ Targets:
9798
- help Show this help message
9899
- git-hook Setup git hooks path to .githooks
99100
- run-mock-atlantic-server Run the mock Atlantic server (options: PORT=4002 FAILURE_RATE=0.1 MAX_CONCURRENT_JOBS=5 BIND_ADDR=0.0.0.0)
101+
- install-llvm19 Install LLVM 19 for Cairo Native (Usage: make install-llvm19 [SUDO=sudo] [CODENAME=jammy|bookworm])
100102

101103
endef
102104
export HELP
@@ -244,7 +246,10 @@ build-orchestrator: setup-cairo
244246
@echo -e "$(PASS)✅ Build complete!$(RESET)"
245247

246248
.PHONY: check
247-
check: setup-cairo
249+
check:
250+
@if [ -z "$(NO_CAIRO_SETUP)" ]; then \
251+
$(MAKE) --silent setup-cairo; \
252+
fi
248253
@echo -e "$(DIM)Running code quality checks...$(RESET)"
249254
@echo -e "$(INFO)Running prettier check...$(RESET)"
250255
@npm install
@@ -552,3 +557,43 @@ setup-bootstrapper:
552557
@cp -r ./build-artifacts/bootstrapper/solidity/out/ ./bootstrapper-v2/contracts/ethereum/out/
553558
@cp -r ./build-artifacts/bootstrapper/cairo/target/ ./bootstrapper-v2/contracts/madara/target/
554559
@echo -e "$(PASS)Bootstrapper setup complete!$(RESET)"
560+
561+
# ============================================================================ #
562+
# LLVM 19 SETUP FOR CAIRO NATIVE #
563+
# ============================================================================ #
564+
565+
# Install LLVM 19 for Cairo Native
566+
# Usage: make install-llvm19 [SUDO=sudo] [CODENAME=jammy|bookworm]
567+
# SUDO=sudo - Use sudo for commands (default: empty, assumes root in Docker)
568+
# CODENAME=jammy|bookworm - Override OS detection (optional)
569+
.PHONY: install-llvm19
570+
install-llvm19:
571+
@echo "Installing LLVM 19 for Cairo Native..."
572+
@# Detect codename if not provided
573+
@if [ -z "$(CODENAME)" ]; then \
574+
if [ -f /etc/os-release ]; then \
575+
. /etc/os-release && CODENAME=$$VERSION_CODENAME; \
576+
elif grep -q "bookworm" /etc/debian_version 2>/dev/null || (grep -q "bookworm" /etc/os-release 2>/dev/null); then \
577+
CODENAME=bookworm; \
578+
elif grep -q "jammy" /etc/os-release 2>/dev/null; then \
579+
CODENAME=jammy; \
580+
else \
581+
CODENAME=jammy; \
582+
fi; \
583+
else \
584+
CODENAME=$(CODENAME); \
585+
fi; \
586+
echo "Using LLVM repository codename: $$CODENAME"; \
587+
$(if $(SUDO),sudo,) wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | $(if $(SUDO),sudo,) tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null; \
588+
$(if $(SUDO),sudo,) add-apt-repository -y "deb http://apt.llvm.org/$$CODENAME/ llvm-toolchain-$$CODENAME-19 main"; \
589+
$(if $(SUDO),sudo,) apt-get update -y; \
590+
$(if $(SUDO),sudo,) apt-get install -y \
591+
clang-19 llvm-19 llvm-19-dev llvm-19-runtime \
592+
libmlir-19-dev mlir-19-tools \
593+
libpolly-19-dev \
594+
liblld-19-dev \
595+
libc6-dev \
596+
$$(if [ "$$CODENAME" = "bookworm" ]; then echo "libstdc++-12-dev"; else echo "libstdc++-11-dev gcc-11 g++-11"; fi) \
597+
libudev-dev protobuf-compiler build-essential \
598+
libssl-dev pkg-config curl wget git libgmp3-dev netcat-openbsd; \
599+
echo "✅ LLVM 19 installed successfully"

build-artifacts/src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ fn get_artifacts(root: &RootDir, artifacts: &VersionFileArtifacts) -> Result<(),
132132
let version = get_version(artifacts)?;
133133
let image = format!("ghcr.io/madara-alliance/artifacts:{version}");
134134
println!("cargo::warning=fetching artifacts from image: {}", image);
135-
let container_name = format!("madara-artifacts-extractor-v{}", version);
135+
136+
// Use a unique container name to avoid conflicts in CI environments
137+
let timestamp = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs();
138+
let container_name = format!("madara-artifacts-extractor-v{}-{}", version, timestamp);
136139

137140
let root = &root.0;
138141

@@ -145,9 +148,24 @@ fn get_artifacts(root: &RootDir, artifacts: &VersionFileArtifacts) -> Result<(),
145148
.then_some(())
146149
.ok_or_else(|| err_handl(cmd, "Failed to download artifacts"))?;
147150

148-
// Remove any existing container with the same name
151+
// Clean up old artifact extractor containers to prevent accumulation
152+
// Match containers with pattern: madara-artifacts-extractor-v{version} or madara-artifacts-extractor-v{version}-{timestamp}
149153
let mut docker = std::process::Command::new("docker");
150-
docker.args(["rm", "-f", &container_name]).status().ok();
154+
docker.args(["ps", "-a", "--format", "{{.Names}}"]);
155+
if let Ok(output) = docker.output() {
156+
if output.status.success() {
157+
let containers = String::from_utf8_lossy(&output.stdout);
158+
let prefix = format!("madara-artifacts-extractor-v{}", version);
159+
for container in containers.lines() {
160+
let container = container.trim();
161+
// Match containers that start with the prefix (handles both with and without timestamp)
162+
if !container.is_empty() && container.starts_with(&prefix) {
163+
let mut rm_docker = std::process::Command::new("docker");
164+
rm_docker.args(["rm", "-f", container]).status().ok();
165+
}
166+
}
167+
}
168+
}
151169

152170
// Create extraction container with consistent name
153171
let mut docker = std::process::Command::new("docker");

configs/args/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,16 @@
112112
},
113113
"chain_config_override": {
114114
"overrides": []
115+
},
116+
"cairo_native_params": {
117+
"enable_native_execution": false,
118+
"native_max_memory_cache_size": 1000,
119+
"native_max_concurrent_compilations": 4,
120+
"native_compilation_timeout_secs": 300,
121+
"native_memory_cache_timeout_ms": 100,
122+
"native_disk_cache_load_timeout_secs": 2,
123+
"native_compilation_mode": "async",
124+
"native_enable_retry": true,
125+
"native_max_failed_compilations": 10000
115126
}
116127
}

madara/Cargo.lock

Lines changed: 34 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

madara/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
"node",
4+
"crates/client/cairo_native",
45
"crates/client/db",
56
"crates/client/exec",
67
"crates/client/sync",
@@ -96,6 +97,7 @@ mp-oracle = { path = "crates/primitives/oracle", default-features = false }
9697

9798
# Madara client
9899
mc-analytics = { path = "crates/client/analytics" }
100+
mc-class-exec = { path = "crates/client/cairo_native" }
99101
mc-telemetry = { path = "crates/client/telemetry" }
100102
mc-db = { path = "crates/client/db" }
101103
mc-exec = { path = "crates/client/exec" }
@@ -127,11 +129,9 @@ starknet = "0.17.0"
127129
starknet-types-core = { version = "0.2.1", default-features = false, features = [
128130
"hash",
129131
] }
130-
#
131-
#blockifier = { version = "=0.16.0-rc.0", features = ["node_api"] }
132-
#starknet_api = "=0.16.0-rc.0"
133132
blockifier = { git = "https://github.com/karnotxyz/sequencer", rev = "ff514ad8f39ac04302d0b176cef673a6a3820914", features = [
134133
"node_api",
134+
"cairo_native",
135135
] }
136136
starknet_api = { git = "https://github.com/karnotxyz/sequencer", rev = "ff514ad8f39ac04302d0b176cef673a6a3820914" }
137137
cairo-lang-starknet-classes = "2.12.3"

madara/Dockerfile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,28 @@ ENV RUSTC_WRAPPER=/bin/sccache
1919

2020
ENV WGET="-O- --timeout=10 --waitretry=3 --retry-connrefused --progress=dot:mega"
2121

22-
RUN apt-get update -y && apt-get install -y wget clang
22+
# Copy Makefile for LLVM installation
23+
COPY Makefile /tmp/Makefile
24+
25+
# Install LLVM 19 for Cairo Native support using Makefile target
26+
RUN apt-get update -y && apt-get install -y wget gnupg software-properties-common make && \
27+
cd /tmp && make -f Makefile install-llvm19 CODENAME=bookworm && \
28+
apt-get clean && rm -rf /var/lib/apt/lists/*
29+
30+
# Set LLVM environment variables for Cairo Native
31+
ENV MLIR_SYS_190_PREFIX=/usr/lib/llvm-19
32+
ENV LLVM_SYS_191_PREFIX=/usr/lib/llvm-19
33+
ENV TABLEGEN_190_PREFIX=/usr/lib/llvm-19
34+
ENV PATH="/usr/lib/llvm-19/bin:${PATH}"
35+
36+
# Set explicit compilers for Cairo Native runtime compilation
37+
# Note: clang-19 handles both C and C++ compilation
38+
ENV CC=clang-19
39+
ENV CXX=clang-19
40+
41+
# Configure linker search paths for Cairo Native runtime compilation
42+
ENV LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/lib:/lib/x86_64-linux-gnu:/lib
43+
ENV LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/lib:/lib/x86_64-linux-gnu:/lib
2344

2445
# Install Python 3.9
2546
RUN wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz \

0 commit comments

Comments
 (0)