8000 GitHub - fengmk2/quick-start: Quick start with Compilets.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fengmk2/quick-start

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quick start with Compilets

This repo demonstrates how to compile a TypeScript source file into C++ and then build a native Node.js module from it.

Only works on Linux and macOS, Windows is currently not supported.

Get started

Clone the repo:

git clone https://github.com/compilets/quick-start.git

Install deps and start building:

cd quick-start
npm install

Run the benchmark script:

./benchmark.js

Exploration

To convert a TypeScript project, run compilets gen, which creates a C++ project under the cpp-project/ directory.

$ npx compilets gen
Done. Made 50 targets from 79 files in 521ms
$ ls cpp-project/
BUILD.gn         eratosthenes.cpp out/
cpp/             eratosthenes.h

The eratosthenes.h and eratosthenes.cpp files are converted from the eratosthenes.ts file, which include both the translated C++ implementation of the TypeScript code, and extra bindings code for Node.js native module.

The BUILD.gn and a hidden file .gn are the configuration files of GN build system, the out/ directory stores build files, and cpp/ directory contains dependencies used by the generated project.

To build the C++ project, run compilets build, and a eratosthenes.node file will be generated under cpp-project/out/Release, which is the built native module.

$ npx compilets build
ninja: Entering directory `out/Release'
ninja: no work to do.
$ node -e "console.log(require('./cpp-project/out/Release/quick-start.node'))"
{
  sieveOfEratosthenes: [Function (anonymous)],
  isPrimeNumber: [Function (anonymous)]
}

License

Public domain

About

Quick start with Compilets.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 61.5%
  • TypeScript 38.5%
0