Skip to content

Commit d79f75b

Browse files
committed
build: switch sass compilations to Dart Sass
This will be much faster, doesn't rely on workers that execute outside of Bazel sandbox and can cause subtle confusion (see recent Sass changes).
1 parent 13a3f82 commit d79f75b

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

WORKSPACE

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ http_archive(
1212
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.4/rules_nodejs-5.8.4.tar.gz"],
1313
)
1414

15-
# Add sass rules
16-
http_archive(
17-
name = "io_bazel_rules_sass",
18-
sha256 = "1c89680ca9cbbba33cb9cd462eb328e5782e14c0aa1286b794c71b5333385407",
19-
strip_prefix = "rules_sass-1.68.0",
20-
urls = [
21-
"https://github.com/bazelbuild/rules_sass/archive/1.68.0.zip",
22-
],
23-
)
24-
2515
# Add skylib which contains common Bazel utilities. Note that `rules_nodejs` would also
2616
# bring in the skylib repository but with an older version that does not support shorthands
2717
# for declaring Bazel build setting flags.
@@ -109,11 +99,6 @@ yarn_install(
10999
yarn_lock = "//tools/bazel/legacy-rnjs:yarn.lock",
110100
)
111101

112-
# Setup the Sass rule repositories.
113-
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
114-
115-
sass_repositories()
116-
117102
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
118103

119104
npm_translate_lock(
@@ -295,3 +280,13 @@ rules_browsers_setup_1()
295280
load("@rules_browsers//setup:step_2.bzl", "rules_browsers_setup_2")
296281

297282
rules_browsers_setup_2()
283+
284+
git_repository(
285+
name = "rules_sass",
286+
commit = "a32f75ce6fa0c5370bd3f29a5306478c681ad124",
287+
remote = "https://github.com/devversion/rules_sass.git",
288+
)
289+
290+
load("@rules_sass//src/toolchain:repositories.bzl", "setup_rules_sass")
291+
292+
setup_rules_sass()

src/material/core/theming/tests/test-theming-bundle.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Imports the theming bundle. Needs to be an absolute bin-dir import path as on Windows,
22
// runfiles are not symlinked, so the Sass compilation happens in the workspace directory
33
// with the include paths being set to the `bazel-bin` directory.
4-
@use 'src/material' as mat;
4+
@use '../../../index' as mat;
55

66
// Disable theme style duplication warnings. This test intentionally generates
77
// the same themes multiple times.

tools/defaults.bzl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
load("@rules_pkg//:pkg.bzl", "pkg_tar")
44
load("@build_bazel_rules_nodejs//:index.bzl", _pkg_npm = "pkg_npm")
5-
load("@io_bazel_rules_sass//:defs.bzl", _sass_binary = "sass_binary", _sass_library = "sass_library")
5+
load("@rules_sass//src:index.bzl", _sass_binary = "sass_binary", _sass_library = "sass_library")
66
load("@npm//@angular/bazel:index.bzl", _ng_package = "ng_package")
77
load("//:packages.bzl", "NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS", "NPM_PACKAGE_SUBSTITUTIONS")
88
load("//:pkg-externals.bzl", "PKG_EXTERNALS")
@@ -25,8 +25,12 @@ karma_web_test_suite = _karma_web_test_suite
2525
def sass_binary(sourcemap = False, include_paths = [], **kwargs):
2626
_sass_binary(
2727
sourcemap = sourcemap,
28-
include_paths = include_paths + ["external/npm/node_modules"],
29-
compiler = "//tools/sass:compiler",
28+
include_paths = include_paths,
29+
module_mappings = {
30+
"@angular/cdk": "/".join([".."] * (native.package_name().count("/") + 1)) + "/src/cdk",
31+
"@angular/material": "/".join([".."] * (native.package_name().count("/") + 1)) + "/src/material",
32+
"@angular/material-experimental": "/".join([".."] * (native.package_name().count("/") + 1)) + "/src/material-experimental",
33+
},
3034
**kwargs
3135
)
3236

tools/extract-tokens/index.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ def _extract_tokens(ctx):
1616
expected_outputs = [output_file_name]
1717

1818
# Pass the necessary information like the package name and files to the script.
19-
args.add(ctx.label.package, output_file_name)
19+
args.add(ctx.label.package)
20+
args.add(output_file_name.short_path)
2021

2122
for input_file in input_files:
22-
args.add(input_file.path)
23+
args.add(input_file.short_path)
2324

2425
# Run the token extraction executable. Note that we specify the outputs because Bazel
2526
# can throw an error if the script didn't generate the required outputs.
2627
ctx.actions.run(
2728
inputs = input_files,
2829
env = {
29-
# Not needed as we operate with source files; not inside `bazel-bin`.
30-
"JS_BINARY__NO_CD_BINDIR": "1",
30+
"BAZEL_BINDIR": ctx.bin_dir.path,
3131
},
3232
executable = ctx.executable._extract_tokens,
3333
outputs = expected_outputs,
3434
arguments = [args],
35-
progress_message = "ExtractTokens",
35+
progress_message = "Extracting theme tokens %s:%s" % (ctx.label.package, ctx.attr.name),
3636
)
3737

3838
return DefaultInfo(files = depset(expected_outputs))

0 commit comments

Comments
 (0)