Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Napi support package c++ static binary. #235

Merged
merged 8 commits into from
Oct 24, 2022

Conversation

shibd
Copy link
Member

@shibd shibd commented Oct 14, 2022

Motivation

Currently, users using the node js client must first install the C++ client. And when the user executes npm install, it also needs to be compiled. This is not user-friendly.

This PR is to provide pre-built packages for all the supported environments, using GYP and rebuild. The pre-built package is then uploaded to Github Release, and when the user installs the client, the system version is matched and the pre-built package is downloaded.

Currently tested linux_glibc_x86_64, linuc_musl_x86_64, linux_glibc_arm64, linuc_musl_arm64 and mac_x86_64. I've built it in my fork repository and can install it directly using the following command (without first installing the C++ client).

npm install shibaodi-pulsar-client

Modifications

New Github workflows

  • When trigger release:
    1. Build the binary C++ static library first(use new c++ client 3.0 source).
    2. And use node-pre-gyp pre-built napi packages.
    3. Use node-pre-gyp-github publish this package to GitHub Release.
  • When trigger unit test(use ubuntu GitHub runner):
    1. Install c++ lib(use new c++ client 3.0 version).
    2. Use this c++ lib build napi.
    3. Use pulsar image start broker(use pulsar latest).
    4. Run the unit test.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

TODO

  • Add pre-build windows binary package.
  • Change user docs.

Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you rename the directory name from certificate to test-conf?

@shibd
Copy link
Member Author

shibd commented Oct 14, 2022

Why do you rename the directory name from certificate to test-conf?

Just for the unified, put all the test-related configurations together.

@BewareMyPower
Copy link
Contributor

Just for the unified

There is no need to make two separate repositories consistent. What if the Python client repo renamed the directory or adjust the hierarchy later? In this case, do you also want to sync the changes here? People who are interested in Node.js client might not be interested in Python client. That's why do we separate C++/Python repos.

From my perspective, if you have a huge PR, please remove unnecessary changes as much as possible.

@shibd
Copy link
Member Author

shibd commented Oct 14, 2022

From my perspective, if you have a huge PR, please remove unnecessary changes as much as possible.

Make sense. I removed unnecessary changes. PTAL.

@shibd
Copy link
Member Author

shibd commented Oct 19, 2022

Currently completed:

  • linux_glibc_x86_64
  • linux_musl_x86_64
  • linux_glibc_arm64
  • linux_musl_arm64
  • macOS_x86_64

Please refer to my repo release: https://github.com/shibd/pulsar-client-node/releases/tag/v1.8.1-rc.3

Other environments:

  • macOS_arm64: Not supported at the moment. Although the cpp client can be properly compiled on the x86_64 by cross-compilation, it is not successful when packaging NAPI. Maybe we need a macOS_m1 runner to run the compilation.
  • windows_x86_64: I'm doing compilation testing, which will be added later.

@merlimat Do you feel there are other environments that need support?

@BewareMyPower @merlimat This PR can be reviewed first when you have time. Thanks.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice to see such progress on the packaging!

.github/workflows/ci-build-release-napi.yml Outdated Show resolved Hide resolved
.github/workflows/ci-pr-validation.yml Outdated Show resolved Hide resolved
pkg/mac/build-cpp-deps-lib.sh Outdated Show resolved Hide resolved
pkg/mac/build-cpp-lib.sh Show resolved Hide resolved
pulsar-client-cpp-version.txt Show resolved Hide resolved
src/pulsar-binding.js Show resolved Hide resolved
@merlimat
Copy link
Contributor

macOS_arm64: Not supported at the moment. Although the cpp client can be properly compiled on the x86_64 by cross-compilation, it is not successful when packaging NAPI. Maybe we need a macOS_m1 runner to run the compilation.

We can try to find a way to cross-compile. Right now there are no M1 runners in GH actions.
Let this not be a blocker.

@shibd
Copy link
Member Author

shibd commented Oct 22, 2022

We can try to find a way to cross-compile. Right now there are no M1 runners in GH actions.
Let this not be a blocker.

Hi, @merlimat I can cross-compile libpulsarwithdeps.a, but I can't cross-compile napi. I tried using the command --target_arch=arm64, but it doesn't work. You can refer to failed job: https://github.com/shibd/pulsar-client-node/actions/runs/3294556450/jobs/5432190252

I raised an issue here and haven't waited for a response yet.

I'll finish compiling Windows first and then continue working on it here.

If you have a good idea, please recommend it to me. Thanks.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good! Let's target windows build in a new PR

build-support/pulsar-test-service-stop.sh Show resolved Hide resolved
build-support/stage-release.sh Outdated Show resolved Hide resolved
@merlimat merlimat merged commit 10ef71a into apache:master Oct 24, 2022
@massakam massakam added this to the 1.8.0 milestone Oct 26, 2022
BewareMyPower pushed a commit that referenced this pull request Nov 1, 2022
### Motivation

#235 

Support windows build napi of static link c++ lib(x64 and x86).

### Modifications
- Download the C++ static library directly instead of recompiling

**Note**: Since there is no static library release for C++ yet, Use a [temporary release](https://github.com/BewareMyPower/pulsar-client-cpp/releases/tag/v3.1.0-rc-20221026-windows).
@shibd shibd mentioned this pull request Nov 4, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants