Files
Guillaume ASSIERandClaude Opus 5.5 78954b90dc
CI / Formatting, tests and builds (push) Successful in 2m44s
feat(windows): compilation croisée depuis Linux, l'hôte tourne sous Wine
Le shell Nix `.#windows` (#93) fournit un rustc pour la cible
x86_64-pc-windows-gnu (en cache dans nixpkgs), mingw-w64 et une libvpx
1.13 statique construite par nix/libvpx.nix, dont la variante Linux
garde son empreinte. aws-lc demande les en-têtes de winpthreads, que
le shell ajoute.

rs-platform se compile pour Windows:
- le portail et zbus ne sont plus que sous Linux; ailleurs, le même API
  répond `Unsupported`, traduit côté coque (`portal_unsupported`);
- la veille a un sous-module par système. Sous Windows, une requête
  d'alimentation (système et écran requis) empêche la veille, et la
  notification de suspension et de reprise remplace PrepareForSleep.

Les réglages vont dans %APPDATA%\rustscreen, le journal dans
%LOCALAPPDATA%\rustscreen\logs.

Vérifié sous Wine: `rustscreen-cli.exe --synthetic` prend le verrou de
veille, sert la mire et Chromium la reçoit (ICE, DTLS, première image
en 170 ms). Les tests du workspace passent sous Wine, sauf la
résolution mDNS de rustscreen.local, à vérifier sur un vrai Windows
(#94). La CI compile et passe clippy pour Windows quand Nix est présent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 20:39:17 +01:00

165 lines
6.9 KiB
Nix

{
description = "rustscreen: screen sharing over the local network, with no account and no relay";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# crane builds the Rust derivations without a `cargoHash` copied by hand:
# vendoring is derived from Cargo.lock. Fewer moving parts than a
# buildRustPackage whose hash changes with every added dependency.
# crane no longer has a nixpkgs input: it takes the one passed to mkLib.
crane.url = "github:ipetkov/crane";
};
outputs =
{
self,
nixpkgs,
crane,
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
];
# Each output is instantiated per system, without flake-utils: two
# systems are enough, and one dependency fewer is a flake that breaks less.
eachSystem =
f:
nixpkgs.lib.genAttrs systems (
system:
let
pkgs = import nixpkgs { inherit system; };
in
f {
inherit system pkgs;
# crane's default toolchain: rustc and cargo from nixpkgs. An
# `overrideToolchain` to `pkgs.rustc` alone left the build without cargo.
craneLib = crane.mkLib pkgs;
}
);
in
{
packages = eachSystem (
{ pkgs, craneLib, ... }:
let
# The command line, and the viewer it serves.
cli = pkgs.callPackage ./nix/package.nix { inherit craneLib; };
# Launching rustscreen opens the desktop application (#84).
rustscreen = pkgs.callPackage ./nix/desktop.nix { inherit craneLib cli; };
in
{
inherit rustscreen;
rustscreen-cli = cli;
default = rustscreen;
}
);
devShells = eachSystem (
{ pkgs, craneLib, ... }:
let
defaultShell = pkgs.mkShell {
name = "rustscreen";
inputsFrom = [ (pkgs.callPackage ./nix/package.nix { inherit craneLib; }) ];
packages = with pkgs; [
cargo
clippy
rustfmt
nodejs_22
nasm
pkg-config
nixfmt-rfc-style
];
shellHook = ''
# The Rust build needs to know where libvpx lives: without these
# variables, `env-libvpx-sys` fails before compiling anything.
export VPX_LIB_DIR="${pkgs.callPackage ./nix/libvpx.nix { }}/lib"
export VPX_INCLUDE_DIR="${pkgs.callPackage ./nix/libvpx.nix { }}/include"
export VPX_VERSION="1.13.0"
# Hardware encoding (#57): the `va` GStreamer plugin and a VA-API
# driver from nixpkgs, since a system driver links system
# libraries the Nix libva cannot load (Intel and AMD/Mesa here).
export GST_PLUGIN_SYSTEM_PATH_1_0="${pkgs.gst_all_1.gstreamer.out}/lib/gstreamer-1.0:${pkgs.gst_all_1.gst-plugins-base}/lib/gstreamer-1.0:${pkgs.gst_all_1.gst-plugins-bad}/lib/gstreamer-1.0"
export LIBVA_DRIVERS_PATH="${pkgs.intel-media-driver}/lib/dri:${pkgs.mesa}/lib/dri"
'';
};
# Windows (#93): cross-compiled from Linux with mingw-w64. A rustc
# built for that target (cached by nixpkgs), its linker, and libvpx
# built as a static library for Windows.
windows =
let
cross = pkgs.pkgsCross.mingwW64;
libvpx = cross.callPackage ./nix/libvpx.nix { };
in
pkgs.mkShell {
name = "rustscreen-windows";
packages = [
cross.buildPackages.rustc
cross.buildPackages.cargo
cross.stdenv.cc
# Build scripts run on Linux, with the Linux compiler.
pkgs.stdenv.cc
pkgs.nasm
cross.buildPackages.clippy
pkgs.rustfmt
pkgs.nodejs_22
pkgs.pkg-config
];
shellHook = ''
export CARGO_BUILD_TARGET=x86_64-pc-windows-gnu
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=${cross.stdenv.cc.targetPrefix}cc
# C dependencies (aws-lc, ring) compiled by the cc crate.
export CC_x86_64_pc_windows_gnu=${cross.stdenv.cc.targetPrefix}cc
export CXX_x86_64_pc_windows_gnu=${cross.stdenv.cc.targetPrefix}c++
export AR_x86_64_pc_windows_gnu=${cross.stdenv.cc.targetPrefix}ar
# aws-lc includes sched.h and pthread.h: winpthreads, which
# the mingw-w64 of nixpkgs (mcfgthread) does not put in the path.
export CFLAGS_x86_64_pc_windows_gnu="-I${cross.windows.pthreads}/include"
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS="-L native=${cross.windows.pthreads}/lib"
export VPX_LIB_DIR="${libvpx}/lib"
export VPX_INCLUDE_DIR="${libvpx}/include"
export VPX_VERSION="1.13.0"
export VPX_STATIC=1
# A separate target directory, under the usual one (the CI
# cache, or ./target): the Linux build keeps its cache.
export CARGO_TARGET_DIR="''${CARGO_TARGET_DIR:-$PWD/target}/windows"
'';
};
in
{
default = defaultShell;
inherit windows;
# The Tauri shell (apps/desktop) also needs WebKitGTK and GTK: a
# separate dev shell, so they are not downloaded when only the host
# or the viewer is being worked on.
desktop = pkgs.mkShell {
name = "rustscreen-desktop";
inputsFrom = [ defaultShell ];
packages = with pkgs; [
# The shell installs with pnpm, the viewer stays on npm.
pnpm
webkitgtk_4_1
gtk3
libsoup_3
glib-networking
librsvg
# The tray icon (#22): loaded at runtime, not linked.
libayatana-appindicator
];
shellHook = defaultShell.shellHook + ''
# WebKitGTK loads its TLS modules and schemas from these paths:
# outside a wrapped package, they have to be provided.
export GIO_MODULE_DIR="${pkgs.glib-networking}/lib/gio/modules"
# tray-icon opens libayatana-appindicator3 with dlopen: without
# this path, the icon is missing unless the system provides it.
export LD_LIBRARY_PATH="${pkgs.libayatana-appindicator}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export XDG_DATA_DIRS="${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:''${XDG_DATA_DIRS:-/usr/share}"
'';
};
}
);
formatter = eachSystem ({ pkgs, ... }: pkgs.nixfmt-rfc-style);
};
}