Skip to content

Commit

Permalink
feat: midl nx pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
szkabaroli committed Aug 15, 2024
1 parent 3db9be9 commit 67670e9
Show file tree
Hide file tree
Showing 50 changed files with 10,799 additions and 7,868 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions experiments/fiber-host/src/components/Host.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client"

import { ObjType } from "midl_TODO"
import type { Libp2p, PeerId, PrivateKey, PublicKey } from "@libp2p/interface"
import { keys } from "@libp2p/crypto"
import { peerIdFromKeys } from "@libp2p/peer-id"
Expand Down
4 changes: 2 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"@nx/js:tsc": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["default", "^default"]

"inputs": []
}
},
"useInferencePlugins": true,
Expand Down
17,991 changes: 10,394 additions & 7,597 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions sdk/midl/fx/msx.json

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/midl/fx/rights.midl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library zx;
library fx;

// TODO(scottmg): (1 << 4) notation or something else for bits would be nice.
type Rights = strict bits : uint32 {
Expand Down
6 changes: 4 additions & 2 deletions src/typescript/fiber-kernel/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function msg_get_handles(

for (let i = 0; i < num_handles; ++i) {
const ref = new Ref(0);
map_handle_to_value(up, handle_list[i], ref);
// TODO: remove null assertion
map_handle_to_value(up, handle_list[i]!, ref);
hvs[i] = ref.value;
}

Expand All @@ -91,7 +92,8 @@ function msg_get_handles(
}
}*/

const handle = new HandleOwner(handle_list[i]);
// TODO: remove null assertion
const handle = new HandleOwner(handle_list[i]!);
// TODO(https://fxbug.dev/42105832): This takes a lock per call. Consider doing these in a
// batch.
up.handle_table().add_handle(handle);
Expand Down
6 changes: 1 addition & 5 deletions src/typescript/fiber-kernel/src/lib/object/handle-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Handle } from "./handle"

