Skip to content

Commit ae9c6cf

Browse files
authored
Strip symbols from linux binary, update readme (microsoft#69)
1 parent c456551 commit ae9c6cf

File tree

10 files changed

+27
-23
lines changed

10 files changed

+27
-23
lines changed

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
44
<LangVersion>10</LangVersion>
55
<Nullable>enable</Nullable>
6-
<PublishAot Condition=" '$(TargetFramework)' == 'net7.0' ">true</PublishAot>
76
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
87
<BaseOutputPath>$(MSBuildThisFileDirectory)out/</BaseOutputPath>
98
<OutputPath>$(BaseOutputPath)bin/$(Configuration)/$(MSBuildProjectName)/</OutputPath>

Docs/node-module.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ For a minimal example of this scenario, see
107107
```xml
108108
<TargetFramework>net7.0</TargetFramework>
109109
<PublishAot>true</PublishAot>
110-
<NativeLib>Shared</NativeLib>
111110
<PublishNodeModule>true</PublishNodeModule>
112111
```
113112
Then publish the project to produce the native module (with `.node` extension):

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Call nearly any .NET APIs in-proc from JavaScript code, with high performance an
44
type-checking. The interop uses [Node API](https://nodejs.org/api/n-api.html) so it is compatible
55
with any Node.js version (without rebuilding) or other JavaScript engine that supports Node API.
66

7-
_**Status: In Development** - Core functionality works, but many things are incomplete, and it
8-
isn't yet all packaged up nicely in a way that can be easily consumed._
7+
:warning: _**Status: In Development** - Core functionality works, but many things are incomplete,
8+
and it isn't yet all packaged up nicely in a way that can be easily consumed._
9+
10+
[Instructions for getting started are below.](#getting-started)
911

1012
### Minimal example
1113
```JavaScript
@@ -33,12 +35,10 @@ const MyType = ExampleAssembly['Namespace.Qualified.MyType'];
3335

3436
### Generate type definitions for .NET APIs
3537
If writing TypeScript, or type-checked JavaScript, there is a tool to generate type `.d.ts` type
36-
definitions for .NET APIs. It also generates a small `.js` file that exports the assembly in a more
37-
natural way as a JS module:
38+
definitions for .NET APIs. Soon, it should also generate a small `.js` file that exports the
39+
assembly in a more natural way as a JS module.
3840
```bash
39-
$ node-api-dotnet-ts-gen "path/to/ExampleAssembly.dll"
40-
Generated ExampleAssembly.js
41-
Generated ExampleAssembly.d.ts
41+
$ npm exec node-api-dotnet-generator --assembly ExampleAssembly.dll --typedefs ExampleAssembly.d.ts
4242
```
4343
```TypeScript
4444
import { ExampleClass } from './ExampleAssembly';
@@ -90,7 +90,7 @@ assembly). The source generator also enables building ahead-of-time compiled lib
9090
can be called by JavaScript without depending on the .NET Runtime. (More on that below.)
9191

9292
### Optionally work directly with JS types in C#
93-
The class library includes an object model of for JavaScript type system. `JSValue` represents a
93+
The class library includes an object model for the JavaScript type system. `JSValue` represents a
9494
value of any type, and there are more types like `JSObject`, `JSArray`, `JSMap`, `JSPromise`, etc.
9595
C# code can work directly with those types if desired:
9696

@@ -111,14 +111,16 @@ public static JSPromise JSAsyncExample(JSValue input)
111111
### Automatic efficient marshaling
112112
There are two ways to get automatic marshaling between C# and JavaScript types:
113113
1. Compile a C# class library with `[JSExport]` attributes like the examples above. The source
114-
generator generates marshaling code that is compiled with the assembly.
114+
generator produces marshaling code that is compiled with the assembly.
115115

116116
2. Load a pre-built .NET assembly, as in the earlier examples. The loader will use reflection to
117117
scan the APIs, then emit marshaling code on-demand for each type that is referenced by JS. The
118-
code is logically equivalent to that from the source generator, but is instead emitted as IL
119-
using the [.NET System.Reflection.Emit APIs](https://learn.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/emitting-dynamic-methods-and-assemblies). So there is a small startup cost
120-
from that reflection and IL emitting, but subsequent calls to the same APIs may be just as fast
121-
as the pre-compiled marshaling code (and are just as likely to be JITted).
118+
dynamic marshalling code is derived from the same expression trees that are used for compile-time
119+
source-generation, but is generated and at runtime and compiled with
120+
[`LambdaExpression.Compile()`](https://learn.microsoft.com/en-us/dotnet/api/system.linq.expressions.lambdaexpression.compile).
121+
So there is a small startup cost from that reflection and compilation, but subsequent calls to
122+
the same APIs may be just as fast as the pre-compiled marshaling code (and are just as likely
123+
to be JITted).
122124

123125
The marshaller uses the strong typing information from the C# API declarations as hints about how to
124126
convert values beteen JavaScript and C#. Here's a general summary of conversions:
@@ -156,7 +158,7 @@ There are advantages and disadvantages to either approach:
156158
|---------------------|--------------|-----------------|
157159
| API compatibility | Broad compatibility with .NET APIs | Limited compatibility with APIs designed to support AOT |
158160
| Ease of deployment | Requires a matching version of .NET to be installed on the target system | A .NET installation is not required (though some platform libs may be required on Linux/Mac)
159-
| Size of deployment | Compact - only IL assemblies need to be deployed | Larger due to building necessary runtime code - minimum 3 MB on Windows, ~13 MB on Linux |
161+
| Size of deployment | Compact - only IL assemblies need to be deployed | Larger due to bundling necessary runtime code - minimum ~3 MB per platform |
160162
| Performance | Slightly slower startup (JIT) | Slightly faster startup (no JIT) |
161163
| Runtime limitations | Full .NET functionality | Some .NET features like reflection and code-generation aren't supported |
162164

@@ -182,6 +184,7 @@ Thanks to these design choices, JS to .NET calls are [more than twice as fast](
182184
#### Requirements
183185
- .NET 6 or later
184186
- .NET 7 or later is required for AOT support.
187+
- .NET Framework 4.x support is [coming soon](https://github.com/microsoft/node-api-dotnet/pull/51).
185188
- Node.js v16 or later
186189
- Other JS engines may be supported in the future.
187190
- OS: Windows, Mac, or Linux

examples/aot-module/aot-module.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<PublishAot>true</PublishAot>
8-
<NativeLib>Shared</NativeLib>
98
<PublishNodeModule>true</PublishNodeModule>
109
<PublishDir>bin</PublishDir>
1110
</PropertyGroup>

src/NodeApi.DotNetHost/NodeApi.DotNetHost.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<RootNamespace>Microsoft.JavaScript.NodeApi.DotNetHost</RootNamespace>
66
<IsPackable>true</IsPackable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8-
<PublishAot>false</PublishAot>
98
</PropertyGroup>
109

1110
<ItemGroup>

src/NodeApi.Generator/NodeApi.Generator.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<RootNamespace>Microsoft.JavaScript.NodeApi.Generator</RootNamespace>
66
<OutputType>Exe</OutputType>
77
<IsPackable>true</IsPackable>
8-
<PublishAot>false</PublishAot>
98
<NoWarn>$(NoWarn);SYSLIB1045</NoWarn><!-- Use GeneratedRegexAttribute -->
109
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
1110
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

src/NodeApi/NodeApi.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
<RootNamespace>Microsoft.JavaScript.NodeApi</RootNamespace>
66
<IsPackable>true</IsPackable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8-
<NativeLib>Shared</NativeLib>
98
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
1012
<SelfContained>false</SelfContained>
13+
<PublishAot>true</PublishAot>
14+
<StripSymbols>true</StripSymbols>
1115
<PublishNodeModule>true</PublishNodeModule>
1216
</PropertyGroup>
1317

src/NodeApi/NodeApi.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
BeforeTargets="PublishManagedAssembly"
55
Condition=" '$(PublishNodeModule)' == 'true' "
66
>
7-
<!-- Rename the native library (and its PDB) to have a .node extension. -->
7+
<!-- Rename the native library (and its symbols file) to have a .node extension. -->
88
<Move SourceFiles="$(PublishDir)$(TargetName)$(NativeBinaryExt)"
99
DestinationFiles="$(PublishDir)$(TargetName).node" />
1010
<Move Condition="Exists('$(PublishDir)$(TargetName).pdb')"
1111
SourceFiles="$(PublishDir)$(TargetName).pdb"
1212
DestinationFiles="$(PublishDir)$(TargetName).node.pdb" />
13+
<Move Condition="Exists('$(PublishDir)$(TargetName).so.dbg')"
14+
SourceFiles="$(PublishDir)$(TargetName).so.dbg"
15+
DestinationFiles="$(PublishDir)$(TargetName).node.dbg" />
1316
</Target>
1417
</Project>

test/NodeApi.Test.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<RootNamespace>Microsoft.JavaScript.NodeApi.Test</RootNamespace>
55
<AssemblyName>Microsoft.JavaScript.NodeApi.Test</AssemblyName>
66
<IsPublishable>false</IsPublishable>
7-
<PublishAot>false</PublishAot>
87
</PropertyGroup>
98

109
<ItemGroup>

test/TestCases/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<Import Project="../../Directory.Build.props" />
33

44
<PropertyGroup>
5-
<NativeLib>Shared</NativeLib>
65
<BaseIntermediateOutputPath>$(BaseOutputPath)obj/$(Configuration)/TestCases/$(MSBuildProjectName)/</BaseIntermediateOutputPath>
76
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
87
<OutputPath>$(BaseOutputPath)bin/$(Configuration)/TestCases/$(MSBuildProjectName)/</OutputPath>
8+
<PublishAot>true</PublishAot>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<NoWarn>CS1591</NoWarn>
1111

0 commit comments

Comments
 (0)