nodejs / node-api-headers

Repository used to make the N-API headers more accessible
MIT License
32 stars 13 forks source link

Provide def file for windows import lib #15

Closed Pospelove closed 1 year ago

Pospelove commented 1 year ago

required for https://github.com/microsoft/vcpkg/pull/29743

this can be done during sync-headers processing https://github.com/nodejs/node-api-headers/blob/main/.github/workflows/sync-headers.yml

the following code may be used to generate .def file

// https://github.com/cmake-js/cmake-js/blob/e2452ee226490bc666d286ab0860aeb35fbbb035/lib/cMake.js#L293

const headers = require('.');

// Compile a Set of all the symbols that could be exported
const allSymbols = new Set()
for (const ver of Object.values(headers.symbols)) {
    for (const sym of ver.node_api_symbols) {
        allSymbols.add(sym)
    }
    for (const sym of ver.js_native_api_symbols) {
        allSymbols.add(sym)
    }
}

// Write a 'def' file for NODE.EXE
const allSymbolsArr = Array.from(allSymbols)
require('fs').writeFileSync("./node.def", 'NAME NODE.EXE\nEXPORTS\n' + allSymbolsArr.join('\n'))
legendecas commented 1 year ago

Thanks for bringing this up. Are you interested in submitting a PR for this?

Pospelove commented 1 year ago

I think so, at some point. I'm dedicated to other tasks these days. But I'll probably get back to this later. I just wanted to leave details here as a reminder to myself (and for someone who theoretically could resolve that issue)

mhdawson commented 1 year ago

We discussed in the Node-api team meeting today and agreed this is a good idea.

We will want two defs files to be created:

node_api.def js_native_api.def

Where the node_api.def contains all of the symbols and the js_native_api.def one will only include those which are part of the js_native_api_symbols list.

We'd be happy if you can create a PR for that.

kkocdko commented 1 year ago

Here's a simple solution, to generate def file in CMakeLists.txt or other build script:

node -e "let a=require('./symbols.js').v8;console.log('LIBRARY node.exe\nEXPORTS\n'+[...a.node_api_symbols,...a.js_native_api_symbols].join('\n'))" >libnode.def

And thanks for your PR.