Skip to content

Commit 4abedfa

Browse files
committed
solana: deterministic builds via Docker
1 parent 39d67c0 commit 4abedfa

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ docker_build(
1919
ref = "solana-contract",
2020
context = ".wormhole/solana",
2121
dockerfile = ".wormhole/solana/Dockerfile",
22-
target = "builder",
22+
target = "dev-builder",
2323
build_args = {"BRIDGE_ADDRESS": "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"}
2424
)
2525
# Solana deploy

solana/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
**/*.rs.bk
33
node_modules
44
test-ledger
5+
artifacts-*

solana/Dockerfile

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ COPY solana/Cargo.toml Cargo.toml
88
COPY solana/modules modules
99
COPY solana/programs programs
1010
COPY solana/rust-toolchain rust-toolchain
11+
COPY solana/scripts scripts
1112

1213
ENV RUST_BACKTRACE=1
1314

14-
FROM anchor AS builder
15+
FROM anchor AS dev-builder
1516

1617
RUN mkdir -p /opt/solana/deps
1718

@@ -37,8 +38,19 @@ COPY --from=solana-contract /opt/solana/deps/cpi_poster.so /opt/solana/deps/cpi_
3738
COPY --from=solana-contract /opt/solana/deps/mpl_token_metadata.so /opt/solana/deps/mpl_token_metadata.so
3839
COPY --from=solana-contract /opt/solana/deps/wormhole_migration.so /opt/solana/deps/wormhole_migration.so
3940

40-
COPY sdk ../sdk
4141
COPY solana/Makefile Makefile
42-
COPY solana/scripts scripts
43-
4442
RUN make target/idl/example_native_token_transfers.json
43+
COPY solana/ts ts
44+
45+
FROM anchor as mainnet-builder
46+
47+
ARG SOLANA_NETWORK
48+
RUN [ -z "$SOLANA_NETWORK" ] && echo "SOLANA_NETWORK is required" && exit 1 || echo "SOLANA_NETWORK=$SOLANA_NETWORK"
49+
50+
RUN --mount=type=cache,target=/opt/solana/deps/target,id=build_anchor_ntt_target \
51+
--mount=type=cache,target=/usr/local/cargo/registry,id=cargo_registry \
52+
--mount=type=cache,target=.anchor,id=anchor_cache \
53+
anchor build --arch sbf -- --no-default-features --features $SOLANA_NETWORK
54+
55+
FROM scratch as export
56+
COPY --from=mainnet-builder /usr/src/solana/target/deploy /

solana/Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ idl: target/idl/example_native_token_transfers.json
2929
node_modules: package-lock.json
3030
npm ci
3131

32+
.PHONY: artifacts-mainnet
33+
artifacts-mainnet: NETWORK=mainnet
34+
artifacts-mainnet: _artifacts
35+
mv _artifacts $@
36+
37+
.PHONY: artifacts-solana-devnet
38+
artifacts-solana-devnet: NETWORK=solana-devnet
39+
artifacts-solana-devnet: _artifacts
40+
mv _artifacts $@
41+
42+
.PHONY: artifacts-tilt-devnet
43+
artifacts-tilt-devnet: NETWORK=tilt-devnet
44+
artifacts-tilt-devnet: _artifacts
45+
mv _artifacts $@
46+
47+
.PHONY: _artifacts
48+
_artifacts:
49+
rm -rf $@
50+
DOCKER_BUILDKIT=1 cd .. && docker build -f solana/Dockerfile --build-arg="SOLANA_NETWORK=$(NETWORK)" -t export -o solana/$@ .
51+
@cd $@ && ls | xargs sha256sum > checksums.txt
52+
@cat $@/checksums.txt
53+
3254
.PHONY: clean
3355
clean:
3456
anchor clean

solana/README.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
# Solana
1+
# Solana
22

33
## Prequisities
44

55
Ensure that you are using the correct version of the Solana and Anchor CLI tools by consulting `Anchor.toml`.
66
```toml
77
[toolchain]
88
anchor_version = "0.29.0" # CLI
9-
solana_version = "1.17.2"
9+
solana_version = "1.18.10"
1010
```
1111

12-
You will also need to install the toolchain listed in `rust-toolchain`.
12+
You will also need `rustup`.
13+
14+
For building the mainnet binaries, the only requirements are `docker` and `make`:
15+
16+
```sh
17+
make artifacts-mainnet
18+
```
19+
20+
which will produce the object files into the `artifacts-mainnet` directory.
21+
This is the recommended way of building the binaries as it results in deterministic builds.
22+
For Solana devnet builds, or local testing builds, use the
23+
24+
``` sh
25+
make artifacts-solana-devnet
26+
make artifacts-tilt-devnet
27+
```
28+
29+
commands.
1330

1431
## Design Overview
1532

@@ -104,4 +121,4 @@ To ensure the SDK has the generated IDL, run the tests with the make command:
104121

105122
```sh
106123
make anchor-test
107-
```
124+
```

0 commit comments

Comments
 (0)