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

OpenSSL issue when compiling on NetBSD #143

Closed
martintc opened this issue Mar 11, 2022 · 29 comments · Fixed by #145
Closed

OpenSSL issue when compiling on NetBSD #143

martintc opened this issue Mar 11, 2022 · 29 comments · Fixed by #145

Comments

@martintc
Copy link
Contributor

martintc commented Mar 11, 2022

I am working on trying to port comtrya over to NetBSD and ran into an initial issue in the build process. Look like it has an issue with the vendored version of openssl.

Here is the output:

error: failed to run custom build command for `openssl-sys v0.9.72`

Caused by:
  process didn't exit successfully: `/home/todd/Projects/comtrya/target/debug/build/openssl-sys-dede6734a7187c76/build-script-main` (exit status: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_NETBSD_OPENSSL_NO_VENDOR
  X86_64_UNKNOWN_NETBSD_OPENSSL_NO_VENDOR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
  OPENSSL_NO_VENDOR unset
  CC_x86_64-unknown-netbsd = None
  CC_x86_64_unknown_netbsd = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-unknown-netbsd = None
  CFLAGS_x86_64_unknown_netbsd = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running "perl" "./Configure" "--prefix=/home/todd/Projects/comtrya/target/debug/build/openssl-sys-235ad40d71f59b42/out/openssl-build/install" "no-dso" "no-shared" "no-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "BSD-x86_64" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64"
  Configuring OpenSSL version 1.1.1m (0x101010dfL) for BSD-x86_64
  Using os-specific seed configuration
  Creating configdata.pm
  Creating Makefile

  **********************************************************************
  ***                                                                ***
  ***   OpenSSL has been successfully configured                     ***
  ***                                                                ***
  ***   If you encounter a problem while building, please open an    ***
  ***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
  ***   and include the output from the following command:           ***
  ***                                                                ***
  ***       perl configdata.pm --dump                                ***
  ***                                                                ***
  ***   (If you are new to OpenSSL, you might want to consult the    ***
  ***   'Troubleshooting' section in the INSTALL file first)         ***
  ***                                                                ***
  **********************************************************************
  running "make" "depend"
  running "make" "build_libs"

  --- stderr
  make: illegal argument to -j -- must be positive integer!
  thread 'main' panicked at '


  Error building OpenSSL:
      Command: "make" "build_libs"
      Exit status: exit status: 1


      ', /home/todd/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-src-111.17.0+1.1.1m/src/lib.rs:479:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

OS: NetBSD 9.2
Arch: Amd64

I have also opened an issue on OpenSSL's github.

@kraileth
Copy link
Contributor

This has been the case for me as well. I could only ever get Comtrya built on FreeBSD by first editing Cargo.toml and removing the "vendored" feature from the openssl crate. Doing so resulted in a Comtrya binary that worked for me, however I have no idea what side effects it may cause (e.g. I have only ever used local manifests). Would be interesting to know the rationale for defining it this way in the first place and what a proper solution might be.

rawkode added a commit to rawkode/comtrya that referenced this issue Mar 12, 2022
I don't remember entirely why this was set to vendored, but I seem to recall it was when I added remote manifest support with Git. Sadly, comtrya#143 does seem to indicate this causes issues on BSD systems.

Let's try without and see what breaks
@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

Let's see what happens if I remove it 😮 #144

@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

OK. Looks like this was a problem because Windows doesn't have a system level OpenSSL to build with. I've told Cargo to only vendor on Windows.

I hope this helps. Should be merged when the tests pass.

rawkode added a commit that referenced this issue Mar 12, 2022
I don't remember entirely why this was set to vendored, but I seem to recall it was when I added remote manifest support with Git. Sadly, #143 does seem to indicate this causes issues on BSD systems.

Let's try without and see what breaks
@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

This fix has been merged to main. Going to close this issue, but please feel free to reopen if there are any further problems.

@rawkode rawkode closed this as completed Mar 12, 2022
@martintc
Copy link
Contributor Author

Sounds good, thanks! Kraileth had mentioned this to me over email and it worked. I hit another issue, but I don't think it is comtrya specific but mostly how NetBSD handled the shared object library for libssl.

@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

Earlier versions of Comtrya tried to avoid OpenSSL altogether by using ring, but it was rather unstable. I'll try again on Monday.

