boringtun icon indicating copy to clipboard operation
boringtun copied to clipboard

Shared library is not built since v0.5.0

Open RandoMan70 opened this issue 1 year ago • 1 comments

As soon as refactoring around workspace is done cargo does not build platform-specific shared and static library anymore. If I add required crate-types for libraries in boringtun/Cargo.toml it builds dynamic and static libraries, but does not include FFI calls there, so library can't be linked anymore. Probably I'm doing something wrong, I'm not a Rust developer, please, help me to get working shared library with expected bindings.

RandoMan70 avatar Aug 06 '22 07:08 RandoMan70

I think you should add --features=ffi-bindings to your cargo build command.

For example, if you are building the library for Windows platform, then you can look at my fork. Check the lines added to boringtun/Cargo.toml and .cargo/config.toml.

And here is the build script to build the static libraries:

cargo build --target=i686-pc-windows-msvc --lib --features=ffi-bindings
cargo build --target=i686-pc-windows-msvc --lib --release --features=ffi-bindings
cargo build --target=x86_64-pc-windows-msvc --lib --features=ffi-bindings
cargo build --target=x86_64-pc-windows-msvc --lib --release --features=ffi-bindings

Note that it also includes a slight modification to mod.rs to randomize the low byte of the session ID. I came across a DPI that checks this byte value (it starts at 0 and increments by one for each successive handshake) to identify the WireGuard protocol and block the handshake.

wiresock avatar Aug 07 '22 11:08 wiresock

@wiresock still doesn't work for me, there are numerous errors when compiling. what version of rust is required to build?

spylogsster avatar Aug 15 '22 18:08 spylogsster

@spylogsster I recently updated to the latest and successfully rebuilt the static libraries. What platform are you trying to build?

wiresock avatar Aug 15 '22 19:08 wiresock

cargo build --target=x86_64-pc-windows-msvc --lib --release --features=ffi-bindings

spylogsster avatar Aug 15 '22 19:08 spylogsster

@spylogsster Have you modified boringtun/Cargo.toml and .cargo/config.toml?

wiresock avatar Aug 15 '22 19:08 wiresock

@wiresock building your fork, branch win_stat_lib_with_rand

fork\boringtun>cargo build --target=x86_64-pc-windows-msvc --lib --release --features=ffi-bindings
   Compiling cfg-if v1.0.0
   Compiling subtle v2.4.1
   Compiling cc v1.0.73
   Compiling cpufeatures v0.2.2
   Compiling smallvec v1.9.0
   Compiling opaque-debug v0.3.0
   Compiling byteorder v1.4.3
   Compiling once_cell v1.13.0
   Compiling scopeguard v1.1.0
   Compiling ip_network_table-deps-treebitmap v0.5.0
   Compiling untrusted v0.7.1
   Compiling spin v0.5.2
   Compiling ip_network v0.4.1
   Compiling pin-project-lite v0.2.9
   Compiling hex v0.4.3
   Compiling base64 v0.13.0
   Compiling untrusted v0.9.0
   Compiling typenum v1.15.0
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-pc-windows-msvc` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc`

error[E0463]: can't find crate for `compiler_builtins`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `cfg-if` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0463]: can't find crate for `alloc`
  --> C:\Users\spylo\.cargo\registry\src\github.com-1ecc6299db9ec823\smallvec-1.9.0\src\lib.rs:87:1
   |
87 | pub extern crate alloc;
   | ^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `core`
 --> C:\Users\spylo\.cargo\registry\src\github.com-1ecc6299db9ec823\opaque-debug-0.3.0\src\lib.rs:5:1
  |
5 | pub extern crate core as __core;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
  |
  = note: the `x86_64-pc-windows-msvc` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc`

rustup target add x86_64-pc-windows-msvc doesnt help

spylogsster avatar Aug 16 '22 13:08 spylogsster

on mac cross-compiling stuck with error: failed to run custom build command for ring v0.16.20``

spylogsster avatar Aug 16 '22 13:08 spylogsster

You just have to read the compiler log:

error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-pc-windows-msvc` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc`

You don't have x86_64-pc-windows-msvc target installed. Add it by running rustup target add x86_64-pc-windows-msvc

wiresock avatar Aug 16 '22 14:08 wiresock

@wiresock I actually mentioned it in the message above, unfortunatelly it doesnt help

spylogsster avatar Aug 16 '22 14:08 spylogsster

Weird... What was an output from the rustup target add x86_64-pc-windows-msvc?

wiresock avatar Aug 16 '22 14:08 wiresock

fork\boringtun>rustup target add x86_64-pc-windows-msvc
info: component 'rust-std' for target 'x86_64-pc-windows-msvc' is up to date

spylogsster avatar Aug 16 '22 14:08 spylogsster

@spylogsster we re-added some flags to Cargo.toml. Try using the latest on master.

Noah-Kennedy avatar Aug 16 '22 15:08 Noah-Kennedy

@Noah-Kennedy same result on latest master

spylogsster avatar Aug 16 '22 16:08 spylogsster

maybe this could help:

boringtun>rustup component list --installed
cargo-x86_64-pc-windows-msvc
clippy-x86_64-pc-windows-msvc
rust-docs-x86_64-pc-windows-msvc
rust-std-x86_64-pc-windows-msvc
rustc-x86_64-pc-windows-msvc
rustfmt-x86_64-pc-windows-msvc

spylogsster avatar Aug 16 '22 16:08 spylogsster

on mac cross-compiling stuck with error: failed to run custom build command for ring v0.16.20``

Cross-compiling ring generally doesn't work. Since boringtun depends on in, you'll likely have to build on the target platform.

rillian avatar Aug 16 '22 16:08 rillian

https://github.com/cloudflare/boringtun/issues/301#issuecomment-1216628130 this log from windows

spylogsster avatar Aug 16 '22 16:08 spylogsster

@spylogsster if this issue is specific to cross compiltion, that is handled under #252. Does it work when not cross-compiling?

Noah-Kennedy avatar Aug 16 '22 16:08 Noah-Kennedy

@Noah-Kennedy https://github.com/cloudflare/boringtun/issues/301#issuecomment-1216628130 this logs from windows.

spylogsster avatar Aug 16 '22 16:08 spylogsster

@spylogsster are you cross compiling or not here?

Noah-Kennedy avatar Aug 16 '22 16:08 Noah-Kennedy

Looks like issue was actually on my side with broken env for Rust. Built this on a new windows virtual machine from latest master. Thanks to everyone for help. Looks like this issue can be closed.

spylogsster avatar Aug 17 '22 09:08 spylogsster