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

can no longer use include_prefix = "" in cc_library with Bazel 6.0.0 #17039

Closed
carpenterjc opened this issue Dec 16, 2022 · 8 comments
Closed
Labels

Comments

@carpenterjc
Copy link

Description of the bug:

We use include_prefix in our C++ assets for legacy component laytout. This has stopped working in bazel 6.0.0, although the virtual includes directory is produced.

If you use include_prefix = "x" and #include "x/blah.h" it works.
If you use includes = ["."] and #include "blah.h" it works.
If you use include_prefix = "" and #include "blah.h" it fails.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

diff --git a/.bazelversion b/.bazelversion
new file mode 100644
index 0000000..73fcd45
--- /dev/null
+++ b/.bazelversion
@@ -0,0 +1 @@
+6.0.0rc5
\ No newline at end of file
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..ff015f9
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,5 @@
+cc_test(
+    name="test",
+    srcs = ["test.cpp"],
+    deps = ["//blah"],
+)
\ No newline at end of file
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..e69de29
diff --git a/blah/BUILD b/blah/BUILD
new file mode 100644
index 0000000..08a2dd6
--- /dev/null
+++ b/blah/BUILD
@@ -0,0 +1,6 @@
+cc_library(
+    name = "blah",
+    hdrs = ["blah.h"],
+    include_prefix = "",
+    visibility = ["//:__pkg__"],
+)
diff --git a/blah/blah.h b/blah/blah.h
new file mode 100644
index 0000000..e69de29
diff --git a/test.cpp b/test.cpp
new file mode 100644
index 0000000..6dc850a
--- /dev/null
+++ b/test.cpp
@@ -0,0 +1,5 @@
+#include "blah.h"
+
+int main(){
+    return 0;
+}
\ No newline at end of file

Which operating system are you running Bazel on?

windows

What is the output of bazel info release?

release 6.0.0rc5

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

Bazel 6.0.0 output fails...

ERROR: C:/dev/test/BUILD:1:8: Compiling test.cpp failed: (Exit 2): cl.exe failed: error executing command (from target //:test)
  cd /d C:/dev/_bazel/l2habeez/execroot/__main__
  SET INCLUDE=C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\ATLMFC\include;C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt
    SET PATH=C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\bazeltools\vs16\Common7\IDE\VC\VCPackages;C:\bazeltools\vs16\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\bazeltools\vs16\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\bazeltools\vs16\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\bazeltools\vs16\Common7\Tools\devinit;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\bazeltools\vs16\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\bazeltools\vs16\Common7\IDE\;C:\bazeltools\vs16\Common7\Tools\;;C:\Windows\system32
    SET PWD=/proc/self/cwd
    SET RUNFILES_MANIFEST_ONLY=1
    SET TEMP=C:\Users\JAMESC~1\AppData\Local\Temp
    SET TMP=C:\Users\JAMESC~1\AppData\Local\Temp
  C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-fastbuild/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-fastbuild/bin/external/bazel_tools /DBAZEL_CURRENT_REPOSITORY="" /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Fobazel-out/x64_windows-fastbuild/bin/_objs/test/test.obj /c test.cpp
# Configuration: b67f5ac3d5b94ed15e96cb37e833e7120042529b3e382867f55890fe82af9163
# Execution platform: @local_config_platform//:host
test.cpp(1): fatal error C1083: Cannot open include file: 'blah.h': No such file or directory
INFO: Elapsed time: 1.060s, Critical Path: 0.14s
INFO: 2 processes: 2 internal.                                                                                                                                                                                                               
FAILED: Build did NOT complete successfully

Working with Bazel 5.3.2

PS C:\dev\test> bazel build ... -s                
Starting local Bazel server and connecting to it...
INFO: Invocation ID: 1a9c33cb-a9f5-4155-8b4b-d7a3931a6f13
INFO: Analyzed 2 targets (48 packages loaded, 681 targets configured).
INFO: Found 2 targets...
SUBCOMMAND: # //:test [action 'Compiling test.cpp', configuration: 8fcc02caf7268a43edcd2a5a3e8e4edfa3c614a84823ca1599fcd30251ebce9f, execution platform: @local_config_platform//:host]
cd /d C:/dev/_bazel/l2habeez/execroot/__main__
  SET INCLUDE=C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\ATLMFC\include;C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt
    SET PATH=C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\bazeltools\vs16\Common7\IDE\VC\VCPackages;C:\bazeltools\vs16\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\bazeltools\vs16\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\bazeltools\vs16\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\bazeltools\vs16\Common7\Tools\devinit;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\bazeltools\vs16\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\bazeltools\vs16\Common7\IDE\;C:\bazeltools\vs16\Common7\Tools\;;C:\Windows\system32
    SET PWD=/proc/self/cwd
    SET RUNFILES_MANIFEST_ONLY=1
    SET TEMP=C:\Users\JAMESC~1\AppData\Local\Temp
    SET TMP=C:\Users\JAMESC~1\AppData\Local\Temp
  C:\bazeltools\vs16\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-fastbuild/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-fastbuild/bin/external/bazel_tools /Ibazel-out/x64_windows-fastbuild/bin/blah/_virtual_includes/blah /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Fobazel-out/x64_windows-fastbuild/bin/_objs/test/test.obj /c test.cpp
# Configuration: 8fcc02caf7268a43edcd2a5a3e8e4edfa3c614a84823ca1599fcd30251ebce9f
# Execution platform: @local_config_platform//:host
INFO: Elapsed time: 15.772s, Critical Path: 0.11s
INFO: 2 processes: 1 disk cache hit, 1 internal.
INFO: Build completed successfully, 2 total actions

Virtual includes are created, but don't seem to work.

PS C:\dev\test> dir .\bazel-bin\ -r | select -exp fullname
C:\dev\test\bazel-bin\blah
C:\dev\test\bazel-bin\test.exe.runfiles
C:\dev\test\bazel-bin\_objs
C:\dev\test\bazel-bin\test.exe
C:\dev\test\bazel-bin\test.exe-2.params
C:\dev\test\bazel-bin\test.exe.runfiles_manifest
C:\dev\test\bazel-bin\test.pdb
C:\dev\test\bazel-bin\blah\_virtual_includes
C:\dev\test\bazel-bin\blah\_virtual_includes\blah
C:\dev\test\bazel-bin\blah\_virtual_includes\blah\blah.h
C:\dev\test\bazel-bin\test.exe.runfiles\MANIFEST
C:\dev\test\bazel-bin\_objs\test
@fmeum
Copy link
Collaborator

fmeum commented Dec 16, 2022

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Dec 16, 2022
@fmeum
Copy link
Collaborator

fmeum commented Dec 16, 2022

cc_common.compile interprets include_prefix = "" as if it wasn't set (ref), whereas Java CcLibrary checks whether the attribute has been set explicitly (ref), which Starlark can't emulate without wrapper macros distinguishing between None and "" (#14434). strip_include_prefix is affected by this logic as well and this is not limited to Windows.

@fmeum
Copy link
Collaborator

fmeum commented Dec 16, 2022

@carpenterjc Could you check whether making the following programmatic change is sufficient to resolve the build failure in your real-world repo?

buildozer 'substitute include_prefix ^$ .' //...:%cc_library
buildozer 'substitute strip_include_prefix ^$ .' //...:%cc_library

If that's the extent of the migration required, having it be a minor incompatible change may be better than carrying the subtle "" vs. None issue forward.

@carpenterjc
Copy link
Author

Yes, so if have include_prefix = "." then it also works.

@carpenterjc
Copy link
Author

Will you get the edge case where the _virtual_includes directory is created with include_prefix = "" but that is not actually usable.

@fmeum
Copy link
Collaborator

fmeum commented Dec 16, 2022

@oquenchil

@meteorcloudy
Copy link
Member

/cc @buildbreaker2021 , can you please take a look? My current assessment is that this is probably a minor incompatible change with workarounds, so probably shouldn't block the 6.0 release. If there is something we should fix, we can cherry pick it into 6.1. WDYT?

@buildbreaker2021
Copy link
Contributor

I agree with Fabian here and I do not see the reason to add more tech debt to fix this. Like adding a hack in cc_library to change "" to ".", for example. The buildozer workaround described here is simple enough.
Also "." is more explicit than "" IMO.

@Wyverald Wyverald removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Dec 19, 2022
github-actions bot pushed a commit to chachako/android-studio that referenced this issue Jan 31, 2023
And fix incompatible changes:

* cc_binary no longer appends ".exe" on Windows
* labels for aspects start with "@//" indicating the default repository
* strip_include_prefix usage of "" migrated to "."
  - bazelbuild/bazel#17039
* removes --bes_header from bazelrc
  - Bazel uses an updated google auth library that uses the quota
    project set in the application default credentials

Bug: 266863277
Test: n/a
Change-Id: I6b1b8495a319652cfa12dc4c84da19a7b6ff1346

Former-commit-id: 610b1d46e31165a7db4facb001946a36fe795e4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants