Git Product home page Git Product logo

Comments (20)

thomwiggers avatar thomwiggers commented on September 23, 2024

I need the equivalent of https://doc.rust-lang.org/nightly/cargo/reference/specifying-dependencies.html#platform-specific-dependencies for features but it does not seem to exist yet (rust-lang/cargo#7914 (comment))

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

I need the equivalent of ...

To fix the OpenSSL issue on Windows, you can swap

if cfg!(feature = "openssl") {
out for

if cfg!(all(not(windows), feature = "openssl")) {

Is there a reason why static linking is enabled by default? Is it needed for your use case of liboqs-rust? I am unable to get this crate to compile on Windows, even with the default features disabled (I have no idea how the Windows CI passes currently). I've also asked others to try and they've also encountered difficulties. Note that liboqs itself compiles and the binaries run fine in Visual Studio. I also tested the liboqs.sln project that liboqs-sys generates as part of the build process in Visual Studio and it compiles fine as well.

Every time I compile liboqs-rust, even with OpenSSL disabled, I'm met with a linker error:

Compiling oqs-sys v0.3.0
   Compiling oqs v0.3.0
error: could not find native static library `oqs`, perhaps an -L flag is missing?

error: aborting due to previous error

error: could not compile `oqs-sys`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed

The only way the linking bug seems to fix itself is by changing this

println!("cargo:rustc-link-lib=static=oqs");
to not statically link:

println!("cargo:rustc-link-lib=oqs");

Tl;dr I'm having a hard time seeing how something with the build script is not wrong currently. If the stuff above is acceptable and desired, I'll open a PR off my testing branch.

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

if cfg!(all(not(windows), feature = "openssl")) {

I don't want to force-disable openssl on Windows, because if you do set up everything correctly, it works fine, and gives you access to accelerated versions of a bunch of primitives that make up between 20% to up to 90% of the runtime of some schemes.

I have no idea how the Windows CI passes currently

Presumably it's set up differently.

I'm not sure if println!("cargo:rustc-link-lib=static=oqs"); should indeed be static, I've mainly just copied that from some example somewhere initially and as I only run Linux, it's obviously not been a problem for me. I'd merge a PR that removes static= assuming it passes CI.

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

I don't want to force-disable openssl on Windows

I should add that if you don't want to have openssl in your crate, you can simply specify no-default-features and use a build.rs that emits the openssl feature where it is supported.

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

I dont want to force disable OpenSSL on Windows

I don’t think it works at all from my testing. This line in the primary C library explodes MSVC if you try to enable OpenSSL. And as stated originally, liboqs unconditionally disables compiling OpenSSL on Windows. None of its CI jobs even attempt to enable it either.

no-default-features

That would only be a solution if the static linking bug was fixed. But, due to the liboqs’ behavior with OpenSSL and Windows I think its not very important, at least until the C code is patched to support MSVC.

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

This line in the primary C library explodes MSVC if you try to enable OpenSSL.

That file should not be compiled though... It's only for tests against NIST's Known-Answer Tests

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

Well, it seems to be anyway. These are the errors that MSVC gives when you try to compile main on Windows with OpenSSL, sorry I didn't share these sooner:

 liboqs-rust\oqs-sys\liboqs\src\common\rand\rand_nist.c(36,15): error C2143: syntax error: missing ')' before '(' [liboqs-rust\target\debug\build\oqs-sys-45a0b0771bd42382\out\build\src\common\common.vcxproj]
  liboqs-rust\oqs-sys\liboqs\src\common\rand\rand_nist.c(36,24): error C2059: syntax error: ')' [liboqs-rust\target\debug\build\oqs-sys-45a0b0771bd42382\out\build\src\common\common.vcxproj]
  liboqs-rust\oqs-sys\liboqs\src\common\rand\rand_nist.c(36,25): error C2059: syntax error: ')' [liboqs-rust\target\debug\build\oqs-sys-45a0b0771bd42382\out\build\src\common\common.vcxproj]
  liboqs-rust\oqs-sys\liboqs\src\common\rand\rand_nist.c(37,13): error C2143: syntax error: missing ')' before 'type' [liboqs-rust\target\debug\build\oqs-sys-45a0b0771bd42382\out\build\src\common\common.vcxproj]
  liboqs-rust\oqs-sys\liboqs\src\common\rand\rand_nist.c(37,13): error C2091: function returns function [liboqs-rust\target\debug\build\oqs-sys-45a0b0771bd42382\out\build\src\common\common.vcxproj]
  liboqs-rust\oqs-sys\liboqs\src\common\rand\rand_nist.c(37,32): error C2085: 'handleErrors': not in formal parameter list [liboqs-rust\target\debug\build\oqs-sys-45a0b0771bd42382\out\build\src\common\common.vcxproj]
  liboqs-rust\oqs-sys\liboqs\src\common\rand\rand_nist.c(37,32): error C2143: syntax error: missing ';' before '{' [liboqs-rust\target\debug\build\oqs-sys-45a0b0771bd42382\out\build\src\common\common.vcxproj]

I tried changing the function to decorated like this and it looked to of fixed it.

#ifdef OQS_USE_OPENSSL
# ifdef __GNUC__
__attribute__((noreturn))
# elif defined(_MSC_VER)
__declspec(noreturn)

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

I'm running into problems if I don't statically link liboqs :(

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

Are you building liboqs directly? How are you building liboqs? You should be passing -DOQS_BUILD_ONLY_LIB=Yes if you want to match what this crate is doing.

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

I’m not building it directly. I am attempting to compile it through this Rust crate. Every error I’ve posted has come from the output of oqs-sys‘ build script using cargo build.

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

That's definitely weird...

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

I've figured out why CI was not having problems: CI wasn't running tests on Windows at all 🙈 (#30)

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

That would explain a bit. Can't believe I didn't see that sooner D:

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

Yeah Github Action's workflow syntax is rather sensitive to these problems where you define matrix vars but don't actually use them

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

The branch in #30 works on a Windows 10 Dev VM (from Microsoft) that's up-to-date; unfortunately I am having trouble updating the Github Actions VM to use a more recent Windows SDK.

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

I've managed to figure out the problem in #30, so you could try that branch. Don't forget to make sure you update the submodule if you check out that branch.

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

I checked out the branch and confirmed it fixes the linking issue. My tests also run after configuring the stack size.

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

This is very unrelated, but it would be cool if we could get this liboqs-rust to work with the openssl-sys crate. To get this compiling, the build.rs logic has duplicated some of the searching and link logic of that crate. It also has a vendored feature to get around the headaches of needing OpenSSL present on your system.

Its probably not possible, at least not easily, since liboqs links to it, but it would be a great feature. I tried tinkering with it but the linker on both Linux and Windows isn't happy with the idea.

from liboqs-rust.

thomwiggers avatar thomwiggers commented on September 23, 2024

The main problem is the openssl-sys crate build.rs does not expose the location where it found OpenSSL. Otherwise I could pass it on to liboqs — I did look into this.

from liboqs-rust.

BlackHoleFox avatar BlackHoleFox commented on September 23, 2024

Ah, that sucks :/ Good to know though.

from liboqs-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.