Skip to content

Commit

Permalink
fix: windows ci (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Dec 1, 2023
1 parent 7ced78d commit b425ae0
Show file tree
Hide file tree
Showing 118 changed files with 235 additions and 204 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
matrix:
name: [
linux,
#windows,
windows,
macos
]
include:
- name: linux
os: ubuntu-latest
# - name: windows
# os: windows-latest
- name: windows
os: windows-latest
- name: macos
os: macos-latest
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn compile(sh: &Shell, tmpdir: &TempDir, file_name: &str) -> anyhow::Result<

cmd!(
sh,
"./src/jco.js new {src_file} --wasi-command -o {dest_file}"
"node ./src/jco.js new {src_file} --wasi-command -o {dest_file}"
)
.run()?;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"homepage": "https://github.com/bytecodealliance/jco#readme",
"scripts": {
"build": "cargo xtask build workspace && npm run build:typescript",
"build": "cargo xtask build workspace",
"build:typescript": "tsc -p tsconfig.json",
"build:types:preview2-shim": "cargo xtask generate wasi-types",
"lint": "eslint -c eslintrc.cjs lib/**/*.js packages/*/lib/**/*.js",
Expand Down
53 changes: 28 additions & 25 deletions packages/preview2-shim/lib/nodejs/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class Descriptor {
descriptor.#hostPreopen = hostPreopen.endsWith("/")
? hostPreopen.slice(0, -1) || '/'
: hostPreopen;
// Windows requires UNC paths at minimum
if (isWindows) {
descriptor.#hostPreopen = descriptor.#hostPreopen.replace(/\\/g, '/');
if (descriptor.#hostPreopen === '/')
descriptor.#hostPreopen = '//';
}
return descriptor;
}

Expand Down Expand Up @@ -112,7 +118,7 @@ class Descriptor {
return this.writeViaStream(this.stat().size);
}

advise(_offset, _length, _advice) {}
advise(_offset, _length, _advice) { }

syncData() {
if (this.#hostPreopen) throw "invalid";
Expand Down Expand Up @@ -158,7 +164,7 @@ class Descriptor {
const mtime = this.#getNewTimestamp(
dataModificationTimestamp,
dataModificationTimestamp.tag === "no-change" &&
stats.dataModificationTimestamp
stats.dataModificationTimestamp
);
try {
futimesSync(this.#fd, atime, mtime);
Expand Down Expand Up @@ -196,9 +202,7 @@ class Descriptor {
readDirectory() {
if (!this.#fullPath) throw "bad-descriptor";
try {
const dir = opendirSync(
isWindows ? this.#fullPath.slice(1) : this.#fullPath
);
const dir = opendirSync(this.#fullPath);
return directoryEntryStreamCreate(dir);
} catch (e) {
throw convertFsError(e);
Expand Down Expand Up @@ -246,10 +250,7 @@ class Descriptor {
const fullPath = this.#getFullPath(path, false);
let stats;
try {
stats = (pathFlags.symlinkFollow ? statSync : lstatSync)(
isWindows ? fullPath.slice(1) : fullPath,
{ bigint: true }
);
stats = (pathFlags.symlinkFollow ? statSync : lstatSync)(fullPath, { bigint: true });
} catch (e) {
throw convertFsError(e);
}
Expand Down Expand Up @@ -279,7 +280,7 @@ class Descriptor {
const mtime = this.#getNewTimestamp(
dataModificationTimestamp,
dataModificationTimestamp.tag === "no-change" &&
stats.dataModificationTimestamp
stats.dataModificationTimestamp
);
try {
(pathFlags.symlinkFollow ? utimesSync : lutimesSync)(
Expand All @@ -295,6 +296,9 @@ class Descriptor {
linkAt(oldPathFlags, oldPath, newDescriptor, newPath) {
const oldFullPath = this.#getFullPath(oldPath, oldPathFlags.symlinkFollow);
const newFullPath = newDescriptor.#getFullPath(newPath, false);
// Windows doesn't automatically fail on trailing slashes
if (isWindows && newFullPath.endsWith('/'))
throw 'no-entry';
try {
linkSync(oldFullPath, newFullPath);
} catch (e) {
Expand All @@ -314,17 +318,14 @@ class Descriptor {
fsOpenFlags |= constants.O_RDWR;
else if (descriptorFlags.write) fsOpenFlags |= constants.O_WRONLY;
else if (descriptorFlags.read) fsOpenFlags |= constants.O_RDONLY;
// TODO:
// if (descriptorFlags.fileIntegritySync)
// if (descriptorFlags.dataIntegritySync)
if (descriptorFlags.fileIntegritySync) fsOpenFlags |= constants.O_SYNC;
if (descriptorFlags.dataIntegritySync) fsOpenFlags |= constants.O_DSYNC;
// Unsupported:
// if (descriptorFlags.requestedWriteSync)
// if (descriptorFlags.mutateDirectory)

try {
const fd = openSync(
isWindows ? fullPath.slice(1) : fullPath,
fsOpenFlags
);
const fd = openSync(fullPath, fsOpenFlags);
return descriptorCreate(fd, descriptorFlags, fullPath, preopenEntries);
} catch (e) {
throw convertFsError(e);
Expand All @@ -345,6 +346,8 @@ class Descriptor {
try {
rmdirSync(fullPath);
} catch (e) {
if (isWindows && e.code === 'ENOENT')
throw 'not-directory';
throw convertFsError(e);
}
}
Expand All @@ -355,6 +358,8 @@ class Descriptor {
try {
renameSync(oldFullPath, newFullPath);
} catch (e) {
if (isWindows && e.code === 'EPERM')
throw 'access';
throw convertFsError(e);
}
}
Expand All @@ -364,6 +369,8 @@ class Descriptor {
try {
symlinkSync(target, fullPath);
} catch (e) {
if (isWindows && (e.code === 'EPERM' || e.code === 'EEXIST'))
throw 'no-entry'
throw convertFsError(e);
}
}
Expand Down Expand Up @@ -394,10 +401,7 @@ class Descriptor {
metadataHashAt(pathFlags, path) {
const fullPath = this.#getFullPath(path, false);
try {
const stats = (pathFlags.symlinkFollow ? statSync : lstatSync)(
isWindows ? fullPath.slice(1) : fullPath,
{ bigint: true }
);
const stats = (pathFlags.symlinkFollow ? statSync : lstatSync)(fullPath, { bigint: true });
return { upper: stats.mtimeNs, lower: stats.ino };
} catch (e) {
throw convertFsError(e);
Expand All @@ -408,7 +412,7 @@ class Descriptor {
#getFullPath(subpath, _followSymlinks) {
let descriptor = this;
if (subpath.indexOf("\\") !== -1) subpath = subpath.replace(/\\/g, "/");
if (subpath[0] === "/") {
if (subpath[0] === '/') {
let bestPreopenMatch = "";
for (const preopenEntry of preopenEntries) {
if (
Expand All @@ -428,7 +432,7 @@ class Descriptor {
subpath = subpath.slice(subpath[1] === "/" ? 2 : 1);
if (descriptor.#hostPreopen)
return (
descriptor.#hostPreopen + (subpath.length > 0 ? "/" : "") + subpath
descriptor.#hostPreopen + (descriptor.#hostPreopen.endsWith('/') ? '' : (subpath.length > 0 ? "/" : "")) + subpath
);
return descriptor.#fullPath + (subpath.length > 0 ? "/" : "") + subpath;
}
Expand Down Expand Up @@ -472,7 +476,6 @@ const directoryEntryStreamCreate = DirectoryEntryStream._create;
delete DirectoryEntryStream._create;

let preopenEntries = [];
// let cwd = environment.initialCwd();

export const preopens = {
Descriptor,
Expand All @@ -481,7 +484,7 @@ export const preopens = {
},
};

_addPreopen("/", "/");
_addPreopen("/", isWindows ? "//" : "/");

export const types = {
Descriptor,
Expand Down
6 changes: 3 additions & 3 deletions packages/preview2-shim/lib/nodejs/sockets/tcp-socket-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import { isIP, Socket as NodeSocket } from "node:net";
import { platform } from "node:os";
import { assert } from "../../common/assert.js";
import { streams } from "../io.js";
const { InputStream, OutputStream } = streams;
// import { streams } from "../io.js";
// const { InputStream, OutputStream } = streams;

const symbolDispose = Symbol.dispose || Symbol.for("dispose");
const symbolSocketState = Symbol.SocketInternalState || Symbol.for("SocketInternalState");
Expand Down Expand Up @@ -369,7 +369,7 @@ export class TcpSocketImpl {
connectReq.localAddress = localAddress;
connectReq.localPort = localPort;

this.#socket.onread = (buffer) => {
this.#socket.onread = (_buffer) => {
// TODO: handle data received from the server
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class OutgoingDatagramStream {
datagrams.forEach((datagram) => {
const { data, remoteAddress } = datagram;
const { tag: family, val } = remoteAddress;
const { address, port } = val;
const { /*address, */port } = val;
const err = doSend(data, port, serializeIpAddress(remoteAddress), family);
console.error({
err,
Expand Down
10 changes: 5 additions & 5 deletions packages/preview2-shim/lib/nodejs/sockets/wasi-sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ export class WasiSockets {
"The new socket resource could not be created because of a system limit"
);

try {
// try {
return new TcpSocket(addressFamily);
} catch (err) {
// assert(true, errorCode.unknown, err);
throw err;
}
// } catch (err) {
// // assert(true, errorCode.unknown, err);
// throw err;
// }
},
};

Expand Down
Loading

0 comments on commit b425ae0

Please sign in to comment.