Bläddra i källkod

contract: Clean up Makefiles

parazyd 2 år sedan
förälder
incheckning
a652375b08

+ 0 - 2
src/contract/consensus/.gitignore

@@ -1,2 +0,0 @@
-consensus_contract.wasm
-proof/*.zk.bin

+ 5 - 5
src/contract/consensus/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "darkfi-consensus-contract"
+name = "darkfi_consensus_contract"
 version = "0.4.1"
 authors = ["Dyne.org foundation <foundation@dyne.org>"]
 license = "AGPL-3.0-only"
@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
 blake3 = "1.5.0"
 darkfi-sdk = { path = "../../sdk" }
 darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
-darkfi-money-contract = { path = "../money", features = ["no-entrypoint"] }
+darkfi_money_contract = { path = "../money", features = ["no-entrypoint"] }
 thiserror = "1.0.50"
 
 # The following dependencies are used for the client API and
@@ -28,7 +28,7 @@ rand = { version = "0.8.5", optional = true }
 smol = "1.3.0"
 bs58 = "0.5.0"
 darkfi = {path = "../../../", features = ["tx", "blockchain"]}
-darkfi-money-contract = { path = "../money", features = ["client", "no-entrypoint"] }
+darkfi_money_contract = { path = "../money", features = ["client", "no-entrypoint"] }
 darkfi-contract-test-harness = {path = "../test-harness"}
 simplelog = "0.12.1"
 sled = "0.34.7"
@@ -44,8 +44,8 @@ no-entrypoint = []
 client = [
     "darkfi",
     "darkfi-serial/async",
-    "darkfi-money-contract/client",
-    "darkfi-money-contract/no-entrypoint",
+    "darkfi_money_contract/client",
+    "darkfi_money_contract/no-entrypoint",
 
     "rand",
     "chacha20poly1305",

+ 38 - 21
src/contract/consensus/Makefile

@@ -3,6 +3,19 @@
 # Cargo binary
 CARGO = cargo +nightly
 
+# Compile target for system binaries
+RUST_TARGET = $(shell rustc -Vv | grep '^host: ' | cut -d' ' -f2)
+# Uncomment when doing musl static builds
+#RUSTFLAGS = -C target-feature=+crt-static -C link-self-contained=yes
+
+# wasm build target
+WASM_TARGET = wasm32-unknown-unknown
+
+# Cargo package name
+PKGNAME = $(shell grep '^name = ' Cargo.toml | cut -d' ' -f3 | tr -d '"')
+# wasm contract binary
+WASM_BIN = $(PKGNAME:=.wasm)
+
 # zkas compiler binary
 ZKAS = ../../../zkas
 
@@ -12,42 +25,46 @@ PROOFS_BIN = $(PROOFS_SRC:=.bin)
 
 # wasm source files
 WASM_SRC = \
-	$(shell find src -type f) \
+	$(shell find src -type f -name '*.rs') \
 	$(shell find ../../sdk -type f -name '*.rs') \
 	$(shell find ../../serial -type f -name '*.rs')
 
-# wasm contract binary
-WASM_BIN = consensus_contract.wasm
-
-# Just compile the tests
-NO_RUN = "--no-run"
-
 all: $(WASM_BIN)
 
-$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
-	$(CARGO) build --release --package darkfi-consensus-contract --target wasm32-unknown-unknown
-	cp -f ../../../target/wasm32-unknown-unknown/release/darkfi_consensus_contract.wasm $@
-
 $(PROOFS_BIN): $(ZKAS) $(PROOFS_SRC)
 	$(ZKAS) $(basename $@) -o $@
 
+$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --target=$(WASM_TARGET) \
+	--release --package $(PKGNAME)
+	cp -f ../../../target/$(WASM_TARGET)/release/$@ $@
+
 test-stake-unstake: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-consensus-contract \
-		--test stake_unstake $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test stake_unstake
 
 test-genesis-stake-unstake: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-consensus-contract \
-		--test genesis_stake_unstake $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test genesis_stake_unstake
 
 test: test-genesis-stake-unstake test-stake-unstake
 
-test-no-run:
-	$(MAKE) test-genesis-stake-unstake ARGS=$(NO_RUN)
-	$(MAKE) test-stake-unstake ARGS=$(NO_RUN)
+clippy: all
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client --tests
 
 clean:
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME)
 	rm -f $(PROOFS_BIN) $(WASM_BIN)
 
-.PHONY: all test-genesis-stake-unstake test-stake-unstake test clean
+.PHONY: all test-genesis-stake-unstake test-stake-unstake test clippy clean

+ 0 - 2
src/contract/dao/.gitignore

@@ -1,2 +0,0 @@
-dao_contract.wasm
-proof/*.zk.bin

+ 5 - 5
src/contract/dao/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "darkfi-dao-contract"
+name = "darkfi_dao_contract"
 version = "0.4.1"
 authors = ["Dyne.org foundation <foundation@dyne.org>"]
 license = "AGPL-3.0-only"
@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
 bs58 = "0.5.0"
 darkfi-sdk = { path = "../../sdk" }
 darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
-darkfi-money-contract = { path = "../money", features = ["no-entrypoint"] }
+darkfi_money_contract = { path = "../money", features = ["no-entrypoint"] }
 thiserror = "1.0.50"
 
 # The following dependencies are used for the client API and
@@ -27,7 +27,7 @@ rand = { version = "0.8.5", optional = true }
 [dev-dependencies]
 smol = "1.3.0"
 darkfi = {path = "../../../", features = ["tx", "blockchain"]}
-darkfi-money-contract = {path = "../money", features = ["client", "no-entrypoint"]}
+darkfi_money_contract = {path = "../money", features = ["client", "no-entrypoint"]}
 simplelog = "0.12.1"
 sled = "0.34.7"
 darkfi-contract-test-harness = {path = "../test-harness"}
@@ -43,8 +43,8 @@ no-entrypoint = []
 client = [
     "darkfi",
     "darkfi-serial/async",
-    "darkfi-money-contract/client",
-    "darkfi-money-contract/no-entrypoint",
+    "darkfi_money_contract/client",
+    "darkfi_money_contract/no-entrypoint",
 
     "rand",
     "chacha20poly1305",

+ 34 - 17
src/contract/dao/Makefile

@@ -3,6 +3,19 @@
 # Cargo binary
 CARGO = cargo +nightly
 
+# Compile target for system binaries
+RUST_TARGET = $(shell rustc -Vv | grep '^host: ' | cut -d' ' -f2)
+# Uncomment when doing musl static builds
+#RUSTFLAGS = -C target-feature=+crt-static -C link-self-contained=yes
+
+# wasm build target
+WASM_TARGET = wasm32-unknown-unknown
+
+# Cargo package name
+PKGNAME = $(shell grep '^name = ' Cargo.toml | cut -d' ' -f3 | tr -d '"')
+# wasm contract binary
+WASM_BIN = $(PKGNAME:=.wasm)
+
 # zkas compiler binary
 ZKAS = ../../../zkas
 
@@ -12,36 +25,40 @@ PROOFS_BIN = $(PROOFS_SRC:=.bin)
 
 # wasm source files
 WASM_SRC = \
-	$(shell find src -type f) \
+	$(shell find src -type f -name '*.rs') \
 	$(shell find ../../sdk -type f -name '*.rs') \
 	$(shell find ../../serial -type f -name '*.rs')
 
-# wasm contract binary
-WASM_BIN = dao_contract.wasm
-
-# Just compile the tests
-NO_RUN = "--no-run"
-
 all: $(WASM_BIN)
 
-$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
-	$(CARGO) build --release --package darkfi-dao-contract --target wasm32-unknown-unknown
-	cp -f ../../../target/wasm32-unknown-unknown/release/darkfi_dao_contract.wasm $@
-
 $(PROOFS_BIN): $(ZKAS) $(PROOFS_SRC)
 	$(ZKAS) $(basename $@) -o $@
 
+$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	cp -f ../../../target/$(WASM_TARGET)/release/$@ $@
+
 test-integration: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-dao-contract \
-		--test integration $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test integration
 
 test: test-integration
 
-test-no-run:
-	$(MAKE) test-integration ARGS=$(NO_RUN)
+clippy: all
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client --tests
 
 clean:
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME)
 	rm -f $(PROOFS_BIN) $(WASM_BIN)
 
-.PHONY: all test test-integration test-no-run clean
+.PHONY: all test-integration test clippy clean

+ 0 - 1
src/contract/deployooor/.gitignore

@@ -1 +0,0 @@
-deployooor_contract.wasm

+ 1 - 1
src/contract/deployooor/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "darkfi-deployooor-contract"
+name = "darkfi_deployooor_contract"
 version = "0.4.1"
 authors = ["Dyne.org foundation <foundation@dyne.org>"]
 license = "AGPL-3.0-only"

+ 31 - 9
src/contract/deployooor/Makefile

@@ -3,6 +3,19 @@
 # Cargo binary
 CARGO = cargo +nightly
 
+# Compile target for system binaries
+RUST_TARGET = $(shell rustc -Vv | grep '^host: ' | cut -d' ' -f2)
+# Uncomment when doing musl static builds
+#RUSTFLAGS = -C target-feature=+crt-static -C link-self-contained=yes
+
+# wasm build target
+WASM_TARGET = wasm32-unknown-unknown
+
+# Cargo package name
+PKGNAME = $(shell grep '^name = ' Cargo.toml | cut -d' ' -f3 | tr -d '"')
+# wasm contract binary
+WASM_BIN = $(PKGNAME:=.wasm)
+
 # zkas compiler binary
 ZKAS = ../../../zkas
 
@@ -12,23 +25,32 @@ PROOFS_BIN = $(PROOFS_SRC:=.bin)
 
 # wasm source files
 WASM_SRC = \
-	$(shell find src -type f) \
+	$(shell find src -type f -name '*.rs') \
 	$(shell find ../../sdk -type f -name '*.rs') \
 	$(shell find ../../serial -type f -name '*.rs')
 
-# wasm contract binary
-WASM_BIN = deployooor_contract.wasm
-
 all: $(WASM_BIN)
 
-$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
-	$(CARGO) build --release --package darkfi-deployooor-contract --target wasm32-unknown-unknown
-	cp -f ../../../target/wasm32-unknown-unknown/release/darkfi_deployooor_contract.wasm $@
-
 $(PROOFS_BIN): $(ZKAS) $(PROOFS_SRC)
 	$(ZKAS) $(basename $@) -o $@
 
+$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	cp -f ../../../target/$(WASM_TARGET)/release/$@ $@
+
+clippy: all
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client --tests
+
 clean:
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME)
 	rm -f $(PROOFS_BIN) $(WASM_BIN)
 
-.PHONY: all clean
+.PHONY: all clippy clean

+ 0 - 2
src/contract/money/.gitignore

@@ -1,2 +0,0 @@
-money_contract.wasm
-proof/*.zk.bin

+ 1 - 1
src/contract/money/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "darkfi-money-contract"
+name = "darkfi_money_contract"
 version = "0.4.1"
 authors = ["Dyne.org foundation <foundation@dyne.org>"]
 license = "AGPL-3.0-only"

+ 54 - 35
src/contract/money/Makefile

@@ -3,6 +3,19 @@
 # Cargo binary
 CARGO = cargo +nightly
 
+# Compile target for system binaries
+RUST_TARGET = $(shell rustc -Vv | grep '^host: ' | cut -d' ' -f2)
+# Uncomment when doing musl static builds
+#RUSTFLAGS = -C target-feature=+crt-static -C link-self-contained=yes
+
+# wasm build target
+WASM_TARGET = wasm32-unknown-unknown
+
+# Cargo package name
+PKGNAME = $(shell grep '^name = ' Cargo.toml | cut -d' ' -f3 | tr -d '"')
+# wasm contract binary
+WASM_BIN = $(PKGNAME:=.wasm)
+
 # zkas compiler binary
 ZKAS = ../../../zkas
 
@@ -12,64 +25,70 @@ PROOFS_BIN = $(PROOFS_SRC:=.bin)
 
 # wasm source files
 WASM_SRC = \
-	$(shell find src -type f) \
+	$(shell find src -type f -name '*.rs') \
 	$(shell find ../../sdk -type f -name '*.rs') \
 	$(shell find ../../serial -type f -name '*.rs')
 
-# wasm contract binary
-WASM_BIN = money_contract.wasm
-
-# Just compile the tests
-NO_RUN = "--no-run"
-
 all: $(WASM_BIN)
 
-$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
-	$(CARGO) build --release --package darkfi-money-contract --target wasm32-unknown-unknown
-	cp -f ../../../target/wasm32-unknown-unknown/release/darkfi_money_contract.wasm $@
-
 $(PROOFS_BIN): $(ZKAS) $(PROOFS_SRC)
 	$(ZKAS) $(basename $@) -o $@
 
+$(WASM_BIN): $(WASM_SRC) $(PROOFS_BIN)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	cp -f ../../../target/$(WASM_TARGET)/release/$@ $@
+
 test-integration: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-money-contract \
-		--test integration $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test integration
 
 test-mint-pay-swap: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-money-contract \
-		--test mint_pay_swap $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test mint_pay_swap
 
 test-txs-verification: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-money-contract \
-		--test txs_verification $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test txs_verification
 
 test-genesis-mint: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-money-contract \
-		--test genesis_mint $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test genesis_mint
 
 test-pow-reward: all
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-money-contract \
-		--test pow_reward $(ARGS)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test pow_reward
 
 bench:
-	$(CARGO) test --release --features=no-entrypoint,client \
-		--package darkfi-money-contract \
-		--test verification_bench $(FILTER)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) test --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client \
+		--test verification_bench
 
 test: test-integration test-mint-pay-swap test-txs-verification test-genesis-mint test-pow-reward
 
-test-no-run:
-	$(MAKE) test-integration ARGS=$(NO_RUN)
-	$(MAKE) test-mint-pay-swap ARGS=$(NO_RUN)
-	$(MAKE) test-txs-verification ARGS=$(NO_RUN)
-	$(MAKE) test-genesis-mint ARGS=$(NO_RUN)
+clippy: all
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clippy --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME) \
+		--features=no-entrypoint,client --tests
 
 clean:
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(WASM_TARGET) \
+		--release --package $(PKGNAME)
+	RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) clean --target=$(RUST_TARGET) \
+		--release --package $(PKGNAME)
 	rm -f $(PROOFS_BIN) $(WASM_BIN)
 
-.PHONY: all test-integration test-mint-pay-swap test-txs-verification test-genesis-mint bench test clean
+.PHONY: all test-integration test-mint-pay-swap test-txs-verification test-genesis-mint test-pow-reward bench test clippy clean

+ 4 - 4
src/contract/test-harness/Cargo.toml

@@ -9,10 +9,10 @@ edition = "2021"
 darkfi = {path = "../../../", features = ["validator"]}
 darkfi-sdk = {path = "../../../src/sdk"}
 darkfi-serial = {path = "../../../src/serial", features = ["crypto"]}
-darkfi-dao-contract = {path = "../dao", features = ["client", "no-entrypoint"]}
-darkfi-money-contract = {path = "../money", features = ["client", "no-entrypoint"]}
-darkfi-consensus-contract = {path = "../consensus", features = ["client", "no-entrypoint"]}
-darkfi-deployooor-contract = {path = "../deployooor", features = ["client", "no-entrypoint"]}
+darkfi_dao_contract = {path = "../dao", features = ["client", "no-entrypoint"]}
+darkfi_money_contract = {path = "../money", features = ["client", "no-entrypoint"]}
+darkfi_consensus_contract = {path = "../consensus", features = ["client", "no-entrypoint"]}
+darkfi_deployooor_contract = {path = "../deployooor", features = ["client", "no-entrypoint"]}
 
 blake3 = "1.5.0"
 bs58 = "0.5.0"