Skip to content

Resolve import loop with use #166

@Back0fnGurke

Description

@Back0fnGurke

wac-cli version 0.7.0

Components xml-converter and network-outgoing implement interfaces defined in the core package and use the record error-detail defined in the core-logic interface. wasm-tools shows that after building said components with the commands wasm-tools component wit xml-converter.wasm and wasm-tools component wit network-outgoing.wasm both import prototype:core/[email protected]. However, the core component depends on the interfaces implemented by the xml-converter and network-outgoing components, which creates an import loop. While testing with WasmCloud and its runtime linking via wrpc, this didn't cause an issue, and everything worked fine. But trying to compose the components with WAC results in the resulting component importing prototype:core/[email protected]. Can this be solved somehow?

core component:

package prototype:[email protected];

interface core-logic {
  enum error-code {
    conversion-failed,
    failed-to-get-product-list,
    internal,
  }

  record error-detail {
    code: error-code,
    message: string,
  }

  get-product-list-csv: func(id: string, trace-id: string) -> result<list<u8>, error-detail>;
}

interface handler-outgoing {
  use core-logic.{error-detail};

  get-product-list: func(id: string, trace-id: string) -> result<list<u8>, error-detail>;
}

interface converter{
  use core-logic.{error-detail};

  convert: func(input: list<u8>, trace-id: string) -> result<list<u8>, error-detail>;
}

world core {
  import converter;
  import handler-outgoing;

  export core-logic;
}

network-outgoing component:

package prototype:[email protected];

world network-outgoing {
  import wasi:http/[email protected];

  export prototype:core/[email protected];
}

xml-converter component:

package prototype:[email protected];

world xml-converter {
  export prototype:core/[email protected];
}

network-incoming component:

package prototype:[email protected];

world network-incoming {
  import prototype:core/[email protected];

  export wasi:http/[email protected];
}

WAC file:

package prototype:[email protected];

let network-outgoing = new prototype:network-outgoing {...};
let xml-converter = new prototype:xml-converter {...};

let core = new prototype:core {
    converter: xml-converter.converter,
    handler-outgoing: network-outgoing.handler-outgoing,
    ...
};

let network-incoming = new prototype:network-incoming {
    core-logic: core.core-logic,
    ...
};

export network-incoming.incoming-handler;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions