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

Build arm64 binaries for mac #2235

Merged
merged 1 commit into from
Oct 5, 2022

Conversation

hayashikun
Copy link
Contributor

For now, pre-compiled binary of grpc-tools is missing for M1 mac (arm64).

#1405

It is possible to run M1 mac by setting npm_config_target_arch=x64, but it is a little bit messy.

It must be straightforward to wait for M1 build machines in GitHub action,
#1405 (comment)

but we can build universal binaries by setting -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" to cmake, and can extract binaries for x86_64/arm64 using lipo.
Or, it would be good to provide universal binaries without separating binaries.

In my Macbook (intel), I can successfully build both x86_64 and arm64 binaries.

$ uname -v
Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
$ cd grpc-node
$ ./packages/grpc-tools/build_binaries.sh
$ cd ./artifacts/grpc-tools/v1.11.2
$ tar -xvf darwin-arm64.tar.gz && tar -xvf darwin-x86_64.tar.gz

$ file x86_64/*
x86_64/grpc_node_plugin: Mach-O universal binary with 1 architecture: [x86_64:Mach-O 64-bit executable x86_64Mach-O 64-bit executable x86_64]
x86_64/grpc_node_plugin (for architecture x86_64):      Mach-O 64-bit executable x86_64
x86_64/protoc:           Mach-O universal binary with 1 architecture: [x86_64:Mach-O 64-bit executable x86_64Mach-O 64-bit executable x86_64]
x86_64/protoc (for architecture x86_64):        Mach-O 64-bit executable x86_64

$ file arm64/*
arm64/grpc_node_plugin: Mach-O universal binary with 1 architecture: [arm64:Mach-O 64-bit executable arm64Mach-O 64-bit executable arm64]
arm64/grpc_node_plugin (for architecture arm64):        Mach-O 64-bit executable arm64
arm64/protoc:           Mach-O universal binary with 1 architecture: [arm64:Mach-O 64-bit executable arm64Mach-O 64-bit executable arm64]
arm64/protoc (for architecture arm64):  Mach-O 64-bit executable arm64

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 2, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: hayashikun / name: Ryosuke Hayashi (2aac1da)

@murgatroid99
Copy link
Member

I ran the build job with this PR, and you can see the result in the PR status checks. Can you manually verify that the artifact produced by the Mac build job works on M1?

@hayashikun
Copy link
Contributor Author

Thanks for running CI.
The artifact built by CI works well in my M1 mac (Macbook Pro).

I uploaded produced artifacts by CI to s3 buckets, and I installed grpc-tools in my M1 mac by the following procedure.
#1405 (comment)

I can successfully installed after setting grpc_tools_binary_host_mirror in .npmrc.
Then, I compiled example.proto using npm installed binaries (that is artifacts built by CI mac).

$ uname -m -s
Darwin arm64

$ npm install grpc-tools
added 57 packages, and audited 58 packages in 2s

4 packages are looking for funding
  run `npm fund` for details

$ ./node_modules/grpc-tools/bin/protoc example.proto --plugin=protoc-gen-grpc=./node_modules/grpc-tools/bin/grpc_node_plugin --grpc_out=. 
$ ls
example.proto  example_grpc_pb.js  node_modules  package-lock.json  package.json

As long as I confirmed, they work well.

Copy link
Member

@murgatroid99 murgatroid99 left a comment

Choose a reason for hiding this comment

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

That's good enough for me. Thank you for your contribution.

@murgatroid99 murgatroid99 merged commit 4257e33 into grpc:master Oct 5, 2022
@murgatroid99
Copy link
Member

This has been published in grpc-tools version 1.11.3.

@yurks
Copy link

yurks commented Mar 1, 2023

something weird with that "new" arm64 binaries:

#2378

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.

3 participants