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

feat(npm): implement Node API #13633

Merged
merged 171 commits into from
Oct 5, 2022
Merged

feat(npm): implement Node API #13633

merged 171 commits into from
Oct 5, 2022

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Feb 9, 2022

This PR implements the NAPI for loading native modules into Deno.

Closes #15717

Feature tracking

  • Environment life cycle APIs
    • napi_set_instance_data
    • napi_get_instance_data
  • Basic Node-API data types
    • napi_status
    • napi_extended_error_info
    • napi_env
    • napi_value
    • napi_threadsafe_function
    • napi_threadsafe_function_release_mode
    • napi_threadsafe_function_call_mode
    • Node-API memory management types
      • napi_handle_scope
      • napi_escapable_handle_scope
      • napi_ref
      • napi_type_tag
      • napi_async_cleanup_hook_handle
    • Node-API callback types
      • napi_callback_info
      • napi_callback
      • napi_finalize
      • napi_async_execute_callback
      • napi_async_complete_callback
      • napi_threadsafe_function_call_js
      • napi_async_cleanup_hook
  • Error handling
    • Return values
      • napi_get_last_error_info
    • Exceptions
      • napi_throw
      • napi_throw_error
      • napi_throw_type_error
      • napi_throw_range_error
      • node_api_throw_syntax_error
      • napi_create_error
      • napi_create_type_error
      • napi_create_range_error
      • node_api_create_syntax_error
      • napi_get_and_clear_last_exception
      • napi_is_exception_pending (stubbed)
      • napi_fatal_exception
    • Fatal errors
      • napi_fatal_error
  • Object lifetime management
  • Module registration
    • napi_module_register
  • Working with JavaScript values
    • Enum types
      • napi_key_collection_mode
      • napi_key_filter
      • napi_key_conversion
      • napi_valuetype
      • napi_typedarray_type
    • Object creation functions
      • napi_create_array
      • napi_create_array_with_length
      • napi_create_arraybuffer
      • napi_create_buffer
      • napi_create_buffer_copy
      • napi_create_date
      • napi_create_external
      • napi_create_external_arraybuffer
      • napi_create_external_buffer
      • napi_create_object
      • napi_create_symbol
      • napi_create_typedarray
      • napi_create_dataview
    • Functions to convert from C types to Node-API
      • napi_create_int32
      • napi_create_uint32
      • napi_create_int64
      • napi_create_double
      • napi_create_bigint_int64
      • napi_create_bigint_uint64
      • napi_create_bigint_words
      • napi_create_string_latin1
      • napi_create_string_utf16
      • napi_create_string_utf8
    • Functions to convert from Node-API to C types
      • napi_get_array_length
      • napi_get_arraybuffer_info
      • napi_get_buffer_info
      • napi_get_prototype
      • napi_get_typedarray_info
      • napi_get_dataview_info
      • napi_get_date_value
      • napi_get_value_bool
      • napi_get_value_double
      • napi_get_value_bigint_int64
      • napi_get_value_bigint_uint64
      • napi_get_value_bigint_words
      • napi_get_value_external
      • napi_get_value_int32
      • napi_get_value_int64
      • napi_get_value_string_latin1
      • napi_get_value_string_utf8
      • napi_get_value_string_utf16
      • napi_get_value_uint32
    • Functions to get global instances
      • napi_get_boolean
      • napi_get_global
      • napi_get_null
      • napi_get_undefined
  • Working with JavaScript values and abstract operations
    • napi_coerce_to_bool
    • napi_coerce_to_number
    • napi_coerce_to_object
    • napi_coerce_to_string
    • napi_typeof
    • napi_instanceof (Add v8::Value::InstanceOf bindings rusty_v8#879)
    • napi_is_array
    • napi_is_arraybuffer
    • napi_is_buffer
    • napi_is_date
    • napi_is_error
    • napi_is_typedarray
    • napi_is_dataview
    • napi_strict_equals
    • napi_detach_arraybuffer
    • napi_is_detached_arraybuffer
  • Working with JavaScript properties
    • Structures
      • napi_property_attributes
      • napi_property_descriptor
    • Functions
      • napi_get_property_names
      • napi_get_all_property_names (needs v8 binding)
      • napi_set_property
      • napi_get_property
      • napi_has_property
      • napi_delete_property
      • napi_has_own_property Add v8::Object::HasOwnProperty bindings rusty_v8#897
      • napi_set_named_property
      • napi_get_named_property
      • napi_has_named_property
      • napi_set_element
      • napi_get_element
      • napi_has_element
      • napi_delete_element
      • napi_define_properties (incomplete)
      • napi_object_freeze
      • napi_object_seal
  • Working with JavaScript functions
  • Object wrap
  • Simple asynchronous operations
    • napi_create_async_work
    • napi_delete_async_work
    • napi_queue_async_work
    • napi_cancel_async_work
  • Custom asynchronous operations
    • napi_async_init
    • napi_async_destroy
    • napi_make_callback
    • napi_open_callback_scope
    • napi_close_callback_scope
  • Version management
    • napi_get_node_version
    • napi_get_version
  • Memory management
  • Promises
    • napi_create_promise
    • napi_resolve_deferred
    • napi_reject_deferred
    • napi_is_promise
  • Script execution
    • napi_run_script
  • libuv event loop
    • napi_get_uv_event_loop
  • Asynchronous thread-safe function calls
    • napi_call_threadsafe_function
    • napi_create_threadsafe_function
    • napi_get_threadsafe_function_context
    • napi_acquire_threadsafe_function
    • napi_release_threadsafe_function
    • napi_ref_threadsafe_function
    • napi_unref_threadsafe_function
  • Miscellaneous utilities
    • node_api_get_module_file_name

cli/napi/function.rs Outdated Show resolved Hide resolved
cli/build.rs Outdated Show resolved Hide resolved
Comment on lines 13 to 17
shared.data_finalize = if !(finalize_cb as *const c_void).is_null() {
Some(finalize_cb)
} else {
None
};
Copy link
Member Author

Choose a reason for hiding this comment

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

finialize_cb should just be a Option<napi_finalize> here

Copy link
Member Author

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

https://github.com/denoland/deno/runs/5127562468?check_suite_focus=true#step:34:2786 The WASM streaming tests are failing, it seems to be using the default V8 WASM streaming callback instead of what Deno defines using Deno.core.setWasmStreamingCallback()

EDIT: Fixed

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

@littledivy littledivy changed the title feat: implement Node API feat(npm): implement Node API Oct 5, 2022
@littledivy littledivy merged commit 0b016a7 into denoland:main Oct 5, 2022
@littledivy
Copy link
Member Author

Thank you @DjDeveloperr and @bartlomieju for the help!

@littledivy littledivy mentioned this pull request Oct 9, 2022
25 tasks
littledivy pushed a commit that referenced this pull request Oct 10, 2022
Changes introduced in #13633 have broken the ability to compile for
linux/aarch64 - specifically the use of a `i8` as a char type, which is
an `u8` on linux/aarch64.

This PR:
- Replaces instances of `i8` with the architecture-aware wrapper type
`c_char`
- Skips the use of `--export-dynamic-symbol` on linux-aarch64, because
the target environments often rely on older libc/binutils versions
bartlomieju pushed a commit that referenced this pull request Oct 17, 2022
Changes introduced in #13633 have broken the ability to compile for
linux/aarch64 - specifically the use of a `i8` as a char type, which is
an `u8` on linux/aarch64.

This PR:
- Replaces instances of `i8` with the architecture-aware wrapper type
`c_char`
- Skips the use of `--export-dynamic-symbol` on linux-aarch64, because
the target environments often rely on older libc/binutils versions
littledivy added a commit that referenced this pull request Jan 14, 2023
This commit removes the libuv pollyfills introduced with Node-API
support.

It is too much Node-specific. Most Node-API modules that depend on libuv
are already giving up the benefits of Node-API. We should rather
encourage modules to use `ThreadSafeFunction` or `AsyncWork` to
interface with the event loop.

Relevant discussion a few months ago:
#13633 (comment)

cc @bartlomieju
bartlomieju pushed a commit that referenced this pull request Jan 16, 2023
This commit removes the libuv pollyfills introduced with Node-API
support.

It is too much Node-specific. Most Node-API modules that depend on libuv
are already giving up the benefits of Node-API. We should rather
encourage modules to use `ThreadSafeFunction` or `AsyncWork` to
interface with the event loop.

Relevant discussion a few months ago:
#13633 (comment)

cc @bartlomieju
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-test-flaky put this on a PR to run concurrent workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPM support did not resolve the node dependencies (knex, better-sqlite3)
10 participants