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

Feature request: CLI available as library #7928

Closed
andybarron opened this issue Oct 11, 2020 · 11 comments · Fixed by #8640
Closed

Feature request: CLI available as library #7928

andybarron opened this issue Oct 11, 2020 · 11 comments · Fixed by #8640
Assignees
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)

Comments

@andybarron
Copy link

I'm working on a project where I'd like to instantiate multiple instances of the full Deno runtime from within Rust code. Because the cli package only provides a binary, that isn't currently possible. I'd like to avoid the inefficiencies of shelling out to multiple separate Deno processes, and instead spin them up in Rust threads.

Adding a [lib] target to Cargo.toml in the cli package would fix this, but it would probably require changes to the package to expose a Rust API with all of the CLI options.

@bartlomieju
Copy link
Member

We had lib option specified some time ago, but in #5226 we decided to remove it - Deno is being developed very fast and each patch release would introduce breaking changes in the Rust interface - that's why it's considered private. There are no plans in the immediate future to change that.

@kitsonk kitsonk added cli related to cli/ dir suggestion suggestions for new features (yet to be agreed) labels Oct 11, 2020
@kitsonk kitsonk added this to the future milestone Oct 11, 2020
@olanod
Copy link

olanod commented Oct 22, 2020

This would be very useful, I'm trying to create a plug-in system where the JS/WASM plug-ins can run in the browser and server unchanged using the WebWorker interface. I see in the cli package most of my homework is done already but can't use it if is not exposed, doing it myself on top of deno-core seems like a non trivial work. Knowing that the API is unstable. what about publishing it as a pre-release version known to be unstable for the people that are willing and expecting things to break? say deno-lib v1.x-alpha from there I get my unstable web worker abstraction and be happy that fixing some breaking API changes is easier than implementing the whole thing myself.

@bartlomieju
Copy link
Member

what about publishing it as a pre-release version known to be unstable for the people that are willing and expecting things to break? say deno-lib v1.x-alpha from there I get my unstable web worker abstraction and be happy that fixing some breaking API changes is easier than implementing the whole thing myself.

This is not possible, deno is at current version 1.4.6 and we have no way to version Rust crate differently.

@hmdhk
Copy link

hmdhk commented Nov 4, 2020

@bartlomieju , Currently the way to reuse any of cli internal implementations is to fork the repo and add the required lib.rs. Is there anyway we can improve on this?

Also, are there any parts that can be exposed initially? Specifically the Worker struct (not MainWorker or WebWorker).
I can work on the necessary changes.

@bartlomieju
Copy link
Member

@jahtalab my comment from above still holds (#7928 (comment)). Every release introduces a lot of changes in Rust code, eg. refactors from #7915. We just had a series of PRs which rewritten about 20% of cli codebase and there are a few more such rewrites coming. I'll be happy to revisit this topic when the codebase stabilizes but I don't think we should provide CLI as library at this point of time. @ry thoughts?

This was referenced Nov 17, 2020
@trevyn
Copy link

trevyn commented Nov 18, 2020

Would it be possible to only expose a "pipe" interface to the CLI? That would be trivially stable and that way we could embed Deno easily and avoid the overhead of shelling out, even if it's not as fancy as a proper API.

@bartlomieju
Copy link
Member

Would it be possible to only expose a "pipe" interface to the CLI? That would be trivially stable and that way we could embed Deno easily and avoid the overhead of shelling out, even if it's not as fancy as a proper API.

@trevyn I'm not sure what you're suggesting here, could you elaborate?

@trevyn
Copy link

trevyn commented Nov 18, 2020

Like, instead of the CLI reading/writing to stdout/stdin, it just piped those to a Rust byte channel or something.

One way would be to mimic the interface to std::process, but there's probably a simpler way.

@olanod
Copy link

olanod commented Nov 18, 2020

That sounds quite hacky 🤔 besides cli args/flags don't come from the stdin, does the cli even read anything from stdin? and what is the output of a command? do I have to write a parser for whatever different commands output?

@bartlomieju
Copy link
Member

@olanod @trevyn agreed, that does indeed sound hacky. Core team had discussion on this topic and we're actually going to expose cli as a library in some near future.

@bartlomieju
Copy link
Member

@andybarron @olanod @jahtalab @trevyn we now provide library crate that exposes runtime functionalities of Deno: https://crates.io/crates/deno_runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants