tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.53k stars 2.58k forks source link

[bug] NixOS Windows build from Linux OpenSSL linking issue #10608

Open liketoeatcheese opened 3 months ago

liketoeatcheese commented 3 months ago

Describe the bug

I'm trying to build Windows MSI on NixOS via nix-shell. Here's my shell.nix:

let
  pkgs = import <nixpkgs> { };
  overrides = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml));

  libraries = with pkgs;[
    webkitgtk
    gtk3
    cairo
    gdk-pixbuf
    glib
    dbus
    librsvg
  ];

  nativePkgs = with pkgs; [
    pkg-config
  ];

  packages = with pkgs; [
    dbus
    openssl_3
    openssl_3.dev
    glib
    gtk3
    libsoup
    webkitgtk
    appimagekit
    librsvg
    clang
    lld
    llvm
    # Replace llvmPackages with llvmPackages_X, where X is the latest LLVM version (at the time of writing, 16)
    llvmPackages_12.bintools
    rustup
  ];
in
pkgs.mkShell {
  buildInputs = packages;
  nativeBuildInputs = nativePkgs;
  RUSTC_VERSION = overrides.toolchain.channel;
  # https://github.com/rust-lang/rust-bindgen#environment-variables
  LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];

  shellHook =
    ''
      export OPENSSL_DIR=${pkgs.openssl_3.dev}
      export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
      export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS
      export PKG_CONFIG_PATH=${pkgs.openssl_3.dev}/lib/pkgconfig:$PKG_CONFIG_PATH
      export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
      export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
    '';
  # Add precompiled library to rustc search path
  RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
    # add libraries here (e.g. pkgs.libvmi)
  ]);
  # Add glibc, clang, glib, and other headers to bindgen search path
  BINDGEN_EXTRA_CLANG_ARGS =
    # Includes normal include path
    (builtins.map (a: ''-I"${a}/include"'') [
      # add dev libraries here (e.g. pkgs.libvmi.dev)
      pkgs.glibc.dev
    ])
    # Includes with special directory paths
    ++ [
      ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"''
      ''-I"${pkgs.glib.dev}/include/glib-2.0"''
      ''-I${pkgs.glib.out}/lib/glib-2.0/include/''
    ];
}

This nix shell follows nixos wiki on rust and Tauri's nixos guide. And also followed Tauri's guide to build Window Apps on Linux

When I tried to install:

๐ŸŒž โŒ   cargo tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc --verbose
     Running [tauri_cli] Command `cargo-xwin  build --features custom-protocol --release --target x86_64-pc-windows-msvc`
   Compiling openssl-sys v0.9.103
   Compiling tauri-runtime-wry v0.14.9
error: failed to run custom build command for `openssl-sys v0.9.103`

Caused by:
  process didn't exit successfully: `/home/wpham/learning/tauri/rocks_chest/src-tauri/target/release/build/openssl-sys-1e6744830b035fb9/build-script-main` (exit status: 101)
  --- stdout
  cargo:rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_OCB", "OPENSSL_NO_SM4", "OPENSSL_NO_SEED", "OPENSSL_NO_CHACHA", "OPENSSL_NO_CAST", "OPENSSL_NO_IDEA", "OPENSSL_NO_CAMELLIA", "OPENSSL_NO_RC4", "OPENSSL_NO_BF", "OPENSSL_NO_PSK", "OPENSSL_NO_DEPRECATED_3_0", "OPENSSL_NO_SCRYPT", "OPENSSL_NO_SM3", "OPENSSL_NO_RMD160", "OPENSSL_NO_EC2M", "OPENSSL_NO_OCSP", "OPENSSL_NO_CMS", "OPENSSL_NO_COMP", "OPENSSL_NO_SOCK", "OPENSSL_NO_STDIO"))
  cargo:rustc-check-cfg=cfg(openssl)
  cargo:rustc-check-cfg=cfg(libressl)
  cargo:rustc-check-cfg=cfg(boringssl)
  cargo:rustc-check-cfg=cfg(libressl250)
  cargo:rustc-check-cfg=cfg(libressl251)
  cargo:rustc-check-cfg=cfg(libressl252)
  cargo:rustc-check-cfg=cfg(libressl261)
  cargo:rustc-check-cfg=cfg(libressl270)
  cargo:rustc-check-cfg=cfg(libressl271)
  cargo:rustc-check-cfg=cfg(libressl273)
  cargo:rustc-check-cfg=cfg(libressl280)
  cargo:rustc-check-cfg=cfg(libressl281)
  cargo:rustc-check-cfg=cfg(libressl291)
  cargo:rustc-check-cfg=cfg(libressl310)
  cargo:rustc-check-cfg=cfg(libressl321)
  cargo:rustc-check-cfg=cfg(libressl332)
  cargo:rustc-check-cfg=cfg(libressl340)
  cargo:rustc-check-cfg=cfg(libressl350)
  cargo:rustc-check-cfg=cfg(libressl360)
  cargo:rustc-check-cfg=cfg(libressl361)
  cargo:rustc-check-cfg=cfg(libressl370)
  cargo:rustc-check-cfg=cfg(libressl380)
  cargo:rustc-check-cfg=cfg(libressl381)
  cargo:rustc-check-cfg=cfg(libressl382)
  cargo:rustc-check-cfg=cfg(libressl390)
  cargo:rustc-check-cfg=cfg(libressl400)
  cargo:rustc-check-cfg=cfg(ossl101)
  cargo:rustc-check-cfg=cfg(ossl102)
  cargo:rustc-check-cfg=cfg(ossl102f)
  cargo:rustc-check-cfg=cfg(ossl102h)
  cargo:rustc-check-cfg=cfg(ossl110)
  cargo:rustc-check-cfg=cfg(ossl110f)
  cargo:rustc-check-cfg=cfg(ossl110g)
  cargo:rustc-check-cfg=cfg(ossl110h)
  cargo:rustc-check-cfg=cfg(ossl111)
  cargo:rustc-check-cfg=cfg(ossl111b)
  cargo:rustc-check-cfg=cfg(ossl111c)
  cargo:rustc-check-cfg=cfg(ossl111d)
  cargo:rustc-check-cfg=cfg(ossl300)
  cargo:rustc-check-cfg=cfg(ossl310)
  cargo:rustc-check-cfg=cfg(ossl320)
  cargo:rustc-check-cfg=cfg(ossl330)
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR = /nix/store/bvrly5zpaqxydbfnx3dm4i7k8cbkrp32-openssl-3.0.14-dev
  cargo:rerun-if-changed=/nix/store/bvrly5zpaqxydbfnx3dm4i7k8cbkrp32-openssl-3.0.14-dev/include/openssl
  cargo:rustc-link-search=native=/nix/store/bvrly5zpaqxydbfnx3dm4i7k8cbkrp32-openssl-3.0.14-dev/lib
  cargo:include=/nix/store/bvrly5zpaqxydbfnx3dm4i7k8cbkrp32-openssl-3.0.14-dev/include
  cargo:rerun-if-changed=build/expando.c
  OPT_LEVEL = Some(3)
  TARGET = Some(x86_64-pc-windows-msvc)
  OUT_DIR = Some(/home/wpham/learning/tauri/rocks_chest/src-tauri/target/x86_64-pc-windows-msvc/release/build/openssl-sys-5ccbb0618efa91c1/out)
  HOST = Some(x86_64-unknown-linux-gnu)
  cargo:rerun-if-env-changed=VCINSTALLDIR
  VCINSTALLDIR = None
  cargo:rerun-if-env-changed=CC_x86_64-pc-windows-msvc
  CC_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CC_x86_64_pc_windows_msvc
  CC_x86_64_pc_windows_msvc = Some(clang-cl)
  cargo:rerun-if-env-changed=CC_KNOWN_WRAPPER_CUSTOM
  CC_KNOWN_WRAPPER_CUSTOM = None
  RUSTC_WRAPPER = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some(cmpxchg16b,fxsr,sse,sse2,sse3)
  DEBUG = Some(false)
  cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc
  CFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc
  CFLAGS_x86_64_pc_windows_msvc = Some(--target=x86_64-pc-windows-msvc -Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/home/wpham/.cache/cargo-xwin/xwin/crt/include /imsvc/home/wpham/.cache/cargo-xwin/xwin/sdk/include/ucrt /imsvc/home/wpham/.cache/cargo-xwin/xwin/sdk/include/um /imsvc/home/wpham/.cache/cargo-xwin/xwin/sdk/include/shared  )
  version: 3_0_14
  cargo:rustc-cfg=osslconf="OPENSSL_NO_SSL3_METHOD"
  cargo:conf=OPENSSL_NO_SSL3_METHOD
  cargo:rustc-cfg=openssl
  cargo:rustc-cfg=ossl300
  cargo:rustc-cfg=ossl101
  cargo:rustc-cfg=ossl102
  cargo:rustc-cfg=ossl102f
  cargo:rustc-cfg=ossl102h
  cargo:rustc-cfg=ossl110
  cargo:rustc-cfg=ossl110f
  cargo:rustc-cfg=ossl110g
  cargo:rustc-cfg=ossl110h
  cargo:rustc-cfg=ossl111
  cargo:rustc-cfg=ossl111b
  cargo:rustc-cfg=ossl111c
  cargo:rustc-cfg=ossl111d
  cargo:version_number=300000e0
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIBS
  X86_64_PC_WINDOWS_MSVC_OPENSSL_LIBS unset
  cargo:rerun-if-env-changed=OPENSSL_LIBS
  OPENSSL_LIBS unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_STATIC
  X86_64_PC_WINDOWS_MSVC_OPENSSL_STATIC unset
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  OPENSSL_STATIC unset

  --- stderr
  thread 'main' panicked at /home/wpham/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.103/build/main.rs:492:13:
  OpenSSL libdir at `["/nix/store/bvrly5zpaqxydbfnx3dm4i7k8cbkrp32-openssl-3.0.14-dev/lib"]` does not contain the required files to either statically or dynamically link OpenSSL
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I also tried adding the OPENSSL_'s environments variale directlly instead of relying on OPENSSL_DIR:

      export OPENSSL_DIR=${pkgs.openssl_3.dev}
      export OPENSSL_NO_VENDOR=1
      export OPENSSL_LIB_DIR=${pkgs.lib.getLib pkgs.openssl_3.dev}/lib
      export OPENSSL_INCLUDE_DIR=${pkgs.lib.getLib pkgs.openssl_3.dev}/include
      export OPENSSL_LIBS=${pkgs.lib.getLib pkgs.openssl_3.dev}/lib
      export OPENSSL_STATIC=1

Then getting:

๐ŸŒž โŒ   cargo tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc --verbose
     Running [tauri_cli] Command `cargo-xwin  build --features custom-protocol --release --target x86_64-pc-windows-msvc`
   Compiling openssl-sys v0.9.103
   Compiling tauri v1.7.1
   Compiling openssl v0.10.66
error: could not find native static library `/nix/store/bvrly5zpaqxydbfnx3dm4i7k8cbkrp32-openssl-3.0.14-dev/lib`, perhaps an -L flag is missing?

error: could not compile `openssl-sys` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
       Error [tauri_cli] failed to build app: failed to build app

I have also tried a heaps variance of open_ssl.dev, open_ssl.out,etcc...

Reproduction

๐ŸŒž โšก  cargo tauri --version
tauri-cli 1.6.0

๐ŸŒž โšก  cargo create-tauri-app --version
4.1.0

๐ŸŒž โŒ  cargo create-tauri-app
โœ” Project name ยท openssl_bug
โœ” Choose which language to use for your frontend ยท TypeScript / JavaScript - (pnpm, yarn, npm, bun)
โœ” Choose your package manager ยท npm
โœ” Choose your UI template ยท Vanilla
โœ” Choose your UI flavor ยท JavaScript

src-tauri/Cargo.toml

[package]
name = "openssl_bug"
...
[dependencies]
tauri = { version = "1", features = ["shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
openssl = "0.10.64"
...

src-tauri/tauri.conf.json

"identifier": "com.openssl-bug.dev",
rustup target add x86_64-pc-windows-msvc
cargo install --locked cargo-xwin

cargo tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc --verbose

Expected behavior

Windows's MSI should be outputed

Full tauri info output

๐ŸŒž โšก  cargo tauri info
WARNING: no lock files found, defaulting to npm

[โœ”] Environment
    - OS: NixOS 24.11.0 X64
    โœ” webkit2gtk-4.0: 2.44.2
    โœ” rsvg2: 2.58.2
    โœ” rustc: 1.80.0 (051478957 2024-07-21)
    โœ” cargo: 1.80.0 (376290515 2024-07-16)
    โœ” rustup: 1.26.0 (1980-01-01)
    โœ” Rust toolchain: stable-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN)
    - node: 22.4.1
    - npm: 10.8.1

[-] Packages
    - tauri [RUST]: 1.7.1
    - tauri-build [RUST]: 1.5.3
    - wry [RUST]: 0.24.10
    - tao [RUST]: 0.16.9
    - tauri-cli [RUST]: 1.6.0
    - @tauri-apps/api ๎œ˜: not installed!
    - @tauri-apps/cli [NPM]: 1.6.0

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../src
    - devPath: ../src

Stack trace

Refer to above

Additional context

No response

Zamoca42 commented 2 months ago

I also encountered the same error on Windows. After referring to gitbutler/development docs and installing Strawberry Perl, it worked normally.

body20002 commented 1 month ago

I got tauri working with this shell.nix

let
  pkgs = import <nixpkgs> { };
in
pkgs.mkShell {
  buildInputs = with pkgs;[
    at-spi2-atk
    atkmm
    cairo
    gdk-pixbuf
    glib
    gobject-introspection
    gobject-introspection.dev
    gtk3
    harfbuzz
    librsvg
    libsoup_3
    pango
    webkitgtk_4_1
    webkitgtk_4_1.dev
    pkg-config
  ];

  OPENSSL_NO_VENDOR = 1;
  LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [ openssl_3 ]);
  OPENSSL_LIB_DIR = "${pkgs.lib.getLib pkgs.openssl_3}/lib";
  OPENSSL_DIR = "${pkgs.openssl_3.dev}";
  PKG_CONFIG_PATH = with pkgs; "${glib.dev}/lib/pkgconfig:${libsoup_3.dev}/lib/pkgconfig:${webkitgtk_4_1.dev}/lib/pkgconfig:${at-spi2-atk.dev}/lib/pkgconfig:${gtk3.dev}/lib/pkgconfig:${gdk-pixbuf.dev}/lib/pkgconfig:${cairo.dev}/lib/pkgconfig:${pango.dev}/lib/pkgconfig:${harfbuzz.dev}/lib/pkgconfig";
}

I got the answer from discourse.nixos.org

jchantrell commented 2 weeks ago

I got tauri working with this shell.nix

let
  pkgs = import <nixpkgs> { };
in
pkgs.mkShell {
  buildInputs = with pkgs;[
    at-spi2-atk
    atkmm
    cairo
    gdk-pixbuf
    glib
    gobject-introspection
    gobject-introspection.dev
    gtk3
    harfbuzz
    librsvg
    libsoup_3
    pango
    webkitgtk_4_1
    webkitgtk_4_1.dev
    pkg-config
  ];

  OPENSSL_NO_VENDOR = 1;
  LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [ openssl_3 ]);
  OPENSSL_LIB_DIR = "${pkgs.lib.getLib pkgs.openssl_3}/lib";
  OPENSSL_DIR = "${pkgs.openssl_3.dev}";
  PKG_CONFIG_PATH = with pkgs; "${glib.dev}/lib/pkgconfig:${libsoup_3.dev}/lib/pkgconfig:${webkitgtk_4_1.dev}/lib/pkgconfig:${at-spi2-atk.dev}/lib/pkgconfig:${gtk3.dev}/lib/pkgconfig:${gdk-pixbuf.dev}/lib/pkgconfig:${cairo.dev}/lib/pkgconfig:${pango.dev}/lib/pkgconfig:${harfbuzz.dev}/lib/pkgconfig";
}

I got the answer from discourse.nixos.org

This worked for me on NixOS WSL, thanks. It could be worth submitting a PR for the docs showing this.