Skip to content

Commit

Permalink
feat: add nodejs addon loader
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxilin committed Jan 10, 2025
1 parent e73dcfb commit bf5a9ff
Show file tree
Hide file tree
Showing 2,401 changed files with 1,005,249 additions and 54 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/build_node_shared.yml

This file was deleted.

18 changes: 12 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
"args": [
"--gtest_filter=ExtensionTest.ExtensionSendMsgToIncorrectEngine"
"--gtest_filter=AudioFrameTest.MultiDestAudioFrame"
],
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
"env": {
Expand Down Expand Up @@ -492,9 +492,9 @@
"name": "app (C/C++) (lldb, launch)",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app/bin/cpp_app_python_app_source",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/nodejs/cpp_app_nodejs/cpp_app_nodejs_app/bin/cpp_app_nodejs_app_source",
"args": [],
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app",
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/nodejs/cpp_app_nodejs/cpp_app_nodejs_app",
"env": {
"ASAN_OPTIONS": "use_sigaltstack=0",
},
Expand All @@ -503,15 +503,21 @@
"name": "app (C/C++) (cppdbg, launch)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/cpp/graph_env_var_1/graph_env_var_1_app/bin/graph_env_var_1_app_source",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/nodejs/cpp_app_nodejs/cpp_app_nodejs_app/bin/cpp_app_nodejs_app_source",
"args": [],
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/cpp/graph_env_var_1/graph_env_var_1_app",
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/nodejs/cpp_app_nodejs/cpp_app_nodejs_app",
"sourceFileMap": {
"${workspaceFolder}": {
"editorPath": "${workspaceFolder}",
"useForBreakpoints": "true"
}
}
},
"environment": [
{
"name": "NODE_PATH",
"value": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/nodejs/cpp_app_nodejs/cpp_app_nodejs_app/ten_packages/system/ten_runtime_nodejs/lib:$NODE_PATH"
}
]
},
{
"name": "app (C/C++) (cppdbg, attach)",
Expand Down
120 changes: 120 additions & 0 deletions build/ten_common/prebuilt/prebuilt.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#
# Copyright © 2025 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/options.gni")

template("ten_prebuilt_library") {
assert(defined(invoker.url), "Must provide dist url")

_dir_path = "prebuilt/${invoker.name}/lib"
_zip_path = "${_dir_path}/${invoker.name}.zip"

_download_target = "${target_name}_lib_download"
action(_download_target) {
script = "//build/ten_common/scripts/download.py"

_source_file = "${invoker.url}"
_dest_file = "${root_out_dir}/${_zip_path}"

args = [
_source_file,
rebase_path(_dest_file),
]

inputs = [ "//build/ten_common/scripts/download.py" ]
outputs = [ _dest_file ]
}

_is_shared_library =
defined(invoker.is_shared_library) && invoker.is_shared_library

_lib_prefix = "lib"
_lib_postfix = ""
if (_is_shared_library) {
if (is_linux) {
_lib_postfix = ".so"
} else if (is_win) {
_lib_postfix = ".dll"
} else if (is_mac) {
_lib_postfix = ".dylib"
} else {
assert(0, "Unsupported platform.")
}
} else {
_lib_postfix = ".a"
}

# Construct the actual library file name.
_lib_file_paths = []
foreach(lib, invoker.libs) {
_lib_file_paths +=
[ "${root_out_dir}/${_dir_path}/${_lib_prefix}${lib}${_lib_postfix}" ]
}

_unzip_target = "${target_name}_lib_unzip"
action(_unzip_target) {
script = "//build/ten_common/scripts/unzip.py"

_source_file = "${root_out_dir}/${_zip_path}"

args = [
rebase_path(_source_file),
rebase_path(_dir_path),
]

inputs = [
_source_file,
"//build/ten_common/scripts/unzip.py",
]

outputs = [ "${root_out_dir}/${_dir_path}" ]
outputs += _lib_file_paths

# Need to complete the downloading first.
deps = [ ":${_download_target}" ]
}

config("${target_name}_config") {
libs = invoker.libs
lib_dirs = [ rebase_path("${root_out_dir}/${_dir_path}") ]

if (defined(invoker.extra_ldflags) && invoker.extra_ldflags != []) {
if (!defined(ldflags)) {
ldflags = []
}

ldflags += invoker.extra_ldflags
}
}

group(target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"data_deps",
"testonly",
"visibility",
])

if (!defined(deps)) {
deps = []
}

# Need to complete the unzip.
deps += [
# ":${_delete_zip_target}",
":${_unzip_target}",
]

# To enable the caller to 'depends' on the prebuilt libraries.
# public_deps = [ ":${_delete_zip_target}" ]
public_deps = [ ":${_unzip_target}" ]

# Inject the header file inclusion path into the caller.
public_configs = [ ":${target_name}_config" ]
}
}
20 changes: 20 additions & 0 deletions build/ten_common/scripts/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright © 2025 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 sys
import requests


