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

Add support for Apple M1 chips. #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brunobely
Copy link

Closes #9.

Comment on lines 18 to 19
const arch =
process.arch === "x64" || process.arch === "arm64" ? "x86_64" : "x86_32";
Copy link
Owner

Choose a reason for hiding this comment

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

I think the M1 chip uses the aarch_64 and not x86_64 (https://en.wikipedia.org/wiki/AArch64). I think we need to translate it to use protoc-${protoVersion}-osx-aarch_64.zip instead (needs to be added to the list of releases).

So the logic should be something like:

  • If arch is equal to x64 use x86_64
  • If arch is equal to arm64 use aarch_64
  • Otherwise use x86_32

Copy link
Author

@brunobely brunobely Nov 18, 2022

Choose a reason for hiding this comment

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

That sounds correct. When I saw the osx-aarch_64 release in v3.20.1 and v3.20.2 but absent in v3.20.3 I assumed they consolidated the macOS release names, but it looks like it was a different issue.

Those binaries were just copies of the x86_64 artifacts, and aarch_64 binaries are only available on or after v21.x: see this comment

I followed this commit to upgrade to v3.21.9 (looks like they're referring to it as just 21.9 now).

Looks like the JS implementation is now under https://github.com/protocolbuffers/protobuf-javascript, so the files in https://github.com/protocolbuffers/protobuf/tree/v3.20.3/js mentioned in this comment no longer exist under v21.9. Is that an issue?

As an aside, is there a reason for both Windows links pointing to the win32 release?

Copy link
Owner

Choose a reason for hiding this comment

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

It lookes like https://github.com/protocolbuffers/protobuf-javascript is needed as I get the following error:

'protoc-gen-js' is not recognized as an internal or external command,
operable program or batch file.
--js_out: protoc-gen-js: Plugin failed with status code 1.

I then downloaded protoc-gen-js.exe from https://github.com/protocolbuffers/protobuf-javascript/releases/tag/v3.21.2 put it in the same bin folder as protoc.exe. Made sure that the bin folder was added to the path. However, that just creates another error:

--js_out: protoc-gen-js: Plugin failed with status code 3221225781.

I'm not exactly sure what causes that issue. Perhaps it's because it needs a specific version or I'm missing some libraries. But maybe you can try and see whether you can get it to work.

I modified the protoc function in index.js to automatically add the folder to the PATH environment:

exports.protoc = function(args, options, callback) {
  if (typeof options === "function" && !callback) {
    callback = options;
    options = {};
  }

  try {
    cp.execFile(protoc, args, {
      env: {
        ...process.env,
        PATH: process.env.PATH + ";" + path.dirname(protoc)
      },
      ...options
    }, callback);
  } catch (err) {
    callback(err);
  }
};

If you're running something other than Windows you probably need to change the separator ; to : instead.

@akv-mshin
Copy link

akv-mshin commented Mar 18, 2023

Hi guys, any news on that?

Tried to see if the code in PR works for me:

So when I try to install current package I see this:

~/c/protoc-test
▶ yarn add -D protoc
yarn add v1.22.19
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
error /path/protoc-test/node_modules/protoc: Command failed.
Exit code: 1
Command: node scripts/postinstall.js
Arguments:
Directory: /path/protoc-test/node_modules/protoc
Output:
/path/protoc-test/node_modules/protoc/scripts/postinstall.js:24
    throw new Error(`Unsupported platform: ${release}. Was not able to find a proper protoc version.`);
          ^

Error: Unsupported platform: darwin_x86_32. Was not able to find a proper protoc version.
    at /path/protoc-test/node_modules/protoc/scripts/postinstall.js:24:11
    at Object.<anonymous> (/path/protoc-test/node_modules/protoc/scripts/postinstall.js:58:3)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

which is expected.

Now I use yarn link to test with local version:

~/c/protoc-test                                                                                                                           ⍉
▶ yarn link "protoc"
yarn link v1.22.19
success Using linked package for "protoc".
✨  Done in 0.02s.

I get

~/c/protoc-test
▶ yarn add -D protoc
yarn add v1.22.19
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
success Saved 46 new dependencies.
info Direct dependencies
└─ protoc@1.1.3
info All dependencies
├─ balanced-match@1.0.2
├─ big-integer@1.6.51
├─ binary@0.3.0
├─ bluebird@3.4.7
├─ brace-expansion@1.1.11
├─ buffer-indexof-polyfill@1.0.2
├─ buffers@0.1.1
├─ chainsaw@0.1.0
├─ clone-buffer@1.0.0
├─ clone-stats@1.0.0
├─ clone@2.1.2
├─ cloneable-readable@1.1.3
├─ concat-map@0.0.1
├─ core-util-is@1.0.3
├─ data-uri-to-buffer@4.0.1
├─ duplexer2@0.1.4
├─ fetch-blob@3.2.0
├─ formdata-polyfill@4.0.10
├─ fs.realpath@1.0.0
├─ fstream@1.0.12
├─ graceful-fs@4.2.11
├─ inflight@1.0.6
├─ inherits@2.0.4
├─ isarray@1.0.0
├─ listenercount@1.0.1
├─ minimatch@3.1.2
├─ minimist@1.2.8
├─ mkdirp@0.5.6
├─ node-domexception@1.0.0
├─ node-fetch@3.3.1
├─ path-is-absolute@1.0.1
├─ process-nextick-args@2.0.1
├─ protoc@1.1.3
├─ readable-stream@2.3.8
├─ remove-trailing-separator@1.1.0
├─ replace-ext@1.0.1
├─ rimraf@3.0.2
├─ safe-buffer@5.1.2
├─ setimmediate@1.0.5
├─ string_decoder@1.1.1
├─ traverse@0.3.9
├─ unzipper@0.10.11
├─ util-deprecate@1.0.2
├─ uuid@9.0.0
├─ vinyl@2.2.1
└─ web-streams-polyfill@3.2.1
✨  Done in 0.99s.

Which is a good sign.

However, when I try to run

yarn protoc

it says that protoc is not found

~/c/protoc-test                                                                                                                           ⍉
▶ yarn protoc
yarn run v1.22.19
error Command "protoc" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Do you guys have any idea?

edit: may be we could publish pre-release based on that PR to doublecheck?

It's currently using Protocol Buffers `v3.20.3`.
It's currently using Protocol Buffers `v21.9`.

Choose a reason for hiding this comment

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

This won't work. See #7 (comment), why.

@kittaakos
Copy link

Hello, any updates on this PR? I would be happy to open a follow-up if contributions are accepted.

From here:

I think the M1 chip uses the aarch_64 and not x86_64

This is what I see on M1:

Error:

Output:
/path/to/node_modules/protoc/scripts/postinstall.js:24
    throw new Error(`Unsupported platform: ${release}. Was not able to find a proper protoc version.`);

arch and platform on M1:

node -e "console.log(process.arch, process.platform)"
arm64 darwin

giacomocusinato added a commit to arduino/arduino-ide that referenced this pull request Jun 17, 2024
The npm package previously used (`protoc`) is still lacking apple arm32 support, see YePpHa/node-protoc#10
giacomocusinato added a commit to arduino/arduino-ide that referenced this pull request Jun 27, 2024
The npm package previously used (`protoc`) is still lacking apple arm32 support, see YePpHa/node-protoc#10
giacomocusinato added a commit to arduino/arduino-ide that referenced this pull request Jun 27, 2024
The npm package previously used (`protoc`) is still lacking apple arm32 support, see YePpHa/node-protoc#10
giacomocusinato added a commit to arduino/arduino-ide that referenced this pull request Jul 8, 2024
The npm package previously used (`protoc`) is still lacking apple arm32 support, see YePpHa/node-protoc#10
giacomocusinato added a commit to arduino/arduino-ide that referenced this pull request Sep 6, 2024
* fix: use `@pingghost/protoc` to compile proto files

The npm package previously used (`protoc`) is still lacking apple arm32 support, see YePpHa/node-protoc#10

* feat: use Arduino CLI 1.0.4

* fix: allow use of node16 in github actions

* chore: update `arduino-language-server` version for cli-1.0.0

* fix: deprecated platform order test

Arduino deprecated platforms should have more priority then other deprecated ones
giacomocusinato added a commit to arduino/arduino-ide that referenced this pull request Sep 9, 2024
The npm package previously used (`protoc`) is still lacking apple arm32 support, see YePpHa/node-protoc#10
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.

Need support m1 macbook pro
5 participants