// HandleOwner wraps a Handle in an Arc that has shared
// ownership of the Handle and deletes it whenever it falls out of scope.
export class HandleOwner implements Disposable {
export class HandleOwner {
constructor(public handle: Handle) {}

dispatcher() {
Expand All @@ -21,8 +21,4 @@ export class HandleOwner implements Disposable {
has_rights(rights: fx_rights_t) {
return this.handle.has_rights(rights)
}

[Symbol.dispose](): void {
console.log("removed")
}
}
6 changes: 1 addition & 5 deletions src/typescript/fiber-kernel/src/lib/object/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function conditional_select_nospec_eq(x: number, y: number, a: number, b: number
// const gHandleTableArena : Handle[] = []

/** A Handle is how a specific process refers to a specific Dispatcher. */
export class Handle implements Disposable {
export class Handle {
#handle_table_id: bigint
#dispatcher: Dispatcher
#rights: fx_rights_t
Expand Down Expand Up @@ -83,10 +83,6 @@ export class Handle implements Disposable {
return new Handle(dispatcher, rights, base_value)
}

[Symbol.dispose](): void {
throw new Error("Method not implemented.")
}

public static make_dispather(dispatcher: Dispatcher, rights: fx_rights_t): HandleOwner {
const base_value = new Ref(0)
const addr = gHandleTableArena.alloc(dispatcher, "new", base_value)
Expand Down
8 changes: 4 additions & 4 deletions src/typescript/fiber-kernel/src/lib/userboot/userboot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class ChildMessageLayout {
}
}

class ChildContext implements Disposable {
[Symbol.dispose](): void {
class ChildContext {
destroy(): void {
for (const handle of this.handles) {
fx_handle_close(handle);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ function parse_next_process_arguments(next: string, argv: { value: string[] }):
return;
}

const args = next.split("+")
const args = next.split("+");
argv.value = args;

// At a minimum, child processes will be passed a single argument containing the binary name.
Expand Down Expand Up @@ -323,7 +323,7 @@ async function bootstrap(channel: fx.Channel): Promise<u32> {

handle_termination(info);

return 0
return 0;
}

type TerminationInfo = {
Expand Down
2 changes: 1 addition & 1 deletion src/typescript/fiber-kernel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"lib": ["ESNext.Disposable", "DOM"],
"lib": ["DOM"],
"esModuleInterop": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
Expand Down
9 changes: 5 additions & 4 deletions src/typescript/fiber-ts/src/handle/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
fx_handle_disposition_t,
u32,
fx_handle_t,
FX_OK,
} from "@meshx-org/fiber-types";
import { HandleWrapper, HandleWrapperPair } from "./handle-wrapper";
import { Handle } from "./handle";
Expand All @@ -36,7 +37,7 @@ export class Channel extends HandleWrapper {
static MAX_MSG_BYTES = FX_CHANNEL_MAX_MSG_BYTES;
static MAX_MSG_HANDLES = FX_CHANNEL_MAX_MSG_HANDLES;

/*writeEtc(data: Uint8Array, handleDispositions: HandleDisposition[] = []): Status {
writeEtc(data: Uint8Array, handleDispositions: HandleDisposition[] = []): Status {
if (!this.handle || !this.handle.isValid) return Status.ERR_BAD_HANDLE;

const fx_handle_dispositions: fx_handle_disposition_t[] = [];
Expand All @@ -51,14 +52,14 @@ export class Channel extends HandleWrapper {
});
}

const status = self.fiber.sys_channel_write_etc(
const status = FX_OK;/*self.fiber.sys_channel_write_etc(
this.handle.raw,
0,
data.buffer,
data.byteLength,
fx_handle_dispositions,
fx_handle_dispositions.length
);
);*/

for (let i = 0; i < handleDispositions.length; ++i) {
handleDispositions[i].result = fx_handle_dispositions[i].result;
Expand All @@ -70,7 +71,7 @@ export class Channel extends HandleWrapper {
}

return status;
}*/
}

write(flags: u32, data: Uint8Array, handles: fx_handle_t[]): Status {
if (!this.handle || !this.handle.isValid) return Status.ERR_BAD_HANDLE;
Expand Down
27 changes: 13 additions & 14 deletions src/typescript/fiber-ts/src/handle/process.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { } from "@meshx-org/fiber-sys"
import { FX_HANDLE_INVALID, Ref, Status, fx_status_t } from "@meshx-org/fiber-types"
import { HandleWrapper } from "./handle-wrapper"
import { Handle } from "./handle"
import { Job } from "./job"
import { CreateResult } from "./types"
import {} from "@meshx-org/fiber-sys";
import { FX_HANDLE_INVALID, Ref, Status, fx_status_t } from "@meshx-org/fiber-types";
import { HandleWrapper } from "./handle-wrapper";
import { Handle } from "./handle";
import { Job } from "./job";
import { CreateResult } from "./types";

export class Process extends HandleWrapper {
constructor(raw: number) {
super(Handle.from_raw(raw))
super(Handle.from_raw(raw));
}

public static create(parent: Job, name: string): CreateResult<Process> {
const process = new Ref(FX_HANDLE_INVALID)
const vmar = new Ref(FX_HANDLE_INVALID)
const process = new Ref(FX_HANDLE_INVALID);

const status = self.fiber.sys_process_create(parent.handle?.raw, name, 0, process, vmar)
const status = self.fiber.sys_process_create(parent.handle?.raw, name, 0, process);

return {
status,
handle: status == Status.OK ? new Process(process.value) : undefined,
}
};
}

/// Similar to `Thread::start`, but is used to start the first thread in a process.
Expand All @@ -28,9 +27,9 @@ export class Process extends HandleWrapper {
/// [fx_process_start](https://fuchsia.dev/fuchsia-src/reference/syscalls/process_start.md)
/// syscall.
public start(entry: string, arg1: Handle): fx_status_t {
const process_raw = this.handle.raw
const arg1_raw = arg1.raw
const process_raw = this.handle.raw;
const arg1_raw = arg1.raw;

return self.fiber.sys_process_start(process_raw, entry, arg1_raw, 0)
return self.fiber.sys_process_start(process_raw, entry, arg1_raw, 0);
}
}
10 changes: 5 additions & 5 deletions src/typescript/fiber-ts/src/handle/socket.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// Typed wrapper around a socket objects

import { Handle } from './handle';
import { HandleWrapper } from './handle-wrapper';
import { Handle } from "./handle";
import { HandleWrapper } from "./handle-wrapper";

/// fx_socket_create() syscall used to create them.
export class Socket extends HandleWrapper {
constructor(handle: Handle | null) {
super(handle)
constructor(handle: Handle) {
super(handle);
}
}
}
20 changes: 10 additions & 10 deletions src/typescript/midl/src/lib/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Channel, ChannelPair, ChannelReader, ChannelReaderError } from "@meshx-org/fiber-ts"
import { MidlError, ErrorCode } from "./errors"
import { IncomingMessage, IncomingMessageSink, OutgoingMessage, OutgoingMessageSink } from "./message"
import { Status } from "@meshx-org/fiber-types"
import { FX_OK, Status } from "@meshx-org/fiber-types"
import { Completer } from "./completer"

export const epitaphOrdinal = 0xffffffffffffffffn
Expand Down Expand Up @@ -159,8 +159,8 @@ export class InterfacePair<T> {

constructor() {
const pair = ChannelPair.create()!
this.request = new InterfaceRequest<T>(pair.first)
this.handle = new InterfaceHandle<T>(pair.second)
this.request = new InterfaceRequest<T>(pair.handle!.first)
this.handle = new InterfaceHandle<T>(pair.handle!.second)
}

passRequest(): InterfaceRequest<T> | null {
Expand Down Expand Up @@ -229,19 +229,19 @@ export abstract class Binding<T> {
wrap(impl: T): InterfaceHandle<T> | null {
// TODO assert(!isBound)
const pair = ChannelPair.create()
if (!pair) {
if (pair.status !== FX_OK) {
return null
}

this.#impl = impl
this._reader.bind(pair.first)
this._reader.bind(pair.handle!.first)

const callback = this.onBind
if (callback != null) {
callback()
}

return new InterfaceHandle<T>(pair.second)
return new InterfaceHandle<T>(pair.handle!.second)
}

/// Binds the given implementation to the given interface request.
Expand Down Expand Up @@ -449,21 +449,21 @@ export class ProxyController<T> {
/// The proxy must not already have been bound.
request(): InterfaceRequest<T> {
// TODO: assert(!isBound);
const pair = ChannelPair.create()
if (!pair) {
const result = ChannelPair.create()
if (result.status !== FX_OK) {
throw new Error("channel creation failed")
}

// TODO: assert(pair.status == FX.OK);
this._reader.bind(pair.first)
this._reader.bind(result.handle!.first)
this._boundCompleter.complete(null)

const callback = this.onBind
if (callback != null) {
callback()
}

return new InterfaceRequest<T>(pair.second)
return new InterfaceRequest<T>(result.handle!.second)
}

/// Binds the proxy to the given interface handle.
Expand Down
4 changes: 2 additions & 2 deletions tools/buildtool/BUILD.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ midl "com.example" {
# "sdk/midl/meshx.drm",
# "sdk/midl/meshx.media2",
# "sdk/midl/meshx.mem",
# "fiber/vdso/zx",
# "fiber/fx",
#]
}

Expand All @@ -21,7 +21,7 @@ meshx_package "buildtool" {
}

resource "font" {
sources = [terminal_font_path]
sources = []
outputs = ["data/font.ttf"]
}

Expand Down
Loading

0 comments on commit 67670e9

Please sign in to comment.