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

Compiling from macOS to Linux failing with openssl #106

Open
alper opened this issue May 8, 2023 · 6 comments
Open

Compiling from macOS to Linux failing with openssl #106

alper opened this issue May 8, 2023 · 6 comments
Labels
question Further information is requested

Comments

@alper
Copy link

alper commented May 8, 2023

I'm using the exact example and it takes a long time before it gives me:

error: builder for '/nix/store/ybs7q7w1vr7prv4fpahz82d8fab1ckhi-cuppings-deps-0.1.0.drv' failed with exit code 101;
       last 10 log lines:
       >   and include information about your system as well as this message.
       >
       >   $HOST = aarch64-apple-darwin
       >   $TARGET = aarch64-unknown-linux-gnu
       >   openssl-sys = 0.9.80
       >
       >   ', /nix/store/p8n62bg6q5wyff7g3pyphy3cx4xyyfww-dependencies/openssl-sys-0.9.80/build/find_normal.rs:191:5
       >   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
       > warning: build failed, waiting for other jobs to finish...
       > [naersk] cargo returned with exit code 101, exiting

Is it possible to fix this or should I not be trying this at all?

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/cross-compile-rust-from-m1/27879/7

@figsoda
Copy link
Member

figsoda commented May 8, 2023

Maybe try adding pkg-config to nativeBuildInputs and openssl to buildInputs. Please post the nix expression (and rust project) you are working with

@figsoda figsoda added the question Further information is requested label May 8, 2023
@alper
Copy link
Author

alper commented May 8, 2023

Hi,

Here's the Nix:

I added the parameters based on this documentation: https://github.com/nix-community/naersk#buildpackages-parameters

{
  inputs = {
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    flake-utils.url = "github:numtide/flake-utils";
    naersk = {
      url = "github:nix-community/naersk";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixpkgs.url = "nixpkgs/nixos-unstable";
  };

  outputs = { self, fenix, flake-utils, naersk, nixpkgs }:
    flake-utils.lib.eachDefaultSystem (system: {
      packages.default =
        let
          pkgs = nixpkgs.legacyPackages.${system};
          target = "aarch64-unknown-linux-gnu";
          toolchain = with fenix.packages.${system}; combine [
            minimal.cargo
            minimal.rustc
            targets.${target}.latest.rust-std
          ];
        in
          (naersk.lib.${system}.override {
            cargo = toolchain;
            rustc = toolchain;
          }).buildPackage {
            src = ./.;

            nativeBuildInputs = [ pkgs.pkg-config ];
            buildInputs = [ pkgs.openssl ];

            CARGO_BUILD_TARGET = target;
            CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER =
            let
              inherit (pkgs.pkgsCross.aarch64-multiplatform.stdenv) cc;
            in
              "${cc}/bin/${cc.targetPrefix}cc";
          };
    });
}

The Rust isn't public but here's the Cargo.toml:

[package]
name = "cuppings"
version = "0.1.0"
edition = "2021"

[profile.dev]
split-debuginfo = "unpacked"

[dependencies]
dotenv = "0.15.0"
serde_json = "1.0.96"
reqwest = { version = "0.11.16", features = ["blocking", "json"] }
axum = "0.6.16"
hyper = { version = "0.14.26", features = ["full"] }
tokio = { version = "1.21.2", features = ["full"] }
tower = "0.4.13"
lazy_static = "1.4.0"
sea-orm = { version = "0.11.2", features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros", "debug-print"] }
anyhow = "1.0.70"
serde = "1.0.160"
tower-http = { version = "0.3.4", features = ["cors", "fs", "trace"] }
form_urlencoded = "1.1.0"
tracing-subscriber = "0.3.17"
askama = { version = "0.12.0", features = ["serde-json"] }
tracing = "0.1.36"

@alper
Copy link
Author

alper commented May 8, 2023

It errors on sqlite:

error: builder for '/nix/store/nc57i86cr4rgb3s606pvdg4v4banq9lq-cuppings-deps-0.1.0.drv' failed with exit code 101;
       last 10 log lines:
       >   exit status: 1
       >
       >   --- stderr
       >
       >
       >   error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=aarch64-unknown-linux-gnu" "-DSQLITE_CORE" "-DSQLITE_DEFAULT_FOREIGN_KEYS=1" "-DSQLITE_ENABLE_API_ARMOR" "-DSQLITE_ENABLE_COLUMN_METADATA" "-DSQLITE_ENABLE_DBSTAT_VTAB" "-DSQLITE_ENABLE_FTS3" "-DSQLITE_ENABLE_FTS3_PARENTHESIS" "-DSQLITE_ENABLE_FTS5" "-DSQLITE_ENABLE_JSON1" "-DSQLITE_ENABLE_LOAD_EXTENSION=1" "-DSQLITE_ENABLE_MEMORY_MANAGEMENT" "-DSQLITE_ENABLE_RTREE" "-DSQLITE_ENABLE_STAT2" "-DSQLITE_ENABLE_STAT4" "-DSQLITE_SOUNDEX" "-DSQLITE_THREADSAFE=1" "-DSQLITE_USE_URI" "-DHAVE_USLEEP=1" "-D_POSIX_THREAD_SAFE_FUNCTIONS" "-DHAVE_ISNAN" "-DHAVE_LOCALTIME_R" "-DSQLITE_ENABLE_UNLOCK_NOTIFY" "-o" 
"/private/tmp/nix-build-cuppings-deps-0.1.0.drv-1/dummy-src/target/aarch64-unknown-linux-gnu/release/build/libsqlite3-sys-372958cdc8356848/out/sqlite3/sqlite3.o" "-c" "sqlite3/sqlite3.c" with args "clang" did not execute successfully (status code exit status: 1).

@dpc
Copy link

dpc commented Sep 28, 2023

You can use -L (like nix build -L ...) to capture full output. Oftentimes 10 last lines is not enough to tell what's wrong.

@rvolosatovs
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants