about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/web/deno
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/web/deno')
-rw-r--r--nixpkgs/pkgs/development/web/deno/default.nix98
-rw-r--r--nixpkgs/pkgs/development/web/deno/deps.nix12
-rw-r--r--nixpkgs/pkgs/development/web/deno/update/common.ts52
-rw-r--r--nixpkgs/pkgs/development/web/deno/update/deps.ts79
-rw-r--r--nixpkgs/pkgs/development/web/deno/update/src.ts67
-rwxr-xr-xnixpkgs/pkgs/development/web/deno/update/update.ts50
6 files changed, 281 insertions, 77 deletions
diff --git a/nixpkgs/pkgs/development/web/deno/default.nix b/nixpkgs/pkgs/development/web/deno/default.nix
index 629c1eeb41a1..199d7f81fe0f 100644
--- a/nixpkgs/pkgs/development/web/deno/default.nix
+++ b/nixpkgs/pkgs/development/web/deno/default.nix
@@ -3,52 +3,34 @@
 , fetchFromGitHub
 , rust
 , rustPlatform
-, python27
 , installShellFiles
 , Security
 , CoreServices
 }:
 let
+  deps = import ./deps.nix { };
+  arch = rust.toRustTarget stdenv.hostPlatform;
+  rustyV8Lib = with deps.rustyV8Lib; fetchurl {
+    url = "https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${arch}.a";
+    sha256 = sha256s."${stdenv.hostPlatform.system}";
+    meta = { inherit version; };
+  };
+in
+rustPlatform.buildRustPackage rec {
   pname = "deno";
-  version = "1.0.0";
+  version = "1.1.0";
 
-  denoSrc = fetchFromGitHub {
+  src = fetchFromGitHub {
     owner = "denoland";
     repo = pname;
     rev = "v${version}";
-    sha256 = "0k8mqy1hf9hkp60jhd0x4z814y36g51083b3r7prc69ih2523hd1";
-
+    sha256 = "11rxfnjam1kr8piiw0s4r0qg8rj4qfpppp6dixk1hhsq2iwbnzj6";
     fetchSubmodules = true;
   };
-  cargoSha256 = "1fjl07qqvl1f20qazcqxh32xmdfh80jni7i3jzvz6vgsfw1g5cmk";
-
-  rustyV8Lib = fetchlib "rusty_v8" "0.4.2" {
-    x86_64-linux = "1ac6kv3kv087df6kdgfd7kbh24187cg9z7xhbz6rw6jjv4ci2zbi";
-    aarch64-linux = "06iyjx4p4vp2i81wdy0vxai2k18pki972ff7k0scjqrgmnav1p8k";
-    x86_64-darwin = "02hwbpsqdzb9mvfndgykvv44f1jig3w3a26l0h26hs5shsrp47jv";
-  };
-
-  arch = rust.toRustTarget stdenv.hostPlatform;
-  fetchlib = name: version: sha256: fetchurl {
-    url = "https://github.com/denoland/${name}/releases/download/v${version}/librusty_v8_release_${arch}.a";
-    sha256 = sha256."${stdenv.hostPlatform.system}";
-    meta = { inherit version; };
-  };
-in
-rustPlatform.buildRustPackage rec {
-  inherit pname version cargoSha256;
-
-  src = denoSrc;
+  cargoSha256 = "107i9zvlwiwad58c7lmh6zl9iwlqn1h8qk7zf7x68b6498p8nh7d";
 
-  nativeBuildInputs = [
-    # chromium/V8 requires python 2.7, we're not building V8 from source
-    # but as a result rusty_v8's download script also uses python 2.7
-    # tracking issue: https://bugs.chromium.org/p/chromium/issues/detail?id=942720
-    python27
-
-    # Install completions post-install
-    installShellFiles
-  ];
+  # Install completions post-install
+  nativeBuildInputs = [ installShellFiles ];
 
   buildInputs = with stdenv.lib; [ ]
     ++ optionals stdenv.isDarwin [ Security CoreServices ];
@@ -56,16 +38,6 @@ rustPlatform.buildRustPackage rec {
   # The rusty_v8 package will try to download a `librusty_v8.a` release at build time to our read-only filesystem
   # To avoid this we pre-download the file and place it in the locations it will require it in advance
   preBuild = ''
-    # Check the rusty_v8 lib downloaded matches the Cargo.lock file
-    rusty_v8_ver="$(grep 'name = "rusty_v8"' -A 1 Cargo.lock | grep "version =" | cut -d\" -f2)"
-    if [ "${rustyV8Lib.meta.version}" != "$rusty_v8_ver" ]; then
-      printf "%s\n" >&2 \
-        "version mismatch between 'rusty_v8' in Cargo.lock and downloaded library:" \
-        "  wanted: ${rustyV8Lib.meta.version}" \
-        "  got:    $rusty_v8_ver"
-      exit 1
-    fi;
-
     _rusty_v8_setup() {
       for v in "$@"; do
         dir="target/$v/gn_out/obj"
@@ -77,40 +49,9 @@ rustPlatform.buildRustPackage rec {
     _rusty_v8_setup "debug" "release" "${arch}/release"
   '';
 
-  # Set home to existing env var TMP dir so tests that write there work correctly
-  preCheck = ''
-    export HOME="$TMPDIR"
-  '';
-
-  checkFlags = [
-    # Strace not allowed on hydra
-    "--skip benchmark_test"
-
-    # Tests that try to write to `/build/source/target/debug`
-    "--skip _017_import_redirect"
-    "--skip https_import"
-    "--skip js_unit_tests"
-    "--skip lock_write_fetch"
-
-    # Cargo test runs a deno test on the std lib with sub-benchmarking-tests,
-    # The sub-sub-tests that are failing:
-    # forAwaitFetchDenolandX10, promiseAllFetchDenolandX10is
-    # Trying to access https://deno.land/ on build's limited network access
-    "--skip std_tests"
-
-    # Fails on aarch64 machines
-    # tracking issue: https://github.com/denoland/deno/issues/5324
-    "--skip run_v8_flags"
-
-    # Skip for multiple reasons:
-    # downloads x86_64 binary on aarch64 machines
-    # tracking issue: https://github.com/denoland/deno/pull/5402
-    # downloads a binary that needs ELF patching & tries to run imediately
-    # upgrade will likely never work with nix as it tries to replace itself
-    # code: https://github.com/denoland/deno/blob/v1.0.0/cli/upgrade.rs#L211
-    "--skip upgrade_in_tmpdir"
-    "--skip upgrade_with_version_in_tmpdir"
-  ];
+  # Tests have some inconsistencies between runs with output integration tests
+  # Skipping until resolved
+  doCheck = false;
 
   # TODO: Move to enhanced installShellCompletion when merged: PR #83630
   postInstall = ''
@@ -120,8 +61,11 @@ rustPlatform.buildRustPackage rec {
     installShellCompletion deno.{bash,fish} --zsh _deno
   '';
 
+  passthru.updateScript = ./update/update.ts;
+
   meta = with stdenv.lib; {
     homepage = "https://deno.land/";
+    changelog = "${src.meta.homepage}/releases/tag/v${version}";
     description = "A secure runtime for JavaScript and TypeScript";
     longDescription = ''
       Deno aims to be a productive and secure scripting environment for the modern programmer.
diff --git a/nixpkgs/pkgs/development/web/deno/deps.nix b/nixpkgs/pkgs/development/web/deno/deps.nix
new file mode 100644
index 000000000000..9218e8ad97d2
--- /dev/null
+++ b/nixpkgs/pkgs/development/web/deno/deps.nix
@@ -0,0 +1,12 @@
+# auto-generated file -- DO NOT EDIT!
+{}:
+rec {
+  rustyV8Lib = {
+    version = "0.5.0";
+    sha256s = {
+      x86_64-linux = "1jmrqf5ns2y51cxx9r88my15m6gc6wmg54xadi3kphq47n4hmdfw";
+      aarch64-linux = "14v57pxpkz1fs483rbbc8k55rc4x41dqi0k12zdrjwa5ycdam3m5";
+      x86_64-darwin = "0466px7k2zvbsswwcrr342i5ml669gf76xd8yzzypsmb7l71s6vr";
+    };
+  };
+}
diff --git a/nixpkgs/pkgs/development/web/deno/update/common.ts b/nixpkgs/pkgs/development/web/deno/update/common.ts
new file mode 100644
index 000000000000..71e4d638f8d7
--- /dev/null
+++ b/nixpkgs/pkgs/development/web/deno/update/common.ts
@@ -0,0 +1,52 @@
+interface GHRelease {
+  tag_name: string;
+}
+
+const decode = (buffer: Uint8Array) => new TextDecoder("utf-8").decode(buffer);
+const run = async (command: string, args: string[]) => {
+  const cmd = Deno.run(
+    { cmd: [command, ...args], stdout: "piped", stderr: "piped" },
+  );
+  if (!(await cmd.status()).success) {
+    throw await cmd.stderrOutput().then((b) => decode(b));
+  }
+  return cmd.output().then((b) => decode(b).trimEnd());
+};
+
+// Exports
+export const versionRegExp = /\d+\.\d+\.\d+/;
+export const sha256RegExp = /[a-z0-9]{52}/;
+
+export async function commit(
+  name: string,
+  oldVer: string,
+  newVer: string,
+  files: string[],
+) {
+  await run("git", ["add", ...files]);
+  await run("git", ["commit", "-m", `${name}: ${oldVer} -> ${newVer}`]);
+}
+
+export const getExistingVersion = async (filePath: string) =>
+  read(filePath).then((s) =>
+    s.match(genValueRegExp("version", versionRegExp))?.shift() || ""
+  );
+
+export const getLatestVersion = (owner: string, repo: string) =>
+  fetch(`https://api.github.com/repos/${owner}/${repo}/releases`)
+    .then((res) => res.json())
+    .then((res: GHRelease[]) => res[0].tag_name);
+
+// The (?<=) and (?=) allow replace to only change inside
+// Match the regex passed in or empty
+export const genValueRegExp = (key: string, regex: RegExp) =>
+  new RegExp(`(?<=${key} = ")(${regex.source}|)(?=")`);
+
+export const logger = (name: string) =>
+  (...a: any) => console.log(`[${name}]`, ...a);
+
+export const nixPrefetch = (args: string[]) => run("nix-prefetch", args);
+export const nixPrefetchURL = (args: string[]) => run("nix-prefetch-url", args);
+
+export const read = Deno.readTextFile;
+export const write = Deno.writeTextFile;
diff --git a/nixpkgs/pkgs/development/web/deno/update/deps.ts b/nixpkgs/pkgs/development/web/deno/update/deps.ts
new file mode 100644
index 000000000000..beedeade3a86
--- /dev/null
+++ b/nixpkgs/pkgs/development/web/deno/update/deps.ts
@@ -0,0 +1,79 @@
+import {
+  getExistingVersion,
+  genValueRegExp,
+  logger,
+  nixPrefetchURL,
+  versionRegExp,
+  write,
+} from "./common.ts";
+
+const log = logger("deps");
+
+export interface Architecture {
+  nix: string;
+  rust: string;
+}
+interface PrefetchResult {
+  arch: Architecture;
+  sha256: string;
+}
+
+const getRustyV8Version = async (
+  owner: string,
+  repo: string,
+  version: string,
+) =>
+  fetch(
+    `https://github.com/${owner}/${repo}/raw/${version}/core/Cargo.toml`,
+  )
+    .then((res) => res.text())
+    .then((txt) =>
+      txt.match(genValueRegExp("rusty_v8", versionRegExp))?.shift()
+    );
+
+const archShaTasks = (version: string, arches: Architecture[]) =>
+  arches.map(async (arch: Architecture): Promise<PrefetchResult> => {
+    log("Fetching:", arch.nix);
+    const sha256 = await nixPrefetchURL(
+      [`https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${arch.rust}.a`],
+    );
+    log("Done:    ", arch.nix);
+    return { arch, sha256 };
+  });
+
+const templateDeps = (version: string, deps: PrefetchResult[]) =>
+  `# auto-generated file -- DO NOT EDIT!
+{}:
+rec {
+  rustyV8Lib = {
+    version = "${version}";
+    sha256s = {
+${deps.map((d) => `      ${d.arch.nix} = "${d.sha256}";`).join("\n")}
+    };
+  };
+}
+`;
+
+export async function updateDeps(
+  filePath: string,
+  owner: string,
+  repo: string,
+  denoVersion: string,
+  arches: Architecture[],
+) {
+  log("Starting deps update");
+  // 0.0.0
+  const version = await getRustyV8Version(owner, repo, denoVersion);
+  if (typeof version !== "string") {
+    throw "no rusty_v8 version";
+  }
+  log("rusty_v8 version:", version);
+  const existingVersion = await getExistingVersion(filePath);
+  if (version === existingVersion) {
+    log("Version already matches latest, skipping...");
+    return;
+  }
+  const archShaResults = await Promise.all(archShaTasks(version, arches));
+  await write(filePath, templateDeps(version, archShaResults));
+  log("Finished deps update");
+}
diff --git a/nixpkgs/pkgs/development/web/deno/update/src.ts b/nixpkgs/pkgs/development/web/deno/update/src.ts
new file mode 100644
index 000000000000..fae15acd0d2c
--- /dev/null
+++ b/nixpkgs/pkgs/development/web/deno/update/src.ts
@@ -0,0 +1,67 @@
+import {
+  genValueRegExp,
+  logger,
+  nixPrefetch,
+  read,
+  sha256RegExp,
+  versionRegExp,
+  write,
+} from "./common.ts";
+
+interface Replacer {
+  regex: RegExp;
+  value: string;
+}
+
+const log = logger("src");
+
+const prefetchSha256 = (nixpkgs: string, version: string) =>
+  nixPrefetch(["-f", nixpkgs, "deno.src", "--rev", version]);
+const prefetchCargoSha256 = (nixpkgs: string) =>
+  nixPrefetch(
+    [`{ sha256 }: (import ${nixpkgs} {}).deno.cargoDeps.overrideAttrs (_: { outputHash = sha256; })`],
+  );
+
+const replace = (str: string, replacers: Replacer[]) =>
+  replacers.reduce(
+    (str, r) => str.replace(r.regex, r.value),
+    str,
+  );
+
+const updateNix = (filePath: string, replacers: Replacer[]) =>
+  read(filePath).then((str) => write(filePath, replace(str, replacers)));
+
+const genVerReplacer = (k: string, value: string): Replacer => (
+  { regex: genValueRegExp(k, versionRegExp), value }
+);
+const genShaReplacer = (k: string, value: string): Replacer => (
+  { regex: genValueRegExp(k, sha256RegExp), value }
+);
+
+export async function updateSrc(
+  filePath: string,
+  nixpkgs: string,
+  denoVersion: string,
+) {
+  log("Starting src update");
+  const trimVersion = denoVersion.substr(1);
+  log("Fetching sha256 for:", trimVersion);
+  const sha256 = await prefetchSha256(nixpkgs, denoVersion);
+  log("sha256 to update:", sha256);
+  await updateNix(
+    filePath,
+    [
+      genVerReplacer("version", trimVersion),
+      genShaReplacer("sha256", sha256),
+      genShaReplacer("cargoSha256", ""), // Empty ready for prefetchCargoSha256
+    ],
+  );
+  log("Fetching cargoSha256 for:", sha256);
+  const cargoSha256 = await prefetchCargoSha256(nixpkgs);
+  log("cargoSha256 to update:", cargoSha256);
+  await updateNix(
+    filePath,
+    [genShaReplacer("cargoSha256", cargoSha256)],
+  );
+  log("Finished src update");
+}
diff --git a/nixpkgs/pkgs/development/web/deno/update/update.ts b/nixpkgs/pkgs/development/web/deno/update/update.ts
new file mode 100755
index 000000000000..18d451480137
--- /dev/null
+++ b/nixpkgs/pkgs/development/web/deno/update/update.ts
@@ -0,0 +1,50 @@
+#!/usr/bin/env nix-shell
+/*
+#!nix-shell -i "deno run --allow-net --allow-run --allow-read --allow-write" -p deno git nix-prefetch
+*/
+import {
+  commit,
+  getExistingVersion,
+  getLatestVersion,
+  logger,
+} from "./common.ts";
+import { Architecture, updateDeps } from "./deps.ts";
+import { updateSrc } from "./src.ts";
+
+const log = logger("update");
+// TODO: Getting current file position to more-safely point to nixpkgs root
+const nixpkgs = Deno.cwd();
+// TODO: Read values from default.nix
+const owner = "denoland";
+const repo = "deno";
+const denoDir = `${nixpkgs}/pkgs/development/web/${repo}`;
+const src = `${denoDir}/default.nix`;
+const deps = `${denoDir}/deps.nix`;
+const architectures: Architecture[] = [
+  { nix: "x86_64-linux", rust: "x86_64-unknown-linux-gnu" },
+  { nix: "aarch64-linux", rust: "aarch64-unknown-linux-gnu" },
+  { nix: "x86_64-darwin", rust: "x86_64-apple-darwin" },
+];
+
+log("Updating deno");
+
+log("Getting latest deno version");
+const version = await getLatestVersion(owner, repo);
+const existingVersion = await getExistingVersion(src);
+const trimVersion = version.substr(1); // Strip v from v0.0.0
+log("Latest version:   ", trimVersion);
+log("Extracted version:", existingVersion);
+if (trimVersion === existingVersion) {
+  log("Version already matches latest, skipping...");
+  Deno.exit(0);
+}
+
+const tasks = [
+  updateSrc(src, nixpkgs, version),
+  updateDeps(deps, owner, repo, version, architectures),
+];
+await Promise.all(tasks);
+log("Updating deno complete");
+log("Commiting");
+await commit(repo, existingVersion, trimVersion, [src, deps]);
+log("Done");