Skip to content

Commit

Permalink
add modern node addons ACCU version
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirtz committed Apr 14, 2024
1 parent 2c8d56b commit 2ed05cf
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 1 deletion.
4 changes: 3 additions & 1 deletion slides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

<div class="fragment fade-out" data-fragment-index="0">

- [Modern C++ addons for node.js](modern-js-addons/js_addons.md)
- Modern C++ addons for node.js
- [March 2024, Core C++](modern-js-addons/js_addons.md)
- [April 2004, ACCU](modern-js-addons/accu.md)
- C++23 ranges: conceptual changes and useful practicalities,
- [April 2023, ACCU](ranges_23/ranges.md)
- [June 2023, Core C++](ranges_23/corecpp.md)
Expand Down
235 changes: 235 additions & 0 deletions slides/modern-js-addons/accu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
---
css:
- node_modules/github-fork-ribbon-css/gh-fork-ribbon.css
- css/custom.css
- css/animations.css
- slides/modern-js-addons/modern-js-addons.css
scripts:
- node_modules/jquery/dist/jquery.min.js
- scripts/customize.js
- node_modules/reveal-compiler-explorer/dist/reveal-compiler-explorer.js
- plugins/embed-code/embed-code.js
- scripts/load-plugins.js
- scripts/custom-options.js
---

<!-- .slide: data-background-image="assets/ACCU_title.png" -->

---

<!-- .slide: data-background-image="assets/parquet-viewer.png" data-background-size="contain" -->

---


<!-- .slide: data-background-image="assets/ACCU_2023.png" data-background-size="contain" -->

----

## Node.js Addons