@martintc
Copy link
Contributor Author

martintc commented Mar 12, 2022

If you just want a reference from NetBSD, here is the terminal output. It compiles with not using the vendored version of openssl. But it hits a runtime issue.

image

The warning is for an import I have not started using yet that I will be using in the pkgin package provider to set everything up for the boostrap.

@rawkode rawkode reopened this Mar 12, 2022
@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

What does locate libssl.so return?

I may need to try and get a NetBSD VM running to test this myself, but one of the goals of Comtrya is to run everywhere; so I'm happy to help get this working

@kraileth
Copy link
Contributor

kraileth commented Mar 12, 2022

@martintc This is interesting. Are you building with Cargo.toml as is after the recent fix or did you modify anything?

At least for me on FreeBSD this does not work for some reason. I need to comment out the line openssl = { version = "0.10", features = ["vendored"] } even though it should only apply to windows.. Tried out replacing [target.'cfg(windows)'.dependencies] with [target.'cfg(target_os = "windows")'.dependencies] which I found mentioned on the net, placed the unix part before it and such - with no success so far.

Now FreeBSD certainly isn't Windows and I'm not sure what's going on with cargo there. Would be interesting to know if it works as intended on NetBSD.

@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

Damn, that's frustrating @kraileth. I'm going to need to dig in to this further. I am really surprised Cargo didn't respect that import definition

@kraileth
Copy link
Contributor

@rawkode I can offer you SSH access to a FreeBSD jail and a NetBSD VM with Rust and Git installed if it helps. Just drop me a mail with a public key if you want me to provide the two dev systems.

@martintc
Copy link
Contributor Author

martintc commented Mar 12, 2022

@kraileth and @rawkode

This is with the adjustment to Cargo.toml to removing the vendored version and just using openssl = '0.10'

image

What is look like is the linker is finding libssl.so.14 when it expects libssl.so.1.1. At least that was the jist I got from a chain of emails in the NetBSD mailing list. Looks like this issue was hit with firefox on NetBSD since firefox uses a lot of Rust code. One possible solution I saw was changing the path in the BSD Makefile in pkgsrc to help comtry/rust find the appropriate libssl during the linking phase.

Email from NetBSD mailing list

To see any changes to my fork for working on NetBSD

My working branch for NetBSD

@martintc
Copy link
Contributor Author

martintc commented Mar 12, 2022

Huh, interesting. I pulled the recent change from main into my NetBSD branch and yea, Cargo doesn't seem to be respecting the [target.cfg(unix).dependencies] so current it does not compile. I will probably revert that back.

Have removed those lines from my NetBSD branch. So now that branch compiles without error on NetBSD.

@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

@kraileth I've dropped it to you via Discord.

@rawkode
Copy link
Member

rawkode commented Mar 12, 2022

@martintc I've removed openssl in this PR #145

OpenSSL is actually a transitive dependency, so I don't actually need to list it.

I don't think this will help, but if you could test and let me know.

@martintc
Copy link
Contributor Author

@martintc I've removed openssl in this PR #145

OpenSSL is actually a transitive dependency, so I don't actually need to list it.

I don't think this will help, but if you could test and let me know.

Will do. I will give it a shot tonight on my lunch break and let you know

@martintc
Copy link
Contributor Author

@rawkode PR#145 builds successfully on NetBSD 9.2. Now, we just need to solve the missing libssl.so.1.1 issue.

Screen Shot 2022-03-13 at 12 21 15 AM

@rawkode
Copy link
Member

rawkode commented Mar 13, 2022

Ah. So it still won't run? Ok. I'll keep reading

@martintc
Copy link
Contributor Author

martintc commented Mar 13, 2022

Something I will test when I get a chance.

Looks like I have the library, it is just a matter of finding it during runtime. Looking at the cargo book (still newish to Rust), we may be able to link that library in during compile time like so:

cargo:rustc-link-lib=dylib=/usr/pkg/lib/libssl.so.1.1

Only issue I see here is that since it is located in /usr/pkg/lib this will require for pkgin to be bootstrapped before using comtrya. That is assuming it is a runtime dependency and not a compile time dependency.

Or something like this:

