Skip to content

Commit

Permalink
feat: add napi-header to third-party packages (#382)
Browse files Browse the repository at this point in the history
* feat: add napi-header to third-party packages

* fix: refine codes

---------

Co-authored-by: Hu Yueh-Wei <[email protected]>
  • Loading branch information
sunxilin and halajohn authored Dec 9, 2024
1 parent 880dccc commit 4c4ad5b
Show file tree
Hide file tree
Showing 42 changed files with 2,858 additions and 4 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pool("serialized_action_pool") {
group("ten_framework_all") {
deps = [
"//core/src/ten_runtime",
"//core/src/ten_runtime/binding",
"//core/src/ten_rust",
"//packages/core_apps",
"//packages/core_extensions",
Expand Down
1 change: 1 addition & 0 deletions build/ten_runtime/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare_args() {
declare_args() {
ten_enable_go_binding = true
ten_enable_python_binding = true
ten_enable_nodejs_binding = true
}

# ten_runtime extensions
Expand Down
12 changes: 12 additions & 0 deletions core/include_internal/ten_runtime/binding/nodejs/app/app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#include "ten_runtime/ten_config.h"

#include "include_internal/ten_runtime/binding/nodejs/common/nodejs_stuff.h"

TEN_RUNTIME_API napi_value ten_nodejs_app_module_init(napi_env env,
napi_value exports);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#pragma once

#include "include_internal/ten_runtime/binding/nodejs/common/nodejs_stuff.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#pragma once

#include <node_api.h>
4 changes: 4 additions & 0 deletions core/src/ten_runtime/binding/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ glob("binding") {
if (ten_enable_python_binding) {
deps += [ "python" ]
}

if (ten_enable_nodejs_binding) {
deps += [ "nodejs" ]
}
}
48 changes: 48 additions & 0 deletions core/src/ten_runtime/binding/nodejs/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright © 2024 Agora
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/feature/ten_package.gni")
import("//build/options.gni")
import("//build/ten_runtime/feature/publish.gni")
import("//build/ten_runtime/options.gni")
import("//build/ten_runtime/ten.gni")
import("//core/src/ten_runtime/output_libs.gni")

ten_package("ten_nodejs_binding_system_package") {
package_kind = "system"
package_output_root_dir_name = "ten_runtime_nodejs"

resources = [
"//core/src/ten_runtime/binding/nodejs/interface=>interface",
"manifest.json",
]

foreach(lib, ten_runtime_nodejs_output_libs) {
libname = get_path_info(rebase_path(lib), "file")
resources += [ "${lib}=>lib/${libname}" ]
}

deps = [ "native:ten_runtime_nodejs" ]
}

if (ten_enable_package_manager) {
ten_package_publish("upload_ten_nodejs_binding_system_package_to_server") {
base_dir =
rebase_path("${root_out_dir}/ten_packages/system/ten_runtime_nodejs")
deps = [
":ten_nodejs_binding_system_package",
"native:ten_runtime_nodejs",
]
}
}

group("nodejs") {
deps = [ "native:ten_runtime_nodejs" ]

if (ten_enable_package_manager) {
deps += [ ":upload_ten_nodejs_binding_system_package_to_server" ]
}
}
6 changes: 6 additions & 0 deletions core/src/ten_runtime/binding/nodejs/interface/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
21 changes: 21 additions & 0 deletions core/src/ten_runtime/binding/nodejs/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "system",
"name": "ten_runtime_nodejs",
"version": "0.4.2",
"dependencies": [
{
"type": "system",
"name": "ten_runtime",
"version": "0.4.2"
}
],
"package": {
"include": [
"manifest.json",
"BUILD.gn",
"interface/**",
"tools/**",
"lib/**"
]
}
}
35 changes: 35 additions & 0 deletions core/src/ten_runtime/binding/nodejs/native/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright © 2024 Agora
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/ten.gni")

config("ten_runtime_nodejs_config") {
include_dirs = ten_runtime_common_includes
include_dirs += [ "//third_party/node-api-headers/include" ]

if (!is_win) {
cflags = [ "-fPIC" ]
}
}

ten_shared_library("ten_runtime_nodejs") {
configs = [ ":ten_runtime_nodejs_config" ]

if (is_mac || is_linux) {
add_configs = [ "//.gnfiles/build/toolchain/common:allow_undefined" ]
remove_configs = [ "//.gnfiles/build/toolchain/common:disallow_undefined" ]
}

sources = [
"//core/src/ten_runtime/binding/nodejs/native/build_template/preserved_metadata.c",
"init.c",
]

deps = [
"app",
"//core/src/ten_runtime:ten_runtime_library",
]
}
14 changes: 14 additions & 0 deletions core/src/ten_runtime/binding/nodejs/native/app/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright © 2024 Agora
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/glob.gni")

glob("app") {
configs = [
"//core/src/ten_runtime/binding/nodejs/native:ten_runtime_nodejs_config",
]
file_list = all_native_files
}
13 changes: 13 additions & 0 deletions core/src/ten_runtime/binding/nodejs/native/app/app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#include "include_internal/ten_runtime/binding/nodejs/app/app.h"

#include "include_internal/ten_runtime/binding/nodejs/common/common.h"

napi_value ten_nodejs_app_module_init(napi_env env, napi_value exports) {
return exports;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#include "include_internal/ten_runtime/common/preserved_metadata.h"

static char metadata[] = "version=0.1.0";

void ten_preserved_metadata(void) {
((char volatile *)metadata)[0] = metadata[0];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#include "include_internal/ten_runtime/common/preserved_metadata.h"

static char metadata[] = "version={{ VERSION }}";

void ten_preserved_metadata(void) {
((char volatile *)metadata)[0] = metadata[0];
}
15 changes: 15 additions & 0 deletions core/src/ten_runtime/binding/nodejs/native/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright © 2024 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#include "include_internal/ten_runtime/binding/nodejs/app/app.h"
#include "include_internal/ten_runtime/binding/nodejs/common/common.h"

napi_value Init(napi_env env, napi_value exports) {
ten_nodejs_app_module_init(env, exports);
return exports;
}

NAPI_MODULE(ten_runtime_nodejs, Init)
4 changes: 0 additions & 4 deletions core/src/ten_runtime/binding/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,4 @@ group("python") {
if (ten_enable_package_manager) {
deps += [ ":upload_ten_python_binding_system_package_to_server" ]
}

if (ten_enable_package_manager) {
deps += [ ":upload_ten_python_binding_system_package_to_server" ]
}
}
8 changes: 8 additions & 0 deletions core/src/ten_runtime/output_libs.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ if (is_linux) {
ten_runtime_go_output_libs = [ "${root_out_dir}/libten_runtime_go.so" ]
ten_runtime_python_output_libs =
[ "${root_out_dir}/libten_runtime_python.so" ]
ten_runtime_nodejs_output_libs =
[ "${root_out_dir}/libten_runtime_nodejs.so" ]
} else if (is_mac) {
ten_runtime_go_output_libs = [ "${root_out_dir}/libten_runtime_go.dylib" ]
ten_runtime_python_output_libs =
[ "${root_out_dir}/libten_runtime_python.dylib" ]
ten_runtime_nodejs_output_libs =
[ "${root_out_dir}/libten_runtime_nodejs.dylib" ]
} else if (is_win) {
ten_runtime_go_output_libs = [
"${root_out_dir}/ten_runtime_go.dll",
Expand All @@ -37,6 +41,10 @@ if (is_linux) {
"${root_out_dir}/ten_runtime_python.dll",
"${root_out_dir}/ten_runtime_python.dll.lib",
]
ten_runtime_nodejs_output_libs = [
"${root_out_dir}/ten_runtime_nodejs.dll",
"${root_out_dir}/ten_runtime_nodejs.dll.lib",
]
}

template("ten_runtime_copy_deps") {
Expand Down
3 changes: 3 additions & 0 deletions third_party/node-api-headers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
node_modules/

2 changes: 2 additions & 0 deletions third_party/node-api-headers/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripts/
.github/
3 changes: 3 additions & 0 deletions third_party/node-api-headers/.release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "1.4.0"
}
101 changes: 101 additions & 0 deletions third_party/node-api-headers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# node-api-headers Changelog

## [1.4.0](https://github.com/nodejs/node-api-headers/compare/v1.3.0...v1.4.0) (2024-10-30)


### Features

* **no-release:** add conditional support in `#if` ([#52](https://github.com/nodejs/node-api-headers/issues/52)) ([e1b8feb](https://github.com/nodejs/node-api-headers/commit/e1b8feb060cf85522538ec1b8a1d6eb782620022))
* update headers from nodejs/node tag v23.1.0 ([#56](https://github.com/nodejs/node-api-headers/issues/56)) ([3336912](https://github.com/nodejs/node-api-headers/commit/33369124c7f8a670422a0c5a27ad149da83ed8d6))

## [1.3.0](https://github.com/nodejs/node-api-headers/compare/v1.2.0...v1.3.0) (2024-09-04)


### Features

* update headers from nodejs/node tag v22.7.0 ([#48](https://github.com/nodejs/node-api-headers/issues/48)) ([6c73c34](https://github.com/nodejs/node-api-headers/commit/6c73c34b72e836531530f863eac315bd42e4569e))

## [1.2.0](https://github.com/nodejs/node-api-headers/compare/node-api-headers-v1.1.0...node-api-headers-v1.2.0) (2024-07-09)


### Features

* update headers from nodejs/node tag v22.1.0 ([d5cfe19](https://github.com/nodejs/node-api-headers/commit/d5cfe19da8b974ca35764dd1c73b91d57cd3c4ce))

## 2023-08-05 Version 1.1.0, @NickNaso

### Notable changes

- Update headers from nodejs/node tag v20.3.0.

### Commits

- \[[`1f5a85dbb0`](https://github.com/nodejs/node-api-headers/commit/1f5a85dbb0)] - Update headers from nodejs/node tag v20.3.0 (#30) (github-actions\[bot])

## 2023-05-18 Version 1.0.1, @NickNaso

### Notable changes

- Update headers from nodejs/node tag v20.2.0.

### Commits

- \[[`d61451e6a3`](https://github.com/nodejs/node-api-headers/commit/d61451e6a3)] - Update headers from nodejs/node tag v20.2.0 (#27) (github-actions\[bot])

## 2023-04-20 Version 1.0.0, @NickNaso

### Notable changes

- Explain package version rationale.
- Update headers from nodejs/node tag v19.9.0.

### Commits

- \[[`130338da33`](https://github.com/nodejs/node-api-headers/commit/130338da33)] - **doc**: explain package version rationale (#26) (Chengzhong Wu)
- \[[`1a328031da`](https://github.com/nodejs/node-api-headers/commit/1a328031da)] - Update headers from nodejs/node tag v19.9.0 (#24) (github-actions\[bot])

## 2023-04-06 Version 0.0.5, @NickNaso

### Notable changes

- Provide def file for windows import lib.

### Commits

- \[[`15477c5898`](https://github.com/nodejs/node-api-headers/commit/15477c5898)] - Update headers from nodejs/node tag v19.8.1 (#22) (github-actions\[bot])
- \[[`d7fa23b60e`](https://github.com/nodejs/node-api-headers/commit/d7fa23b60e)] - Use git status instead of git diff for change calculation (#21) (Kevin Eady)
- \[[`ea0dc01425`](https://github.com/nodejs/node-api-headers/commit/ea0dc01425)] - **fix**: moved def files on a proper folder. (#19) (Nicola Del Gobbo)
- \[[`069c3eb6f8`](https://github.com/nodejs/node-api-headers/commit/069c3eb6f8)] - **doc**: how to create a new release. (#18) (Nicola Del Gobbo)
- \[[`d23c2879c8`](https://github.com/nodejs/node-api-headers/commit/d23c2879c8)] - Provide def file for windows import lib (#17) (Leonid Pospelov)

## 2023-03-17 Version 0.0.4, @NickNaso

### Notable changes

- Update headers from nodejs/node tag v19.8.0.

### Commits

- \[[`a1f0d41240`](https://github.com/nodejs/node-api-headers/commit/a1f0d41240)] - Merge pull request #14 from nodejs/update-headers/v19.8.0 (Nicola Del Gobbo)
- \[[`7548267285`](https://github.com/nodejs/node-api-headers/commit/7548267285)] - Update headers from nodejs/node tag v19.8.0 (github-actions\[bot])

## 2023-03-08 Version 0.0.3, @NickNaso

### Notable changes

- Add helper scripts for updating headers and symbols.js.

### Commits

- \[[`4fdbdd1710`](https://github.com/nodejs/node-api-headers/commit/4fdbdd1710)] - Update headers from nodejs/node tag v19.6.0 (#9) (github-actions\[bot])
- \[[`ecefbdd00f`](https://github.com/nodejs/node-api-headers/commit/ecefbdd00f)] - Add helper scripts for updating headers and symbols.js (#7) (Kevin Eady)

## 2022-12-29 Version 0.0.2, @NickNaso

### Notable changes

- Fixed wrong symblos in v6.

### Commits

- \[[`9c0b4ecaa5`](https://github.com/nodejs/node-api-headers/commit/9c0b4ecaa5)] - **fix**: wrong symblos in v6 (#6) (Nicola Del Gobbo)
4 changes: 4 additions & 0 deletions third_party/node-api-headers/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Code of Conduct

The Node.js Code of Conduct, which applies to this project, can be found at
https://github.com/nodejs/admin/blob/master/CODE_OF_CONDUCT.md.
Loading

0 comments on commit 4c4ad5b

Please sign in to comment.