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

How to run on windows? #51

Closed
rahulv4667 opened this issue Jun 1, 2021 · 8 comments · Fixed by #52 or #87
Closed

How to run on windows? #51

rahulv4667 opened this issue Jun 1, 2021 · 8 comments · Fixed by #52 or #87
Labels
question Further information is requested

Comments

@rahulv4667
Copy link
Contributor

rahulv4667 commented Jun 1, 2021

Hello, I am having trouble trying to compile on windows10.

.\protoc.exe -I=proto_src --ts_out=dist message.proto throws 'protoc-gen-ts' is not recognized as an internal or external command, operable program or batch file. --ts_out: protoc-gen-ts: Plugin failed with status code 1. error.

And when I use .\protoc.exe --plugin=protoc-gen-ts=<absolute_path_to_project>/node_modules/protoc-gen-ts/bin/protoc-gen-ts -I=proto_src --ts_out=dist message.proto, it throws --ts_out: protoc-gen-ts: %1 is not a valid Win32 application. And it only takes absolute path. Doesn't work with relative path.

I have observed that in other typescript generators, there was cmd script given in bin folder of package. But in my npm download, there is only javascript code without any extension to the file but with first line saying '#!/usr/bin/env node'. This made me think if this is made only for shells in unix systems and not windows.

I neither have bazel on my system and nor am I familiar with it. So, I would like to know how to generate files on windows(if it is possible), preferably without bazel.

@thesayyn
Copy link
Owner

thesayyn commented Jun 1, 2021

Hey @rahulv4667

Thank you for this great finding. Unfortunately, I do not have a windows machine that I can work with to fix this but I can definitely put you in the right spot if you want to send a PR for this.

Since I do the development on Unix-like machines I never had this issue but I would expect it to work since npm creates a wrapper on windows.

Maybe the problem that you are having is because of the direct invocation of the binary which is designed for unix systems.

The only solution that I see is having an executable file called protoc-gen-ts.cmd which invokes node with ./src/index.js as an argument.

But even before that, I feel like you can implement a workaround by running a set of commands and create an appropriate executable file in place then send it as a PR.

1 - Add .cmd as a suffix to path (it must be already there alongside normal bin that is designed for unix)

If there is no such file then

2- Create it manually

  • find global node_modules path by running npm root -g / on my machine (a mac) the output is /opt/homebrew/lib/node_modules
  • open up this folder in file explorer and locate the folder called protoc-gen-ts
  • navigate to the bin folder and create a file called protoc-gen-ts.cmd
  • put node ../src/index

and try to invoke the .cmd command

@rahulv4667
Copy link
Contributor Author

Sure. I was able to get it running by calling the index file. But, I had to hard code the file location. To set the right location dynamically, I think it needs to check the local and global installation folders. Will try to write the script by tomorrow and make a pull request.

But I didn't understand step 1(add .cmd as a suffix to path) in your message. Let me see if I understood what I need to do.

  • Write a protoc-gen-ts.cmd script which gets the installation location(checks for local first. if not present, takes global) and runs node <node_modules_path>/protoc-gen-ts/src/index
  • Not sure about this, but I think bin/BUILD.bazel needs to be changed according to OS? I am assuming the root BUILD.bazel depends on what is generated by the bin/BUILD. bazel. As I told, I am not famiiar with bazel, so would need some help in this part.

Please let me know if I am missing anything else.

@thesayyn
Copy link
Owner

thesayyn commented Jun 1, 2021

But I didn't understand step 1(add .cmd as a suffix to path) in your message. Let me see if I understood what I need to do.

I mean there must be a binary that is specifically generated for "windows" with possibly ".cmd" (".ps" in some cases) extension.

so in order to use the correct one when invoking protoc with "--plugin" option present, you need to invoke tell it to use the one with correct extension.

so in your case it was <absolute_path_to_project>/node_modules/protoc-gen-ts/bin/protoc-gen-ts which should have been <absolute_path_to_project>/node_modules/protoc-gen-ts/bin/protoc-gen-ts.cmd in the first place.

@thesayyn
Copy link
Owner

thesayyn commented Jun 1, 2021

Alternatively, installing the plugin globally rather than locally might help.

As far as I am concerned, you ran into this problem because protoc-gen-ts is neither recognized because its location is not in the PATH variable.

