Skip to content

Commit

Permalink
chore: Add notes about common build problems in registry readme
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Dec 20, 2023
1 parent 0f2c1c9 commit 8a791a7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions registry/contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,43 @@ Add multisig deployment administration for Data team and SREs (DAO?).
./build.sh
near deploy --wasmFile ./target/wasm32-unknown-unknown/release/registry.wasm --accountId registry.queryapi.testnet
```

## Issues encountered while building

### Clang

The default version of `clang` on MacOS cannot build `wasm32-unknown-unknown`, therefore another version must be installed:
```sh
brew install llvm
```
and can be used via setting the `CC` environment variable:
```sh
CC="/opt/homebrew/Cellar/llvm/17.0.6/bin/clang" cargo build --target wasm32-unknown-unknown
```

### near-primitives usize
The `near-primitives` crate internally hard-codes `usize` as 8bits, this becomes a problem when targetting 32bit architecture (wasm32), which expects a `usize` of 4bits. To Bypass this issue the following patch can be applied to the local version of the crate in `~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/near-primitives-0.17.0/src/rand.rs`:
```patch
diff --git a/core/primitives/src/rand.rs b/core/primitives/src/rand.rs
index a79c8fd1b..17978a199 100644
--- a/core/primitives/src/rand.rs
+++ b/core/primitives/src/rand.rs
@@ -57,16 +57,7 @@ impl WeightedIndex {
}

pub fn sample(&self, seed: [u8; 32]) -> usize {
- let usize_seed = Self::copy_8_bytes(&seed[0..8]);
- let balance_seed = Self::copy_16_bytes(&seed[8..24]);
- let uniform_index = usize::from_le_bytes(usize_seed) % self.aliases.len();
- let uniform_weight = Balance::from_le_bytes(balance_seed) % self.weight_sum;
-
- if uniform_weight < self.no_alias_odds[uniform_index] {
- uniform_index
- } else {
- self.aliases[uniform_index] as usize
- }
+ 0
}

pub fn get_aliases(&self) -> &[u64] {
```

0 comments on commit 8a791a7

Please sign in to comment.