nixpkgs/pkgs/development/ocaml-modules/tsdl/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

48 lines
1.4 KiB
Nix

{ lib, stdenv, fetchurl, ocaml, findlib, ocamlbuild, topkg, ctypes, ctypes-foreign, result, SDL2, pkg-config
, AudioToolbox, Cocoa, CoreAudio, CoreVideo, ForceFeedback }:
if lib.versionOlder ocaml.version "4.03"
then throw "tsdl is not available for OCaml ${ocaml.version}"
else
let
pname = "tsdl";
version = "1.0.0";
webpage = "https://erratique.ch/software/${pname}";
in
stdenv.mkDerivation {
pname = "ocaml${ocaml.version}-${pname}";
inherit version;
src = fetchurl {
url = "${webpage}/releases/${pname}-${version}.tbz";
hash = "sha256-XdgzCj9Uqplt/8Jk8rSFaQf8zu+9SZa8b9ZIlW/gjyE=";
};
strictDeps = true;
nativeBuildInputs = [ pkg-config ocaml findlib ocamlbuild topkg ];
buildInputs = [ topkg ];
propagatedBuildInputs = [ SDL2 ctypes ctypes-foreign ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ AudioToolbox Cocoa CoreAudio CoreVideo ForceFeedback ];
preConfigure = ''
# The following is done to avoid an additional dependency (ncurses)
# due to linking in the custom bytecode runtime. Instead, just
# compile directly into a native binary, even if it's just a
# temporary build product.
substituteInPlace myocamlbuild.ml \
--replace ".byte" ".native"
'';
inherit (topkg) buildPhase installPhase;
meta = with lib; {
homepage = webpage;
description = "Thin bindings to the cross-platform SDL library";
license = licenses.isc;
inherit (ocaml.meta) platforms;
};
}