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

llvm target triple for Deno.build #4948

Merged
merged 15 commits into from
Apr 28, 2020
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
5 changes: 5 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ fn main() {
deno_typescript::ts_version()
);

println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
);

let extern_crate_modules = include_crate_modules![deno_core];

// The generation of snapshots is slow and often unnecessary. Until we figure
Expand Down
29 changes: 12 additions & 17 deletions cli/js/build.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

export type OperatingSystem = "mac" | "win" | "linux";

export type Arch = "x64" | "arm64";

// Do not add unsupported platforms.
export interface BuildInfo {
arch: Arch;

os: OperatingSystem;
}

export const build: BuildInfo = {
arch: "" as Arch,
os: "" as OperatingSystem,
export const build = {
target: "unknown",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to Deno.build.triple ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think target is fine

arch: "unknown",
os: "unknown",
vendor: "unknown",
env: undefined as string | undefined,
};

export function setBuildInfo(os: OperatingSystem, arch: Arch): void {
build.os = os;
export function setBuildInfo(target: string): void {
const [arch, vendor, os, env] = target.split("-", 4);
build.target = target;
build.arch = arch;

build.vendor = vendor;
build.os = os;
build.env = env;
Object.freeze(build);
}
2 changes: 1 addition & 1 deletion cli/js/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export {
writeAll,
writeAllSync,
} from "./buffer.ts";
export { build, OperatingSystem, Arch } from "./build.ts";
export { build } from "./build.ts";
export { chmodSync, chmod } from "./ops/fs/chmod.ts";
export { chownSync, chown } from "./ops/fs/chown.ts";
export { transpileOnly, compile, bundle } from "./compiler/api.ts";
Expand Down
26 changes: 13 additions & 13 deletions cli/js/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ declare namespace Deno {
*
* Deno.test({
* name: "example ignored test",
* ignore: Deno.build.os === "win"
* ignore: Deno.build.os === "windows"
* fn(): void {
* // This test is ignored only on Windows machines
* },
Expand Down Expand Up @@ -2356,19 +2356,19 @@ declare namespace Deno {
*/
export function inspect(value: unknown, options?: InspectOptions): string;

export type OperatingSystem = "mac" | "win" | "linux";

export type Arch = "x64" | "arm64";

interface BuildInfo {
/** The CPU architecture. */
arch: Arch;
/** The operating system. */
os: OperatingSystem;
}

/** Build related information. */
export const build: BuildInfo;
export const build: {
/** The LLVM target triple */
target: string;
/** Instruction set architecture */
arch: "x86_64";
/** Operating system */
os: "darwin" | "linux" | "windows";
/** Computer vendor */
vendor: string;
/** Optional environment */
env?: string;
};

interface Version {
deno: string;
Expand Down
2 changes: 1 addition & 1 deletion cli/js/ops/fs/stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface StatResponse {

// @internal
export function parseFileInfo(response: StatResponse): FileInfo {
const isUnix = build.os === "mac" || build.os === "linux";
const isUnix = build.os === "darwin" || build.os === "linux";
return {
isFile: response.isFile,
isDirectory: response.isDirectory,
Expand Down
4 changes: 2 additions & 2 deletions cli/js/ops/fs/symlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function symlinkSync(
newpath: string,
type?: string
): void {
if (build.os === "win" && type) {
if (build.os === "windows" && type) {
return util.notImplemented();
}
sendSync("op_symlink", { oldpath, newpath });
Expand All @@ -19,7 +19,7 @@ export async function symlink(
newpath: string,
type?: string
): Promise<void> {
if (build.os === "win" && type) {
if (build.os === "windows" && type) {
return util.notImplemented();
}
await sendAsync("op_symlink", { oldpath, newpath });
Expand Down
2 changes: 1 addition & 1 deletion cli/js/ops/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { assert } from "../util.ts";
import { build } from "../build.ts";

export function kill(pid: number, signo: number): void {
if (build.os === "win") {
if (build.os === "windows") {
throw new Error("Not yet implemented");
}
sendSync("op_kill", { pid, signo });
Expand Down
10 changes: 2 additions & 8 deletions cli/js/ops/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

import { sendSync } from "./dispatch_json.ts";

// TODO(bartlomieju): these two types are duplicated
// in `cli/js/build.ts` - deduplicate
export type OperatingSystem = "mac" | "win" | "linux";
export type Arch = "x64" | "arm64";

export interface Start {
cwd: string;
pid: number;
Expand All @@ -21,11 +16,10 @@ export interface Start {
v8Version: string;
tsVersion: string;
noColor: boolean;
os: OperatingSystem;
arch: Arch;
target: string;
}

export function start(): Start {
export function opStart(): Start {
return sendSync("op_start");
}

Expand Down
8 changes: 3 additions & 5 deletions cli/js/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as util from "./util.ts";
import { setBuildInfo } from "./build.ts";
import { setVersions } from "./version.ts";
import { setPrepareStackTrace } from "./error_stack.ts";
import { Start, start as startOp } from "./ops/runtime.ts";
import { Start, opStart } from "./ops/runtime.ts";
import { handleTimerMacrotask } from "./web/timers.ts";

export let OPS_CACHE: { [name: string]: number };
Expand Down Expand Up @@ -36,12 +36,10 @@ export function start(source?: string): Start {
// First we send an empty `Start` message to let the privileged side know we
// are ready. The response should be a `StartRes` message containing the CLI
// args and other info.
const s = startOp();

const s = opStart();
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
setBuildInfo(s.os, s.arch);
setBuildInfo(s.target);
util.setLogDebug(s.debugFlag, source);

setPrepareStackTrace(Error);
return s;
}
4 changes: 2 additions & 2 deletions cli/js/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ enum MacOSSignal {
export const Signal: { [key: string]: number } = {};

export function setSignals(): void {
if (build.os === "mac") {
if (build.os === "darwin") {
Object.assign(Signal, MacOSSignal);
} else {
Object.assign(Signal, LinuxSignal);
}
}

export function signal(signo: number): SignalStream {
if (build.os === "win") {
if (build.os === "windows") {
throw new Error("not implemented!");
}
return new SignalStream(signo);
Expand Down
2 changes: 1 addition & 1 deletion cli/js/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ unitTest(function simpleTestFn(): void {
});

unitTest({
ignore: Deno.build.os === "win",
ignore: Deno.build.os === "windows",
perms: { read: true, write: true },
},
function complexTestFn(): void {
Expand Down
2 changes: 1 addition & 1 deletion cli/js/tests/blob_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ unitTest(function nativeEndLine(): void {
};
const blob = new Blob(["Hello\nWorld"], options);

assertEquals(blob.size, Deno.build.os === "win" ? 12 : 11);
assertEquals(blob.size, Deno.build.os === "windows" ? 12 : 11);
});

unitTest(async function blobText(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions cli/js/tests/build_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ unitTest(function buildInfo(): void {
// Deno.build is injected by rollup at compile time. Here
// we check it has been properly transformed.
const { arch, os } = Deno.build;
assert(arch === "x64");
assert(os === "mac" || os === "win" || os === "linux");
assert(arch.length > 0);
assert(os === "darwin" || os === "windows" || os === "linux");
});
8 changes: 4 additions & 4 deletions cli/js/tests/chmod_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { unitTest, assert, assertEquals } from "./test_util.ts";

unitTest(
{ ignore: Deno.build.os === "win", perms: { read: true, write: true } },
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
function chmodSyncSuccess(): void {
const enc = new TextEncoder();
const data = enc.encode("Hello");
Expand All @@ -21,7 +21,7 @@ unitTest(
// Check symlink when not on windows
unitTest(
{
ignore: Deno.build.os === "win",
ignore: Deno.build.os === "windows",
perms: { read: true, write: true },
},
function chmodSyncSymlinkSuccess(): void {
Expand Down Expand Up @@ -73,7 +73,7 @@ unitTest({ perms: { write: false } }, function chmodSyncPerm(): void {
});

unitTest(
{ ignore: Deno.build.os === "win", perms: { read: true, write: true } },
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function chmodSuccess(): Promise<void> {
const enc = new TextEncoder();
const data = enc.encode("Hello");
Expand All @@ -93,7 +93,7 @@ unitTest(

unitTest(
{
ignore: Deno.build.os === "win",
ignore: Deno.build.os === "windows",
perms: { read: true, write: true },
},
async function chmodSymlinkSuccess(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion cli/js/tests/chown_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { unitTest, assertEquals, assert } from "./test_util.ts";

// chown on Windows is noop for now, so ignore its testing on Windows
if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
async function getUidAndGid(): Promise<{ uid: number; gid: number }> {
// get the user ID and group ID of the current process
const uidProc = Deno.run({
Expand Down
4 changes: 2 additions & 2 deletions cli/js/tests/dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unitTest({ perms: { write: true } }, function dirCwdChdirSuccess(): void {
const path = Deno.makeTempDirSync();
Deno.chdir(path);
const current = Deno.cwd();
if (Deno.build.os === "mac") {
if (Deno.build.os === "darwin") {
assertEquals(current, "/private" + path);
} else {
assertEquals(current, path);
Expand All @@ -20,7 +20,7 @@ unitTest({ perms: { write: true } }, function dirCwdChdirSuccess(): void {

unitTest({ perms: { write: true } }, function dirCwdError(): void {
// excluding windows since it throws resource busy, while removeSync
if (["linux", "mac"].includes(Deno.build.os)) {
if (["linux", "darwin"].includes(Deno.build.os)) {
const initialdir = Deno.cwd();
const path = Deno.makeTempDirSync();
Deno.chdir(path);
Expand Down
4 changes: 2 additions & 2 deletions cli/js/tests/files_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ unitTest(
});
file.close();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
assertEquals(pathInfo.mode! & 0o777, 0o626 & ~Deno.umask());
}
}
Expand All @@ -191,7 +191,7 @@ unitTest(
});
file.close();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
assertEquals(pathInfo.mode! & 0o777, 0o626 & ~Deno.umask());
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/js/tests/fs_events_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ unitTest({ perms: { read: true } }, function watchFsInvalidPath() {
Deno.watchFs("non-existant.file");
} catch (err) {
console.error(err);
if (Deno.build.os === "win") {
if (Deno.build.os === "windows") {
assert(
err.message.includes(
"Input watch path is neither a file nor a directory"
Expand Down
8 changes: 4 additions & 4 deletions cli/js/tests/make_temp_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ unitTest(
function makeTempDirSyncMode(): void {
const path = Deno.makeTempDirSync();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
assertEquals(pathInfo.mode! & 0o777, 0o700 & ~Deno.umask());
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ unitTest(
async function makeTempDirMode(): Promise<void> {
const path = await Deno.makeTempDir();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
assertEquals(pathInfo.mode! & 0o777, 0o700 & ~Deno.umask());
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ unitTest(
function makeTempFileSyncMode(): void {
const path = Deno.makeTempFileSync();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
assertEquals(pathInfo.mode! & 0o777, 0o600 & ~Deno.umask());
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ unitTest(
async function makeTempFileMode(): Promise<void> {
const path = await Deno.makeTempFile();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
assertEquals(pathInfo.mode! & 0o777, 0o600 & ~Deno.umask());
}
}
Expand Down
8 changes: 4 additions & 4 deletions cli/js/tests/mkdir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { unitTest, assert, assertEquals, assertThrows } from "./test_util.ts";
function assertDirectory(path: string, mode?: number): void {
const info = Deno.lstatSync(path);
assert(info.isDirectory);
if (Deno.build.os !== "win" && mode !== undefined) {
if (Deno.build.os !== "windows" && mode !== undefined) {
assertEquals(info.mode! & 0o777, mode & ~Deno.umask());
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ unitTest(
Deno.mkdirSync(path, { recursive: true });
Deno.mkdirSync(path, { recursive: true, mode: 0o731 });
assertDirectory(path, 0o737);
if (Deno.build.os != "win") {
if (Deno.build.os !== "windows") {
const pathLink = path + "Link";
Deno.symlinkSync(path, pathLink);
Deno.mkdirSync(pathLink, { recursive: true });
Expand All @@ -144,7 +144,7 @@ unitTest(
await Deno.mkdir(path, { recursive: true });
await Deno.mkdir(path, { recursive: true, mode: 0o731 });
assertDirectory(path, 0o737);
if (Deno.build.os != "win") {
if (Deno.build.os !== "windows") {
const pathLink = path + "Link";
Deno.symlinkSync(path, pathLink);
await Deno.mkdir(pathLink, { recursive: true });
Expand Down Expand Up @@ -178,7 +178,7 @@ unitTest(
Deno.mkdirSync(file, { recursive: true });
}, Deno.errors.AlreadyExists);

if (Deno.build.os !== "win") {
if (Deno.build.os !== "windows") {
const fileLink = testDir + "/fileLink";
const dirLink = testDir + "/dirLink";
const danglingLink = testDir + "/danglingLink";
Expand Down
Loading