rustpq / pqcrypto

Rust Post-Quantum cryptography
212 stars 38 forks source link

Unable to compile for `wasm32-wasi` due to a typedef redefinition #45

Closed Sculas closed 1 year ago

Sculas commented 1 year ago

I've tried to compile pqcrypto to WASM using the instructions provided in WASM.md, but it only led me to this error:

warning: In file included from cfiles/fips202.c:10:
warning: In file included from /opt/wasi/wasi-sysroot/include/stdlib.h:29:
warning: /opt/wasi/wasi-sysroot/include/bits/alltypes.h:72:24: error: typedef redefinition with different types ('unsigned long' vs 'unsigned int')
warning: typedef unsigned _Addr size_t;
warning:                        ^
warning: /usr/lib/llvm-6.0/lib/clang/6.0.0/include/stddef.h:62:23: note: previous definition is here
warning: typedef __SIZE_TYPE__ size_t;
warning:                       ^
warning: 1 error generated.
warning: In file included from cfiles/aes.c:30:
warning: In file included from /opt/wasi/wasi-sysroot/include/string.h:32:
warning: /opt/wasi/wasi-sysroot/include/bits/alltypes.h:72:24: error: typedef redefinition with different types ('unsigned long' vs 'unsigned int')
warning: typedef unsigned _Addr size_t;
warning:                        ^
warning: /usr/lib/llvm-6.0/lib/clang/6.0.0/include/stddef.h:62:23: note: previous definition is here
warning: typedef __SIZE_TYPE__ size_t;
warning:                       ^
warning: 1 error generated.

error: failed to run custom build command for `pqcrypto-internals v0.2.4 (/home/user/projects/pqcrypto/pqcrypto-internals)`

env:

cargo:includepath=/home/user/projects/pqcrypto/pqcrypto-internals/include
TARGET = Some("wasm32-wasi")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-unknown-linux-gnu")
cargo:rerun-if-env-changed=CC_wasm32-wasi
CC_wasm32-wasi = None
cargo:rerun-if-env-changed=CC_wasm32_wasi
CC_wasm32_wasi = None
cargo:rerun-if-env-changed=TARGET_CC
TARGET_CC = None
cargo:rerun-if-env-changed=CC
CC = None
cargo:rerun-if-env-changed=CFLAGS_wasm32-wasi
CFLAGS_wasm32-wasi = None
cargo:rerun-if-env-changed=CFLAGS_wasm32_wasi
CFLAGS_wasm32_wasi = None
cargo:rerun-if-env-changed=TARGET_CFLAGS
TARGET_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")

There seems to be a clash between wasi-sysroot and clang and I'm not sure how to fix this. Any help is definitely appreciated! Either this is an issue on my end or the instructions provided are wrong/outdated.

Sculas commented 1 year ago

After quite some research, I found out that I had a version of LLVM/Clang installed which does not support WebAssembly (I suppose that's what you get for still running Ubuntu 18, heh). Retried it with Ubuntu 22.04, and it compiled without any problems. That solves the issue then.

thomwiggers commented 1 year ago

Perfect, because I don't know anything about WASM 😄