Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wasm build #421

Merged
merged 1 commit into from
Mar 30, 2022
Merged

Fix wasm build #421

merged 1 commit into from
Mar 30, 2022

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Mar 17, 2022

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

@TheBlueMatt
Copy link
Member

What happens if we just drop all the WASM32_* consts in stdio.h? Otherwise we'll need to not define them, just declare the extern and add another .c file which actually defines them and only build it in when building for wasm.

@tcharding
Copy link
Member Author

I'll digest that more thoroughly tomorrow and have a go. Cheers.

@cryptoquick
Copy link

Just wanted to leave a word of encouragement, @tcharding, the work you're doing here is very valuable.

@tcharding
Copy link
Member Author

tcharding commented Mar 18, 2022

Thanks man! For the record, I absolutely love working on this project :)

@tcharding tcharding marked this pull request as ready for review March 19, 2022 00:21
@reuvenpo
Copy link

reuvenpo commented Mar 22, 2022

Hi! Passing by because I'm having compilation issues with v0.22.1 and clang v10, but letting you know that earlier versions (namely v0.20.3) only worked with clang v10 when targeting wasm.

@tcharding
Copy link
Member Author

Noted! Thanks for the info @reuvenpo.

@@ -1,17 +0,0 @@
#include <stddef.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can delete the entire file I guess?

Copy link
Member Author

@tcharding tcharding Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it because I don't know why these files are there, stdlib.h is empty as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK @TheBlueMatt added them when he worked on wasm compatibility. They are included in the build-script but serve otherwise no purpose.

This may be an instance of Chesterton’s fence but I would honestly just try and delete them and if nothing breaks, you are good to go :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing it and build fails, FTR here is a portion of the error:

cargo:warning=In file included from depend/secp256k1/src/field.h:25:
cargo:warning=depend/secp256k1/src/util.h:16:10: fatal error: 'stdio.h' file not found
cargo:warning=#include <stdio.h>
cargo:warning=         ^~~~~~~~~
cargo:warning=1 error generated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting. Yeah that makes sense!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, if nothing breaks these files (or any parts of them you can) should definitely be removed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, I am pretty sure that #include should not be present upstream. cc @real-or-random

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created bitcoin-core/secp256k1#1095 to track this.

@elichai
Copy link
Member

elichai commented Mar 28, 2022

We added these align/size checks because wasm32 doesn't have a well-defined ABI.
Are we sure we want to remove those?
See #208

@apoelstra
Copy link
Member

Agreed, let's not remove them. But they should be in their own include, not stdio.h, which is included only from secp256k1.c and not the other binaries.

@tcharding
Copy link
Member Author

Total re-write, please see re-written PR description.

@@ -8,6 +8,7 @@

#include "../include/secp256k1.h"
#include "../include/secp256k1_preallocated.h"
#include "../../../wasm-sysroot/wasm.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should likely patch this by means of a .patch file that is automatically applied by vendor.sh otherwise this change will be gone with the next update of libsecp256k1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh coool, that will fix my unease mentioned in the commit message about patching vendored code :) Thanks man.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case you can also append -include ../../../wasm-sysroot/wasm.h to the command line of the C compiler (https://docs.rs/cc/latest/cc/struct.Build.html#method.flag), this works on gcc and clang at least.

@elichai
Copy link
Member

elichai commented Mar 29, 2022

Should this maybe just be a c file that we compile and link to? that way we don't need to include it anywhere.
and we anyway just use it for the symbols

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.
@tcharding
Copy link
Member Author

Force push is total re-write, please see updated PR description.

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean, thanks!
Can't see any blockers in this.

ACK bfd88db

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bfd88db

Huzzah! My local CI script passes once again.

@apoelstra
Copy link
Member

Thank you @elichai for explaining wtf was going on here.

@apoelstra apoelstra merged commit f7cae46 into rust-bitcoin:master Mar 30, 2022
@elichai
Copy link
Member

elichai commented Mar 30, 2022

post merge ACK bfd88db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants