btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / development / compilers / dart / default.nix
blobd6d538d5c844c9cf89e22944f0496c726aa54b30
1 { stdenv
2 , lib
3 , fetchurl
4 , unzip
5 , runCommand
6 , cctools
7 , darwin
8 , sources ? import ./sources.nix {inherit fetchurl;}
9 , version ? sources.versionUsed
12 assert sources != null && (builtins.isAttrs sources);
13 stdenv.mkDerivation (finalAttrs: {
14   pname = "dart";
15   inherit version;
17   nativeBuildInputs = [ unzip ];
19   src = sources."${version}-${stdenv.hostPlatform.system}" or (throw "unsupported version/system: ${version}/${stdenv.hostPlatform.system}");
21   installPhase = ''
22     mkdir -p $out
23     cp -R * $out/
24     echo $libPath
25   '' + lib.optionalString (stdenv.hostPlatform.isLinux) ''
26     find $out/bin -executable -type f -exec patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \;
27   '';
29   libPath = lib.makeLibraryPath [ stdenv.cc.cc ];
30   dontStrip = true;
31   passthru = {
32     updateScript = ./update.sh;
33     tests = {
34       testCreate = runCommand "dart-test-create" { nativeBuildInputs = [ finalAttrs.finalPackage ]; } ''
35         PROJECTNAME="dart_test_project"
36         dart create --no-pub $PROJECTNAME
38         [[ -d $PROJECTNAME ]]
39         [[ -f $PROJECTNAME/bin/$PROJECTNAME.dart ]]
40         touch $out
41       '';
43       testCompile = runCommand "dart-test-compile" {
44         nativeBuildInputs = [ finalAttrs.finalPackage ]
45           ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools darwin.sigtool ];
46       } ''
47         HELLO_MESSAGE="Hello, world!"
48         echo "void main() => print('$HELLO_MESSAGE');" > hello.dart
49         dart compile exe hello.dart
50         PROGRAM_OUT=$(./hello.exe)
52         [[ "$PROGRAM_OUT" == "$HELLO_MESSAGE" ]]
53         touch $out
54       '';
55     };
56   };
58   meta = with lib; {
59     homepage = "https://dart.dev";
60     maintainers = with maintainers; [ grburst ];
61     description = "Scalable programming language, with robust libraries and runtimes, for building web, server, and mobile apps";
62     longDescription = ''
63       Dart is a class-based, single inheritance, object-oriented language
64       with C-style syntax. It offers compilation to JavaScript, interfaces,
65       mixins, abstract classes, reified generics, and optional typing.
66     '';
67     mainProgram = "dart";
68     platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
69     sourceProvenance = with sourceTypes; [ binaryNativeCode ];
70     license = licenses.bsd3;
71   };