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

fix(typescript): fix for cross platform ts_devserver issue #1409 #1413

Conversation

gregmagolan
Copy link
Collaborator

Fixes #1409

This change allows a ts_devserver target to be build with cross platform RBE (host platform is osx or Windows & execution platform is linux) and still run on the host platform.

With cross-platform RBE for OSX & Windows ctx.executable.devserver will be linux as --cpu and --host_cpu must be overridden to k8. However, we still want to be able to run the devserver on the host machine so we need to include the host devserver binary, which is ctx.executable.devserver_host, in the runfiles. For non-RBE and for RBE with a linux host, ctx.executable.devserver & ctx.executable.devserver_host will be the same binary.

BREAKING CHANGE:

@bazel/typescript version needs to be in sync with @build_bazel_rule_nodejs for this fix so this is a breaking change between the two release artifacts. Next release should be a bump on the minor version (breaking change for 0.x.x in semver).

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

@bazel/typescript version needs to be in sync with @build_bazel_rule_nodejs for this fix so this is a breaking change between the two release artifacts.

Other information

…rib#1409

This change allows a ts_devserver target to be build with cross platform RBE (host platform is osx or Windows & execution platform is linux) and still run on the host platform.

With cross-platform RBE for OSX & Windows ctx.executable.devserver will be linux as --cpu and --host_cpu must be overridden to k8. However, we still want to be able to run the devserver on the host machine so we need to include the host devserver binary, which is ctx.executable.devserver_host, in the runfiles. For non-RBE and for RBE with a linux host, ctx.executable.devserver & ctx.executable.devserver_host will be the same binary.
Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

Can't we just tag the action that generates the script with "local" so it doesn't try to run it on RBE? Seems unhelpful to have a remote machine interpolate some strings, it's just I/O bound on the upload/download

Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

feels like the core issue is that we are doing something complex here where we should do something simple instead. All of this is just to serve a bit of bundled JS to angular protractor tests. Surely we could just switch them to http_server for nearly all these use cases?

"devserver_host": attr.label(
doc = """Go based devserver executable for the host platform.
Defaults to precompiled go binary in @npm_bazel_typescript setup by @bazel/typescript npm package""",
default = Label("//devserver:devserver_%s" % host_platform),
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there some other way we could get this info so we don't need to create the new index.bzl file and make the rollout complicated? @meteorcloudy maybe you have some idea - I know there's a starlark trick to know if we are on Windows or not

devserver_runfiles = [
ctx.executable.devserver,
ctx.executable.devserver_host,
Copy link
Collaborator

Choose a reason for hiding this comment

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

feels really gross to upload both binaries to RBE just because it can't select the right one. This is a limitation of cross-platform RBE being broken? Still feels like a hacky workaround

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess you mean this one: https://github.com/bazelbuild/rules_nodejs/blob/dcdc98b093edf2a3ccd6962d8b4f15aa28ba6fa8/internal/common/windows_utils.bzl#L63

It's basically a hack to make the code simpler, but it should work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm we also need a way to distinguish mac from linux, do you know of any trick to do that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, maybe you can consider this:

Adding the following to .bazelrc

--enable_platform_specific_config
build:windows --action_env=NODE_PLATFORM=windows
build:macos --action_env=NODE_PLATFORM=macos
build:linux --action_env=NODE_PLATFORM=linux

Then you can check the value of ctx.configuration.default_shell_env['NODE_PLATFORM']

Doc for --enable_platform_specific_config

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's clever but we can't control users' .bazelrc files so this will get us in trouble

@@ -42,8 +42,45 @@ else
fi
# --- end runfiles.bash initialization ---

# Check environment for which node path to use
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we could key this off the path to node instead?

This comment was marked as spam.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, sorry. I commented at the wrong place.

Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

Not really excited about the hacks here but it seems we have to get some fixes in RBE itself to do it correctly, and we think Angular team treats this as a P1 so we can merge and come back to it maybe

@gregmagolan gregmagolan merged commit 172caff into bazel-contrib:master Dec 4, 2019
@gregmagolan
Copy link
Collaborator Author

@alexeagle Created Revisit cross-platform RBE mechanics #1415. .Will add more details about how it is currently working and how it should work.

gregmagolan added a commit to gregmagolan/angular that referenced this pull request Dec 5, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for angular#34112
2) fix(typescript): fix for cross platform ts_devserver issue angular#1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific angular#1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Dec 5, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for #34112
2) fix(typescript): fix for cross platform ts_devserver issue #1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific #1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.

PR Close #34243
AndrewKushnir pushed a commit to angular/angular that referenced this pull request Dec 5, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for #34112
2) fix(typescript): fix for cross platform ts_devserver issue #1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific #1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.

PR Close #34243
josephperrott pushed a commit to josephperrott/angular that referenced this pull request Dec 11, 2019
This release brings two bug fixes we're waiting on:
1) fix(builtin): additional_root_paths in pkg_web should also include paths in genfiles and bin dirs (bazel-contrib/rules_nodejs#1402), which is a pre-req for angular#34112
2) fix(typescript): fix for cross platform ts_devserver issue angular#1409 (bazel-contrib/rules_nodejs#1413) which resolves ts_devserver launcher template is platform specific angular#1409 (bazel-contrib/rules_nodejs#1409) --- this fixes an OSX developer workflow with --config=remote

This does not upgrade integration/bazel or integation/schematics. That will be done in another PR.

PR Close angular#34243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ts_devserver launcher template is platform specific
4 participants