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

fix: exit process when build finishes #985

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sapphi-red
Copy link
Contributor

@sapphi-red sapphi-red commented Apr 27, 2024

Description

The cli didn't exit process immediately after the build finished. This PR fixes that.

But I'm not sure why it did exit the process after some seconds even if the thread safe functions are not "weak".

We can add a test by using why-is-node-running. I didn't add it though.

Copy link

netlify bot commented Apr 27, 2024

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 76f912b
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/662e07d2c698b600083fdc4d

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BindingPluginOptions").field("name", &self.name).finish_non_exhaustive()
}
}

impl FromNapiValue for BindingPluginOptions<true> {
Copy link
Member

@hyf0 hyf0 Apr 28, 2024

Choose a reason for hiding this comment

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

Do we still need customization if we already make these option with WEAK: true like you above code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to make this work in napi_derive?

hmmm, I think I can support the const generic in napi_derive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we still need customization if we already make these option with WEAK: true like you above code?

Yes, because we need BindingPluginOptions<true> for main thread plugins and BindingPluginOptions<false> for plugins in worker threads.

If pub struct BindingPluginOptions<const WEAK: bool = false> is flipped to pub struct BindingPluginOptions<const WEAK: bool = true>, then we need impl FromNapiValue for BindingPluginOptions<false> and call cb.refer(env) instead.

Copy link
Member

Choose a reason for hiding this comment

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

Nah. It's ok we mark main thread plugins WEAK: true.

@@ -65,18 +65,20 @@ use rolldown_utils::debug::pretty_type_name;
/// - Rust(Simplified): `MaybeAsyncJsCallback<(Option<String>, i32), Option<i32>>`
/// - Js: `(a: string | null | undefined, b: number) => Promise<number | null | undefined | void> | number | null | undefined | void`
/// - Js(Simplified): `(a: Nullable<string>, b: number) => MaybePromise<VoidNullable<number>>`
pub type JsCallback<Args, Ret> = ThreadsafeFunction<Args, Either<Ret, UnknownReturnValue>, false>;
pub type JsCallback<Args, Ret, const WEAK: bool = false> =
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub type JsCallback<Args, Ret, const WEAK: bool = false> =
pub type JsCallback<Args, Ret, const WEAK: bool = true> =

I think we could make it as the default.

let env = &napi::Env::from_raw(env);

if let Some(cb) = &mut false_options.build_start {
cb.unref(env)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

@hyf0
Copy link
Member

hyf0 commented Apr 28, 2024

So let's make WEAK: true by default in JsCallback and remove the customization, since they are all WEAK: true now.

@sapphi-red
Copy link
Contributor Author

If pub struct BindingPluginOptions<const WEAK: bool = false> is flipped to pub struct BindingPluginOptions<const WEAK: bool = true>, then we need impl FromNapiValue for BindingPluginOptions<false> and call cb.refer(env) instead.

Actually, this wasn't correct. If I call a WEAK=true threadsafe-function in worker threads, it throws "Rolldown internal error: Closing" error, even if I call cb.refer(env).

@sapphi-red
Copy link
Contributor Author

sapphi-red commented Apr 28, 2024

@sapphi-red
Copy link
Contributor Author

This is the code I wanted to write but reverted before I made this PR due to compile errors: 76f912b

@hyf0
Copy link
Member

hyf0 commented Apr 29, 2024

I looked into it. The current workaround would be use different struct for main and worker threads. Making NAPI-RS supporting generic could reduce the maintain overhead. @Brooooooklyn

@hyf0
Copy link
Member

hyf0 commented Apr 29, 2024

let's on hold this pr before #1003.

hyf0 added a commit that referenced this pull request May 12, 2024
<!-- Thank you for contributing! -->

### Description

Workaround of #985.


<!-- Please insert your description here and provide especially info about the "what" this PR is solving -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants