taiki-e / upload-rust-binary-action

GitHub Action for building and uploading Rust binary to GitHub Releases.
Apache License 2.0
247 stars 22 forks source link

cross-compilation errors #47

Open juli1 opened 1 year ago

juli1 commented 1 year ago

I am trying to cross-compile a program. There is the matrix of all the values that I defined:

      matrix:
        include:
          # Ubuntu
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          # Mac OS
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: universal-apple-darwin
            os: macos-latest
          # Windows
          - target: x86_64-pc-windows-msvc
            os: windows-latest

When compiling for Linux, I get the following output below. I tried installing libssl-dev in the GitHub action but it does not solve the problem.

Any idea how to solve this?

Thanks!

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

Caused by:
  process didn't exit successfully: `/home/runner/work/stella/stella/target/release/build/openssl-sys-aae445923f341257/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR
  AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR
  AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_DIR
  AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: pkg-config has not been configured to support cross-compilation.

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.

  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-gnu
  $TARGET = aarch64-unknown-linux-gnu
  openssl-sys = 0.9.90

  ', /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.90/build/find_normal.rs:190:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
Error: Process completed with exit code 101.
taiki-e commented 1 year ago

This action uses cross to cross-compile by default, and the cross wiki has a section on openssl.

Probably the easiest way is to enable the vendored feature of openssl crate.

juli1 commented 1 year ago

The problem is that I do not control how openssl is imported since it's imported by my dependencies (I do not import it directly). I will try to go the route to install libssl but there are other challenges to do this in GitHub actions.

taiki-e commented 1 year ago

Because of the feature unification, it will work even if you add openssl with vendored feature enabled as a dependency of your crate.

Also, I think another way that might work is to install the toolchain for linux using setup-cross-toolchain-action mentioned in cross-compilation examples in readme, then enable the APT packages for arm64 (sudo dpkg --add-architecture arm64) and install libssl-dev:arm64 via APT.

juli1 commented 1 year ago

Thank you for your email! I am trying to include the vendored feature for openssl and see if this works.

I already tried to install libssl-dev:arm64 in the GitHub action. For a reason I still do not understand, dpkg --add-architecture adds invalid sources in the sources.list, which results to the following error.

E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/main/binary-arm64/Packages  404  Not Found [IP: 91.189.91.38 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/main/binary-arm64/Packages  404  Not Found [IP: 91.189.91.38 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-security/main/binary-arm64/Packages  404  Not Found [IP: 91.189.91.38 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/main/binary-arm64/Packages  404  Not Found [IP: 91.189.91.38 80]
williamfzc commented 8 months ago

@taiki-e

Thanks for your quick response! Enabling vendored can fix this issue on Mac and Linux, but not work on Windows. It produces another error error: failed to run custom build command foropenssl-sys v0.9.95``

Same as https://github.com/p2panda/send-to-node/issues/7

Adding vendored breaks the windows build actually. It works fine before.

taiki-e commented 8 months ago

Hmm, is it possible to use the way that doesn't use openssl (i.e., use rustls)?.

taiki-e commented 8 months ago

Adding vendored breaks the windows build actually.

It is actually quite odd that it is failing though, since tarpaulin can build with this action and vendored feature enabled openssl without problems.

https://github.com/xd009642/tarpaulin/blob/a33d6dae1bac153a3c59cd112c74fccc58ea11dc/.github/workflows/release.yml#L61

williamfzc commented 8 months ago

It is actually quite odd that it is failing though, since tarpaulin can build with this action and vendored feature enabled openssl without problems.

Thanks!

I have followed https://github.com/xd009642/tarpaulin/blob/a33d6dae1bac153a3c59cd112c74fccc58ea11dc/Cargo.toml#L64 and solved this problem.

It seems that this problem caused by the difference between git2/openssl and openssl.

davincios commented 6 months ago

Thanks for the awesome library.

I am sorry to also report the same issue and I know you have pointed people in the right direction, but I still am not able to solve the open ssl issue.

What I am getting in the CI/CD:

error[E0433]: failed to resolve: could not find `unix` in `os`
 --> src\setup\files.rs:6:14
  |
6 | use std::os::unix::fs::PermissionsExt;
  |              ^^^^ could not find `unix` in `os`
  |
note: found an item that was configured out
 --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\std\src\os\mod.rs:26:9
note: found an item that was configured out
 --> /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\std\src\os\mod.rs:64:9
error[E0599]: no function or associated item named `from_mode` found for struct `Permissions` in the current scope
  --> src\setup\files.rs:14:52
   |
14 |         fs::set_permissions(path, fs::Permissions::from_mode(0o700))
   |                                                    ^^^^^^^^^ function or associated item not found in `Permissions`
error[E0599]: no function or associated item named `from_mode` found for struct `Permissions` in the current scope
  --> src\setup\files.rs:24:69
   |
24 |         fs::set_permissions(config_json_file_path, fs::Permissions::from_mode(0o600))
   |                                                                     ^^^^^^^^^ function or associated item not found in `Permissions`
Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `tracer` (lib) due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
davincios commented 6 months ago

and in my cargo toml:

[dependencies] clap = { version = "4.5.4", features = ["derive"] } anyhow = "1.0.81" tokio = { version = "1.0.1", features = ["full"] } reqwest = { version = "0.11", features = ["json"] } serde_json = "1.0.64" serde = { version = "1.0.127", features = ["derive"] } config = "0.13" tokio-util = "0.6.8" tokio-tungstenite = "0.13.0" dirs = "3.0" tempfile = "3.10.1" sysinfo = "0.30.11" bstr = "1.9.1" log = "0.4.14" openssl = { version = "0.10", features = ["vendored"] }

But I keep getting deployment issues on windows:

error[E0433]: failed to resolve: could not find unix in os

Or:

Run taiki-e/upload-rust-binary-action@v1 Run bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh"

taiki-e commented 6 months ago

@davincios Your issue sounds like a bug in your code, not an openssl-related problem. Please submit a new issue with complete information (e.g., link to the repository) on the actual code that has the error and a link to full CI/CD logs.

davincios commented 6 months ago

@taiki-e awesome thank you for the quick response. I have opened a new issue with a link to the repository.

That code issue occurs only on Windows builds though still, although I have now reconfigured it. Somehow I cannot solve this openssl-sys v0.9.102 issue.

Here is my new opened issue, I would greatly appreciate any help! 😀

https://github.com/taiki-e/upload-rust-binary-action/issues/76