Merge rust-bitcoin/rust-secp256k1#421: Fix wasm build

bfd88dbd6c Move WASM const definitions to a source file (Tobin Harding)

Pull request description:

  Total re-write ... again :)

  Currently we are defining the WASM integer size and alignments in the `stdio.h` header file, this is wrong because this file is included in the build by way of `build.rs` as well as by upstream `libsecp256k1`.

  Move WASM integer definitions to a `C` source file and build the file  into the binary if target is WASM.

  Fixes the first part of #419 (#422 does the second part).

  ### Note to reviewers

  I'm not exactly sure why the directory `was-sysroot` is named as it is or if the name is significant to `cargo` , please review carefully the directory tree changes.

  ```
  cd secp256k1-sys
  tree wasm
  wasm
  ├── wasm.c
  └── wasm-sysroot
             ├── stdio.h
             ├── stdlib.h
             └── string.h
  ```

ACKs for top commit:
  thomaseizinger:
    ACK bfd88dbd6c
  apoelstra:
    ACK bfd88dbd6c

Tree-SHA512: ba822b764fb5f74dfd22cc797f7e3f70440dbaabfe34e0475c796e0e5d88f2086bedb00a1ec765cce91bde6bb45130b9abe5d9289317d6c20f692c6ed711969e
This commit is contained in:
Andrew Poelstra 2022-03-30 16:37:16 +00:00
commit f7cae46fc7
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
6 changed files with 20 additions and 19 deletions

View File

@ -52,9 +52,10 @@ fn main() {
#[cfg(feature = "recovery")]
base_config.define("ENABLE_MODULE_RECOVERY", Some("1"));
// Header files. WASM only.
// WASM headers and size/align defines.
if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "wasm32" {
base_config.include("wasm-sysroot");
base_config.include("wasm/wasm-sysroot")
.file("wasm/wasm.c");
}
// secp256k1

View File

@ -1,17 +0,0 @@
#include <stddef.h>
#define alignof(type) offsetof (struct { char c; type member; }, member)
extern const unsigned char WASM32_INT_SIZE = sizeof(int);
extern const unsigned char WASM32_INT_ALIGN = alignof(int);
extern const unsigned char WASM32_UNSIGNED_INT_SIZE = sizeof(unsigned int);
extern const unsigned char WASM32_UNSIGNED_INT_ALIGN = alignof(unsigned int);
extern const unsigned char WASM32_SIZE_T_SIZE = sizeof(size_t);
extern const unsigned char WASM32_SIZE_T_ALIGN = alignof(size_t);
extern const unsigned char WASM32_UNSIGNED_CHAR_SIZE = sizeof(unsigned char);
extern const unsigned char WASM32_UNSIGNED_CHAR_ALIGN = alignof(unsigned char);
extern const unsigned char WASM32_PTR_SIZE = sizeof(void*);
extern const unsigned char WASM32_PTR_ALIGN = alignof(void*);

View File

17
secp256k1-sys/wasm/wasm.c Normal file
View File

@ -0,0 +1,17 @@
#include <stddef.h>
#define alignof(type) offsetof (struct { char c; type member; }, member)
const unsigned char WASM32_INT_SIZE = sizeof(int);
const unsigned char WASM32_INT_ALIGN = alignof(int);
const unsigned char WASM32_UNSIGNED_INT_SIZE = sizeof(unsigned int);
const unsigned char WASM32_UNSIGNED_INT_ALIGN = alignof(unsigned int);
const unsigned char WASM32_SIZE_T_SIZE = sizeof(size_t);
const unsigned char WASM32_SIZE_T_ALIGN = alignof(size_t);
const unsigned char WASM32_UNSIGNED_CHAR_SIZE = sizeof(unsigned char);
const unsigned char WASM32_UNSIGNED_CHAR_ALIGN = alignof(unsigned char);
const unsigned char WASM32_PTR_SIZE = sizeof(void*);
const unsigned char WASM32_PTR_ALIGN = alignof(void*);