[target.x86_64-unknown-linux-gnu.foo]
rustc-link-search = ["/path/to/foo"]
rustc-link-lib = ["foo"]
root = "/path/to/foo"
key = "value"

With the appropriate paths needed.

@rawkode
Copy link
Member

rawkode commented Mar 13, 2022

@kraileth @martintc I just built Comtrya without openssl on a netbsd box provider by @kraileth and it worked, no libssl.so.1.1 issue

@rawkode
Copy link
Member

rawkode commented Mar 13, 2022

In the FreeBSD jail and the netbsd machine, I can successfully run:

cargo run -- https://github.com/comtrya/comtrya#main:examples

from the build of PR #145

@rawkode
Copy link
Member

rawkode commented Mar 13, 2022

@kraileth thanks for that jail, found another bug that's an easy fix 😀

#146

@martintc
Copy link
Contributor Author

Mhmm, wonder if it is because I wasn't providing options. Just
'Cargo run'

Awesome! I'll get to work on a package provider for pkgin then!

@rawkode
Copy link
Member

rawkode commented Mar 13, 2022

Best of luck. Feel free to jump on the Discord if you need any help or advice.

https://Rawkode.chat

There's a Comtrya channel 😀

@martintc
Copy link
Contributor Author

@rawkode Sounds good, I have joined the discord.

@martintc
Copy link
Contributor Author

martintc commented Mar 15, 2022

Pulled in the most recent changes in main into my development test and have been trying to run the examples/command/run.yaml and I am still getting the same issue.

CODE_OF_CONDUCT.md  Comtrya.gif         README.md           src
Cargo.lock          Justfile            deny.toml           target
Cargo.toml          LICENSE             examples            tests
localhost$ cargo run -- . -m examples/command/run.yaml
    Finished dev [unoptimized + debuginfo] target(s) in 0.64s
     Running `target/debug/comtrya . -m examples/command/run.yaml`
target/debug/comtrya: Shared object "libcrypto.so.1.1" not found
localhost$ cargo run -- --help
    Finished dev [unoptimized + debuginfo] target(s) in 0.56s
     Running `target/debug/comtrya --help`
target/debug/comtrya: Shared object "libcrypto.so.1.1" not found
localhost$ cargo run -- --manifests examples/command/run.yaml
    Finished dev [unoptimized + debuginfo] target(s) in 0.57s
     Running `target/debug/comtrya --manifests examples/command/run.yaml`
target/debug/comtrya: Shared object "libcrypto.so.1.1" not found
localhost$ cargo run -- examples/command/run.yaml
    Finished dev [unoptimized + debuginfo] target(s) in 0.55s
     Running `target/debug/comtrya examples/command/run.yaml`
target/debug/comtrya: Shared object "libcrypto.so.1.1" not found
localhost$ cargo run -- ./examples/command/run.yaml
    Finished dev [unoptimized + debuginfo] target(s) in 0.58s
     Running `target/debug/comtrya ./examples/command/run.yaml`
target/debug/comtrya: Shared object "libcrypto.so.1.1" not found
localhost$ cargo run -- https://github.com/comtrya/comtrya#main:examples
    Finished dev [unoptimized + debuginfo] target(s) in 0.65s
     Running `target/debug/comtrya 'https://github.com/comtrya/comtrya#main:examples'`
target/debug/comtrya: Shared object "libcrypto.so.1.1" not found

Well, it is slightly different now. Instead of complaining of libssl is not complains of libcrypto

@rawkode
Copy link
Member

rawkode commented Mar 15, 2022

Hmm. I wonder what's different about your netbsd box vs the VM @kraileth provided?

@martintc
Copy link
Contributor Author

Hmm. I wonder what's different about your netbsd box vs the VM @kraileth provided?

Are you using doas or sudo when when running?

@theowenyoung
Copy link

For, in a new macOS, run the binary:

 ./comtrya-x86_64-apple-darwin 
dyld[10842]: Library not loaded: /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib
  Referenced from: /Users/green/dotfiles/comtrya-x86_64-apple-darwin
  Reason: tried: '/usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib' (no such file), '/usr/local/lib/libssl.1.1.dylib' (no such file), '/usr/lib/libssl.1.1.dylib' (no such file)
zsh: abort      ./comtrya-x86_64-apple-darwin

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 a pull request may close this issue.

4 participants