Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deno: 1.6.3 -> 1.8.0 -> 1.8.1 #110156

Merged
merged 5 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions pkgs/development/web/deno/default.nix
Original file line number Diff line number Diff line change
@@ -1,72 +1,77 @@
{ lib, stdenv
, fetchurl
{ stdenv
, lib
, callPackage
, fetchFromGitHub
, rust
, rustPlatform
, installShellFiles
, libobjc
, Security
, CoreServices
, Metal
, Foundation
, librusty_v8 ? callPackage ./librusty_v8.nix { }
}:
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.6.3";
version = "1.8.1";

src = fetchFromGitHub {
owner = "denoland";
repo = pname;
rev = "v${version}";
sha256 = "1wmkx458fpsfw57ysawxc0ghxag8v051hiyswm7nnb7gckrm6j8z";
fetchSubmodules = true;
sha256 = "sha256-tyqZ/vjQ9gjLoK+Juj30It3H6+2sT9Fj/s0kEv0HRwI=";
};
cargoSha256 = "08vzsp53019gmxkn8lpa6l84w3fvbrnr11lzrfgf99nmii6l2hq5";
cargoSha256 = "sha256-LpBQztMqw7IbgTJkfiD+6Fcy5XXmN58HO/zhVen3oCI=";

# Install completions post-install
nativeBuildInputs = [ installShellFiles ];

buildInputs = lib.optionals stdenv.isDarwin [ Security CoreServices ];
buildInputs = lib.optionals stdenv.isDarwin [ libobjc Security CoreServices Metal Foundation ];

# 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 = ''
_rusty_v8_setup() {
for v in "$@"; do
dir="target/$v/gn_out/obj"
mkdir -p "$dir" && cp "${rustyV8Lib}" "$dir/librusty_v8.a"
done
}
preBuild =
let arch = rust.toRustTarget stdenv.hostPlatform; in
''
_librusty_v8_setup() {
for v in "$@"; do
install -D ${librusty_v8} "target/$v/gn_out/obj/librusty_v8.a"
done
}

# Copy over the `librusty_v8.a` file inside target/XYZ/gn_out/obj, symlink not allowed
_rusty_v8_setup "debug" "release" "${arch}/release"
'';
# Copy over the `librusty_v8.a` file inside target/XYZ/gn_out/obj, symlink not allowed
_librusty_v8_setup "debug" "release" "${arch}/release"
'';

# Tests have some inconsistencies between runs with output integration tests
# Skipping until resolved
doCheck = false;

postInstall = ''
# remove test plugin and test server
rm -rf $out/lib $out/bin/test_server
rm -r $out/lib $out/bin/test_server $out/bin/denort

installShellCompletion --cmd deno \
--bash <($out/bin/deno completions bash) \
--fish <($out/bin/deno completions fish) \
--zsh <($out/bin/deno completions zsh)
'';

doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
$out/bin/deno --help
$out/bin/deno --version | grep "deno ${version}"
runHook postInstallCheck
'';

passthru.updateScript = ./update/update.ts;

meta = with lib; {
homepage = "https://deno.land/";
changelog = "${src.meta.homepage}/releases/tag/v${version}";
changelog = "https://github.com/denoland/deno/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.
Expand All @@ -79,6 +84,6 @@ rustPlatform.buildRustPackage rec {
'';
license = licenses.mit;
maintainers = with maintainers; [ jk ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
};
}
12 changes: 0 additions & 12 deletions pkgs/development/web/deno/deps.nix

This file was deleted.

21 changes: 21 additions & 0 deletions pkgs/development/web/deno/librusty_v8.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# auto-generated file -- DO NOT EDIT!
{ rust, stdenv, fetchurl }:

let
arch = rust.toRustTarget stdenv.hostPlatform;
fetch_librusty_v8 = args: fetchurl {
name = "librusty_v8-${args.version}";
url = "https://github.com/denoland/rusty_v8/releases/download/v${args.version}/librusty_v8_release_${arch}.a";
sha256 = args.shas.${stdenv.hostPlatform.system};
meta = { inherit (args) version; };
};
in
fetch_librusty_v8 {
version = "0.20.0";
shas = {
x86_64-linux = "sha256-pTWNYQzChyYJh+afn1AMw/MxUE+Cv4k2FnM3+KDYCvg=";
aarch64-linux = "sha256-SPRtQO0tnuEf49GuSsuo403QO0Y6ioRkOp4cjohXRhw=";
x86_64-darwin = "sha256-k0kS5NiITqW/WEFWe/Bnt7Z9HZp2YN19L7DvVlptrj4=";
aarch64-darwin = "sha256-CDGxSv7fPR+5kF3+5NVTOH8ugLaM07Kv5mjoEW6/g/8=";
};
}
34 changes: 12 additions & 22 deletions pkgs/development/web/deno/update/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ interface GHRelease {
}

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" },
);
const decodeTrim = (b: Uint8Array) => decode(b).trimEnd();
export const run = async (command: string, args: string[]) => {
const cmd = Deno.run({
cmd: [command, ...args],
stdout: "piped",
stderr: "piped",
});
if (!(await cmd.status()).success) {
const error = await cmd.stderrOutput().then((b) => decode(b).trimEnd());
const error = await cmd.stderrOutput().then(decodeTrim);
// Known error we can ignore
if (error.includes("'allow-unsafe-native-code-during-evaluation'")) {
// Extract the target sha256 out of the error
Expand All @@ -23,26 +26,16 @@ const run = async (command: string, args: string[]) => {
}
throw new Error(error);
}
return cmd.output().then((b) => decode(b).trimEnd());
return cmd.output().then(decodeTrim);
};

// 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 sha256RegExp = /[a-z0-9]{52}|sha256-.{44}/;

export const getExistingVersion = async (filePath: string) =>
read(filePath).then((s) =>
s.match(genValueRegExp("version", versionRegExp))?.shift() || ""
read(filePath).then(
(s) => s.match(genValueRegExp("version", versionRegExp))?.shift() || "",
);

export const getLatestVersion = (owner: string, repo: string) =>
Expand All @@ -58,8 +51,5 @@ export const genValueRegExp = (key: string, regex: RegExp) =>
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;
79 changes: 0 additions & 79 deletions pkgs/development/web/deno/update/deps.ts

This file was deleted.

92 changes: 92 additions & 0 deletions pkgs/development/web/deno/update/librusty_v8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
genValueRegExp,
getExistingVersion,
logger,
run,
versionRegExp,
write,
} from "./common.ts";

const log = logger("librusty_v8");

export interface Architecture {
nix: string;
rust: string;
}
interface PrefetchResult {
arch: Architecture;
sha256: string;
}

const getLibrustyV8Version = 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 fetchArchShaTasks = (version: string, arches: Architecture[]) =>
arches.map(
async (arch: Architecture): Promise<PrefetchResult> => {
log("Fetching:", arch.nix);
const sha256 = await run("nix-prefetch", [
`
{ fetchurl }:
fetchurl {
url = "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!
{ rust, stdenv, fetchurl }:

let
arch = rust.toRustTarget stdenv.hostPlatform;
fetch_librusty_v8 = args: fetchurl {
name = "librusty_v8-\${args.version}";
url = "https://github.com/denoland/rusty_v8/releases/download/v\${args.version}/librusty_v8_release_\${arch}.a";
sha256 = args.shas.\${stdenv.hostPlatform.system};
meta = { inherit (args) version; };
};
in
fetch_librusty_v8 {
version = "${version}";
shas = {
${deps.map(({ arch, sha256 }) => ` ${arch.nix} = "${sha256}";`).join("\n")}
};
}
`;

export async function updateLibrustyV8(
filePath: string,
owner: string,
repo: string,
denoVersion: string,
arches: Architecture[],
) {
log("Starting librusty_v8 update");
// 0.0.0
const version = await getLibrustyV8Version(owner, repo, denoVersion);
if (typeof version !== "string") {
throw "no librusty_v8 version";
}
log("librusty_v8 version:", version);
const existingVersion = await getExistingVersion(filePath);
if (version === existingVersion) {
log("Version already matches latest, skipping...");
return;
}
const archShaResults = await Promise.all(fetchArchShaTasks(version, arches));
await write(filePath, templateDeps(version, archShaResults));
log("Finished deps update");
}
Loading