def download_file(url, output_path):
response = requests.get(url, stream=True)
response.raise_for_status()
with open(output_path, "wb") as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)


if __name__ == "__main__":
download_file(sys.argv[1], sys.argv[2])
34 changes: 34 additions & 0 deletions build/ten_common/scripts/unzip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright © 2025 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 zipfile
import sys
import os


def unzip_file(src_path, dest_path) -> int | None:
if not os.path.exists(src_path):
return -1

src_dir = os.path.dirname(src_path)
dst_dir = src_dir if dest_path == "" else dest_path
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)

zip_ref = zipfile.ZipFile(src_path, "r")
zip_ref.extractall(dst_dir)
zip_ref.close()


def main(argv):
if len(argv) < 2:
return -1
dest_path = "" if len(argv) < 3 else argv[2]
return unzip_file(argv[0], dest_path)


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2 changes: 1 addition & 1 deletion core/src/ten_runtime/binding/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/src/ten_runtime/binding/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": "tsc --listEmittedFiles"
},
"devDependencies": {
"@types/node": "^18.14.5",
"@types/node": "^18.19.70",
"source-map-support": "^0.5.21",
"typescript": "^5.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion core/ten_gn
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/core_addon_loaders/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ group("core_addon_loaders") {
deps = []

if (ten_enable_python_binding) {
deps += [ "python_addon_loader" ]
deps += [
"nodejs_addon_loader",
"python_addon_loader",
]
}
}
41 changes: 41 additions & 0 deletions packages/core_addon_loaders/nodejs_addon_loader/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0.
# See the LICENSE file for more information.
#
import("//build/feature/ten_package.gni")
import("//build/ten_runtime/feature/publish.gni")
import("//build/ten_runtime/glob.gni")
import("//build/ten_runtime/options.gni")

config("nodejs_addon_loader_config") {
cflags_cc = [ "-std=c++17" ]
}

ten_package("nodejs_addon_loader") {
package_kind = "addon_loader"
enable_build = true

resources = [
"manifest.json",
"property.json",
]

configs = [ ":nodejs_addon_loader_config" ]

sources = [ "src/main.cc" ]
include_dirs = [ "//core" ]

deps = [
"//core/src/ten_runtime",
"//third_party/node",
]
}

if (ten_enable_ten_manager) {
ten_package_publish("upload_nodejs_addon_loader_to_server") {
base_dir = rebase_path(
"${root_out_dir}/ten_packages/addon_loader/nodejs_addon_loader")
deps = [ ":nodejs_addon_loader" ]
}
}
13 changes: 13 additions & 0 deletions packages/core_addon_loaders/nodejs_addon_loader/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright © 2025 Agora

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
18 changes: 18 additions & 0 deletions packages/core_addon_loaders/nodejs_addon_loader/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "addon_loader",
"name": "nodejs_addon_loader",
"version": "0.6.0",
"dependencies": [
{
"type": "system",
"name": "ten_runtime",
"version": "0.6.0"
},
{
"type": "system",
"name": "ten_runtime_nodejs",
"version": "0.6.0"
}
],
"api": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit bf5a9ff

Please sign in to comment.