{"id":13524720,"url":"https://github.com/noppoMan/node-native-extension-in-swift","last_synced_at":"2025-04-01T03:32:26.808Z","repository":{"id":149091906,"uuid":"108419759","full_name":"noppoMan/node-native-extension-in-swift","owner":"noppoMan","description":"An experimental repo for Node.js native addons that written in Swift.","archived":false,"fork":false,"pushed_at":"2019-09-01T13:11:48.000Z","size":10,"stargazers_count":45,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T03:51:26.178Z","etag":null,"topics":["node-native-addons","nodejs","swift"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noppoMan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-10-26T14:05:37.000Z","updated_at":"2024-12-03T12:43:48.000Z","dependencies_parsed_at":"2023-06-30T04:15:21.716Z","dependency_job_id":null,"html_url":"https://github.com/noppoMan/node-native-extension-in-swift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noppoMan%2Fnode-native-extension-in-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noppoMan%2Fnode-native-extension-in-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noppoMan%2Fnode-native-extension-in-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noppoMan%2Fnode-native-extension-in-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noppoMan","download_url":"https://codeload.github.com/noppoMan/node-native-extension-in-swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246578589,"owners_count":20799851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node-native-addons","nodejs","swift"],"created_at":"2024-08-01T06:01:12.772Z","updated_at":"2025-04-01T03:32:26.552Z","avatar_url":"https://github.com/noppoMan.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# node-native-extension-in-swift\n\n\u003cimg width=\"180\" src=\"https://www.shareicon.net/data/512x512/2015/10/06/112654_apple_512x512.png\"\u003e　　　\u003cimg width=\"230\" src=\"https://nodejs.org/static/images/logos/nodejs-new-pantone-black.png\"\u003e\n\nAn experimental repo for [Node.js native addons](https://nodejs.org/api/addons.html) that written in Swift.  \nThe first motivation of implementeing this was reduceing overhead of execution between Node.js and Swift on the Serverless environment.\n\n## Writing native extensions with Swift\n\n1. Define function(s) in a format that can be exported to C/C++ in Swift side.\n\n```swift\n@_cdecl(\"swift_fibonacci\") // Name the function symbol.\npublic func fibonacci(_ n: CInt) -\u003e CInt {\n    if n == 0 {\n        return 0\n    } else if n == 1{\n        return 1\n    }\n    return fibonacci(n - 1) + fibonacci(n - 2)\n}\n```\n\n2. [Register fibonacci as callable function in Node.js (V8 side)](https://github.com/noppoMan/node-native-extension-in-swift/blob/master/swift.cc#L53)\n\n3. The exported functions can be imported and executed in Node.js side.\n\n```js\nconst swift = require('bindings')('swift');\n\nconst result = swift.fibonacci(10);\nconsole.log(result);\n```\n\n\n## Running Example\n\n## Linux\n\n```sh\n$ docker build -t node-native-extension-in-swift .\n$ docker run -t node-native-extension-in-swift\n```\n\n## Mac\n\n```sh\n$ git clone https://github.com/noppoMan/node-native-extension-in-swift.git\n$ cd node-native-extension-in-swift\n$ swift build --package-path NativeExtensionInSwift\n$ npm i\n$ node index.js\n```\n\n## License\nnode-native-extension-in-swift is released under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FnoppoMan%2Fnode-native-extension-in-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FnoppoMan%2Fnode-native-extension-in-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FnoppoMan%2Fnode-native-extension-in-swift/lists"}