- shared libraries loaded by node.js
- can be imported like node.js modules
- [Node-API](https://nodejs.org/api/n-api.html) C API
- [node-addon-api](https://github.com/nodejs/node-addon-api) C++ header only API

Notes:

Addons are dynamically-linked shared objects that can be loaded into Node.js like JavaScript modules.

Node-API (formerly N-API) is an API for building native Addons. Unlike older APIs (like nan), it is independent from the underlying JavaScript runtime (for example, V8) and is maintained as part of Node.js itself. This API will be Application Binary Interface (ABI) stable across versions of Node.js.

There's also other, unofficial, bindings for other languages like rust, swift and zig.

---

## building a C++ addon

- `node-gyp`
- `CMake.js`

Notes:

node-gyp is the official build system from the Node.js org. It is based on the chromium build system, written in Python and is wide and has widespread adoption and documentation.

However, for C++ developers, it might be more convenient to use CMake, which is a more modern and powerful build system that is widely used in the C++ community.
For that, we can use CMake.js, which is a CMake wrapper integrating with the Node.js ecosystem.

Both tools require a C++ toolchain to be installed on the system. For node-gyp, Python is required and for CMake.js, CMake is required.

---

![`Pipenv`](assets/pipenv.png)

<!-- .element: class="r-stretch" -->

```bash
pipenv install cmake
pipenv run cmake
```

Notes:

`Pipenv` is a tool that automatically creates and manages virtual Python environments. It's main advantages here is the ability to run installed python packages simply with the `pipenv run`command.

---

`Pipfile`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/Pipfile" class="language-ini" data-line-numbers="|7"></code></pre>


---

`package.json`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/package.json" class="language-json" data-line-numbers="16-17,19-21|11-12|5-9"></code></pre>

---

## Node-Api version [matrix](https://nodejs.org/api/n-api.html#node-api-version-matrix)

<table style="font-size: 0.8em" -->
<tr>
<th>Node-API version</th>
<th scope="col">Supported In</th>
</tr>
<tr>
<th scope="row">9</th>
<td>v18.17.0+, 20.3.0+, 21.0.0 and all later versions</td>
</tr>
<tr>
<th scope="row">8</th>
<td>v12.22.0+, v14.17.0+, v15.12.0+, 16.0.0 and all later versions</td>
</tr>
<tr>
<th scope="row">7</th>
<td>v10.23.0+, v12.19.0+, v14.12.0+, 15.0.0 and all later versions</td>
</tr>
<tr>
<th scope="row">6</th>
<td>v10.20.0+, v12.17.0+, 14.0.0 and all later versions</td>
</tr>
</table>

---

`.npmrc`

<pre class="r-stretch"><code data-url="assets/npmrc" class="language-ini" data-line-numbers="12-14"></code></pre>

---

`CMakeLists.txt`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/src/cpp/CMakeLists.txt" class="language-cmake" data-line-numbers="1-3|5-24|39-47"></code></pre>

---

`inteface.cpp`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/src/cpp/interface.cpp" class="language-cpp" data-line-numbers="1|37-44|9-23|25-34|7"></code></pre>

---

`calendar.cxx`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/src/cpp/calendar.cxx" class="language-cpp" data-line-numbers="1-11|81-83|166-179|113-124"></code></pre>

---

`concat.cxx`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/src/cpp/concat.cxx" class="language-cpp" data-line-numbers="1-7|37-41"></code></pre>

---

![conan](assets/conan2-logo-for-dark.svg)

```bash
pipenv install conan
```

Notes:

Conan is a C++ package manager that allows developers to easily manage dependencies and build artifacts for C++ projects. It is widely used in the C++ community and integrates with many build systems and package managers.

---

`.npmrc`

<pre class="r-stretch"><code data-url="assets/npmrc" class="language-ini" data-line-numbers="15"></code></pre>

<!-- .element: style="font-size: 0.45em" -->

https://github.com/conan-io/cmake-conan

---

`CMakeLists.txt`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/src/cpp/CMakeLists.txt" class="language-cmake" data-line-numbers="29-37,50"></code></pre>

---

## demo

----

## deployment

- `node-pre-gyp`
- `prebuild`
- `prebuildify`
- `pkg-prebuilds`

Notes:

`node-pre-gyp` is a tool based on node-gyp that adds the ability to upload binaries to a server of the developer's choice. node-pre-gyp has particularly good support for uploading binaries to Amazon S3.

`prebuild` is a tool that supports builds using either node-gyp or CMake.js. Unlike node-pre-gyp which supports a variety of servers, `prebuild` uploads binaries only to GitHub releases. `prebuild` is a good choice for GitHub projects using CMake.js.

`prebuildify` is a tool based on node-gyp. The advantage of `prebuildify` is that the built binaries are bundled with the native addon when it's uploaded to npm. The binaries are downloaded from npm and are immediately available to the module user when the native addon is installed.

`pkg-prebuild` is built to support cmake-js and be simple.

---

`binding-options.ts`

<pre><code data-url="electron-calendar/packages/calendar-generator/src/ts/binding-options.ts" class="language-typescript" data-line-numbers=""></code></pre>

---

`package.json`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/package.json" class="language-json" data-line-numbers="12"></code></pre>

---

`CMakeLists.txt`

<pre class="r-stretch"><code data-url="electron-calendar/packages/calendar-generator/src/cpp/CMakeLists.txt" class="language-cmake" data-line-numbers="52-55"></code></pre>

---

`interface.ts`

<pre><code data-url="electron-calendar/packages/calendar-generator/src/ts/interface.ts" class="language-typescript" data-line-numbers=""></code></pre>

---

## GitHub actions

![pipeline](assets/pipeline.png)

---

## GitHub actions

<pre><code data-url="https://raw.githubusercontent.com/dvirtz/vscode-parquet-viewer/c109a1dcb7a12b88ab9e3eaee628c7fb4c83a010/.github/workflows/main.yml" class="language-yaml" data-line-numbers="59-65|117-120"></code></pre>

----

<!-- .slide: data-background-image="assets/thank_you.png" data-background-size="contain" -->

Binary file added slides/modern-js-addons/assets/ACCU_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2ed05cf

Please sign in to comment.