@thesayyn thesayyn added the question Further information is requested label Jun 1, 2021
@rahulv4667
Copy link
Contributor Author

I mean there must be a binary that is specifically generated for "windows" with possibly ".cmd" (".ps" in some cases) extension.

Oh. I understood that.

Alternatively, installing the plugin globally rather than locally might help.

As far as I am concerned, you ran into this problem because protoc-gen-ts is neither recognized because its location is not in the PATH variable.

No, installing globally didn't solve the problem. The problem wasn't with path. It's, as you said, not having a batch script. I have created the batch script. You can look at it here.

I will install bazel and test if it is building properly after making necessary changes to build files. Then, make the pull request. Or if you prefer just the batch script, I could make it now.

@rahulv4667
Copy link
Contributor Author

I am facing this error when running npm test. Unable to figure out the cause.

> [email protected] test D:\open_source\protoc-gen-ts\protoc-gen-ts
> bazel build //test:codegen && node ./scripts/sync_generated_protos.js test && bazel test //test/... --test_output=errors

INFO: Repository npm instantiated at:
  D:/open_source/protoc-gen-ts/protoc-gen-ts/WORKSPACE:21:13: in <toplevel>
  C:/users/4667r/_bazel_4667rahul/vgrfovvs/external/build_bazel_rules_nodejs/index.bzl:78:18: in yarn_install
Repository rule yarn_install defined at:
  C:/users/4667r/_bazel_4667rahul/vgrfovvs/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl:644:31: in <toplevel>
ERROR: An error occurred during the fetch of repository 'npm':
   Traceback (most recent call last):
        File "C:/users/4667r/_bazel_4667rahul/vgrfovvs/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 610, column 15, in _yarn_install_impl
                _copy_file(repository_ctx, repository_ctx.attr.package_json)
        File "C:/users/4667r/_bazel_4667rahul/vgrfovvs/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 343, column 17, in _copy_file
                fail("mkdir -p %s failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (dirname, result.stdout, result.stderr))
Error in fail: mkdir -p _ failed:
STDOUT:

STDERR:
java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("mkdir" -p _): The system cannot find the file specified.      
 (error: 2)
ERROR: Error fetching repository: Traceback (most recent call last):
        File "C:/users/4667r/_bazel_4667rahul/vgrfovvs/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 610, column 15, in _yarn_install_impl
                _copy_file(repository_ctx, repository_ctx.attr.package_json)
        File "C:/users/4667r/_bazel_4667rahul/vgrfovvs/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 343, column 17, in _copy_file
                fail("mkdir -p %s failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (dirname, result.stdout, result.stderr))
Error in fail: mkdir -p _ failed:
STDOUT:

STDERR:
java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("mkdir" -p _): The system cannot find the file specified.      
 (error: 2)
ERROR: Skipping '//test:codegen': no such package '@npm//@bazel/typescript': mkdir -p _ failed:
STDOUT:

STDERR:
java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("mkdir" -p _): The system cannot find the file specified.      
 (error: 2)
WARNING: Target pattern parsing failed.
ERROR: no such package '@npm//@bazel/typescript': mkdir -p _ failed:
STDOUT:

STDERR:
java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("mkdir" -p _): The system cannot find the file specified.      
 (error: 2)
INFO: Elapsed time: 0.205s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
    currently loading: test
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `bazel build //test:codegen && node ./scripts/sync_generated_protos.js test && bazel test //test/... --test_output=errors`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\4667r\AppData\Roaming\npm-cache\_logs\2021-06-02T05_14_18_754Z-debug.log

@thesayyn
Copy link
Owner

thesayyn commented Jun 2, 2021

No, installing globally didn't solve the problem. The problem wasn't with path. It's, as you said, not having a batch script. I have created the batch script. You can look at it here.

Bazel has a lot of problems with windows still so I wouldn’t recommend that you try to build it on windows.

So if this solved your problem then we can get it merged when you could send a PR with the batch script.

I can additionally integrate Github workflows so we can make sure in the future that it works on a windows machine too.

Refer to matrix testing here:

matrix:
os: [ubuntu-latest, macos-latest]

@thesayyn
Copy link
Owner

thesayyn commented Dec 1, 2021

Hey @rahulv4667

We have landed a fix for this on 0.8.0. Let me know if it works for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
2 participants