Skip to content

Conversation

@congzhangzh
Copy link
Contributor

msbuild property need pass by /p:key=value

msbuild property need pass by /p:key=value
@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. windows Issues and PRs related to the Windows platform. labels Mar 17, 2024
@congzhangzh congzhangzh changed the title [vcbuild.bat] minor fix [vcbuild.bat] bug fix & add ccache support Mar 17, 2024
@congzhangzh
Copy link
Contributor Author

@zcbenz @liudonghua123 @targos Hi folks, can you do a code review:)

@congzhangzh
Copy link
Contributor Author

congzhangzh commented Mar 17, 2024

The Directory.Build.props still be needed, the default debug info setting does no work with cache, and no way to config ClCompile from cmdline,

Directory.Build.props

<Project>
  <ItemDefinitionGroup>
    <ClCompile>
      <DebugInformationFormat>OldStyle</DebugInformationFormat>
      <ForcedIncludeFiles />
      <ObjectFileName>$(IntDir)%(FileName).obj</ObjectFileName>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

Refs:

  1. https://github.com/ccache/ccache/wiki/MS-Visual-Studio#usage-with-visual-studio
  2. https://medium.com/@parakram.majumdar/ccache-with-msbuild-devenv-f286778e0be7
  3. Support for MSVC's /Zi ccache/ccache#1040
  4. https://github.com/mozilla/sccache
  5. https://learn.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format
  6. https://learn.microsoft.com/en-us/cpp/build/reference/fd-program-database-file-name
  7. https://learn.microsoft.com/en-us/cpp/build/reference/cl-environment-variables
  8. https://learn.microsoft.com/en-us/cpp/build/reference/cl-command-files
  9. https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_DEBUG_INFORMATION_FORMAT.html

@anonrig
Copy link
Member

anonrig commented Mar 17, 2024

cc @nodejs/platform-windows

@StefanStojanovic
Copy link
Contributor

Hello @congzhangzh. Changes from this PR interest me. I've tried running it locally and got the compilation to pass, but regarding ccache, all calls are Uncacheable calls.

Can you share the setup you're using eg. ccache configuration and other prerequisites? Thanks in advance.

@congzhangzh
Copy link
Contributor Author

congzhangzh commented Mar 22, 2024

Hello @congzhangzh. Changes from this PR interest me. I've tried running it locally and got the compilation to pass, but regarding ccache, all calls are Uncacheable calls.

Can you share the setup you're using eg. ccache configuration and other prerequisites? Thanks in advance.

@StefanStojanovic Hi Stefan, can you try to do test in a small project first, follow,

copy ccache.exe as cl.exe, I assume you install cache to c:\ccache

https://github.com/ccache/ccache/wiki/MS-Visual-Studio#alternative-1-masquerade-as-the-compiler

create a Directory.Build.props in you project dir or upper dir

https://github.com/ccache/ccache/wiki/MS-Visual-Studio#usage-with-visual-studio

or if it still not work

Tips: Microsoft's document confused me, they say you can not use Directory.Build.props to override some C++ settings like ClCompile part, but I works for me, for 100% work, I split it into different files to be sure it always works!
##Directory.Build.props

<Project>
  <PropertyGroup>
     <CLToolPath>C:\ccache\</CLToolPath>
     <ForceImportAfterCppProps>props_4_ccache.props"</ForceImportAfterCppProps>
  </PropertyGroup>
  <!-- The following will set the needed properties described in Tips above. -->
  <!-- Creation of a precompiled header will have to be disabled separately. -->
  <PropertyGroup>
    <UseMultiToolTask>true</UseMultiToolTask>            
    <TrackFileAccess>false</TrackFileAccess>
  </PropertyGroup>
</Project>

props_4_ccache.props

<Project>
  <!-- The following will set the needed properties described in Tips above. -->
  <!-- Creation of a precompiled header will have to be disabled separately. -->
  <ItemDefinitionGroup>
    <ClCompile>
      <DebugInformationFormat>OldStyle</DebugInformationFormat>
      <ForcedIncludeFiles />
      <ObjectFileName>$(IntDir)%(FileName).obj</ObjectFileName>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

BTW, I do many ccache debugging these days, feedback is very welcome, the latest document in ccache is updated by me, some may be misleading if I understand wrong!

@congzhangzh
Copy link
Contributor Author

BTW, I am 100% sure ccache works for me on windows

@congzhangzh congzhangzh closed this by deleting the head repository Mar 22, 2024
@StefanStojanovic
Copy link
Contributor

@congzhangzh I installed ccache with Chocolatey, so for me it is in C:\ProgramData\chocolatey\bin\ccache.exe (it can be found deeper in C:\ProgramData\chocolatey\lib\ccache\tools\ccache-4.9.1-windows-x86_64 too), so I copied ccache.exe and renamed it to cl.exe in there.

Anyway, I tried what you suggested (split props into 2 files) but still nothing caches. The code compiles but no cache hits. This is the log I'm getting from ccache. The command I ran was simple msbuild ccache_test.sln. From log you'll see my ccache configuration, so maybe that's where the issue is.

[2024-03-22T16:44:34.271600 31056] === CCACHE 4.9.1 STARTED =========================================
[2024-03-22T16:44:34.271683 31056] Configuration file: E:\work\ccache\dir\ccache.conf
[2024-03-22T16:44:34.271690 31056] System configuration file: C:\ProgramData\ccache\ccache.conf
[2024-03-22T16:44:34.271690 31056] Config: (default) absolute_paths_in_stderr = false
[2024-03-22T16:44:34.271690 31056] Config: (default) base_dir = 
[2024-03-22T16:44:34.271690 31056] Config: (environment) cache_dir = E:\work\ccache\dir
[2024-03-22T16:44:34.271690 31056] Config: (default) compiler = 
[2024-03-22T16:44:34.271690 31056] Config: (default) compiler_check = mtime
[2024-03-22T16:44:34.271690 31056] Config: (default) compiler_type = auto
[2024-03-22T16:44:34.271690 31056] Config: (default) compression = true
[2024-03-22T16:44:34.271690 31056] Config: (default) compression_level = 0
[2024-03-22T16:44:34.271690 31056] Config: (default) cpp_extension = 
[2024-03-22T16:44:34.271690 31056] Config: (default) debug = false
[2024-03-22T16:44:34.271690 31056] Config: (default) debug_dir = 
[2024-03-22T16:44:34.271690 31056] Config: (default) debug_level = 2
[2024-03-22T16:44:34.271690 31056] Config: (default) depend_mode = false
[2024-03-22T16:44:34.271690 31056] Config: (default) direct_mode = true
[2024-03-22T16:44:34.271690 31056] Config: (default) disable = false
[2024-03-22T16:44:34.271690 31056] Config: (default) extra_files_to_hash = 
[2024-03-22T16:44:34.271690 31056] Config: (default) file_clone = false
[2024-03-22T16:44:34.271690 31056] Config: (default) hard_link = false
[2024-03-22T16:44:34.271690 31056] Config: (default) hash_dir = true
[2024-03-22T16:44:34.271690 31056] Config: (default) ignore_headers_in_manifest = 
[2024-03-22T16:44:34.271690 31056] Config: (default) ignore_options = 
[2024-03-22T16:44:34.271690 31056] Config: (default) inode_cache = true
[2024-03-22T16:44:34.271690 31056] Config: (default) keep_comments_cpp = false
[2024-03-22T16:44:34.271690 31056] Config: (E:\work\ccache\dir\ccache.conf) log_file = E:\work\ccache\log.txt
[2024-03-22T16:44:34.271690 31056] Config: (default) max_files = 0
[2024-03-22T16:44:34.271690 31056] Config: (default) max_size = 5.0 GiB
[2024-03-22T16:44:34.271690 31056] Config: (default) msvc_dep_prefix = Note: including file:
[2024-03-22T16:44:34.271690 31056] Config: (default) namespace = 
[2024-03-22T16:44:34.271690 31056] Config: (default) path = 
[2024-03-22T16:44:34.271690 31056] Config: (default) pch_external_checksum = false
[2024-03-22T16:44:34.271690 31056] Config: (E:\work\ccache\dir\ccache.conf) prefix_command = cl.exe
[2024-03-22T16:44:34.271690 31056] Config: (default) prefix_command_cpp = 
[2024-03-22T16:44:34.271690 31056] Config: (default) read_only = false
[2024-03-22T16:44:34.271690 31056] Config: (default) read_only_direct = false
[2024-03-22T16:44:34.271690 31056] Config: (default) recache = false
[2024-03-22T16:44:34.271690 31056] Config: (default) remote_only = false
[2024-03-22T16:44:34.271690 31056] Config: (default) remote_storage = 
[2024-03-22T16:44:34.271690 31056] Config: (default) reshare = false
[2024-03-22T16:44:34.271690 31056] Config: (default) run_second_cpp = true
[2024-03-22T16:44:34.271690 31056] Config: (default) sloppiness = 
[2024-03-22T16:44:34.271690 31056] Config: (default) stats = true
[2024-03-22T16:44:34.271690 31056] Config: (default) stats_log = 
[2024-03-22T16:44:34.271690 31056] Config: (default) temporary_dir = E:\work\ccache\dir/tmp
[2024-03-22T16:44:34.271690 31056] Config: (default) umask = 
[2024-03-22T16:44:34.271758 31056] Command line: C:\\ProgramData\\chocolatey\\lib\\ccache\\tools\\ccache-4.9.1-windows-x86_64\\ccache.exe @C:\\Users\\Mefi\\AppData\\Local\\Temp\\MSBuildTemp\\tmp08b79581ecfc4964824d52a02e98c7aa.rsp
[2024-03-22T16:44:34.274277 31056] Hostname: DESKTOP-8CS7IB9
[2024-03-22T16:44:34.274289 31056] Working directory: E:/work/_other/Ccache_test/Ccache_test
[2024-03-22T16:44:34.274306 31056] Compiler: @C:\Users\Mefi\AppData\Local\Temp\MSBuildTemp\tmp08b79581ecfc4964824d52a02e98c7aa.rsp
[2024-03-22T16:44:34.274344 31056] Compiler type: other
[2024-03-22T16:44:34.274424 31056] No input file found
[2024-03-22T16:44:34.275082 31056] Using command-line prefix cl.exe
[2024-03-22T16:44:34.275092 31056] Failed; falling back to running the real compiler
[2024-03-22T16:44:34.275102 31056] Executing "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX64\\x64\\cl.exe" @C:\\Users\\Mefi\\AppData\\Local\\Temp\\MSBuildTemp\\tmp08b79581ecfc4964824d52a02e98c7aa.rsp
[2024-03-22T16:44:34.275114 31056] Result: no_input_file
[2024-03-22T16:44:34.275130 31056] Acquiring E:\work\ccache\dir/5/0/stats.lock
[2024-03-22T16:44:34.275614 31056] Acquired E:\work\ccache\dir/5/0/stats.lock
[2024-03-22T16:44:34.275926 31056] Releasing E:\work\ccache\dir/5/0/stats.lock
[2024-03-22T16:44:34.275966 31056] Released E:\work\ccache\dir/5/0/stats.lock
[2024-03-22T16:44:34.276000 31056] Cleaning up E:\work\ccache\dir/tmp

@congzhangzh congzhangzh reopened this Mar 22, 2024
@congzhangzh
Copy link
Contributor Author

congzhangzh commented Mar 22, 2024

@StefanStojanovic Hi Stefan,

Can you try download ccache to ccache, and don’t install chocolatey, this may simple the debug process,

Btw, Can you show ccache -s and ccache —print-state here?

you can use https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer to get how ccache dummy cl& real cl be called too:)

@StefanStojanovic
Copy link
Contributor

Hey @congzhangzh it worked when using ccache directly, not via Chocolatey. Thanks for your help.

I want to enable using ccache in Node.js CI, and for that, Chocolatey would be great. I'll investigate the issues with that approach further.

@congzhangzh
Copy link
Contributor Author

Hey @congzhangzh it worked when using ccache directly, not via Chocolatey. Thanks for your help.

I want to enable using ccache in Node.js CI, and for that, Chocolatey would be great. I'll investigate the issues with that approach further.

@StefanStojanovic Hi Stefan, you should not use shimed ccache shim executable, but the the real file

the document https://github.com/ccache/ccache/wiki/MS-Visual-Studio point that, you can:

copy C:\ProgramData\chocolatey\lib\ccache\tools\ccache-4.7.4-windows-x86_64\ccache.exe C:\some\folder\cl.exe

BTW, some of the ccache document update by me recently, you may need double check:)

@StefanStojanovic
Copy link
Contributor

@StefanStojanovic Hi Stefan, you should not use shimed ccache shim executable, but the the real file

the document https://github.com/ccache/ccache/wiki/MS-Visual-Studio point that, you can:

copy C:\ProgramData\chocolatey\lib\ccache\tools\ccache-4.7.4-windows-x86_64\ccache.exe C:\some\folder\cl.exe

BTW, some of the ccache document update by me recently, you may need double check:)

Thanks for the heads up @congzhangzh. I saw that Chocolatey's using shimmed ccache and that's a problem. Still, on the other hand, Chocolatey gives us a simple mechanism for updating installed packages (we already leverage this in the CI). Since it downloads the actual ccache.exe, I can copy it as cl.exe somewhere and use it directly while using Chocolatey for updating. I'll still investigate my options, but this should be achievable one way or the other.

@congzhangzh
Copy link
Contributor Author

congzhangzh commented Mar 28, 2024

@StefanStojanovic Hi Stefan, I create a new pull request focus on ccache 4 windows

#52255

<ObjectFileName>$(IntDir)%(FileName).obj</ObjectFileName>
</ClCompile>
</ItemDefinitionGroup>
</Project> No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add an empty line at the bottom?

Also, I think a better place for this file would be in tools/msvs as there are all Windows-specific tools. Once you move it, just make sure to change the path in ForceImportAfterCppProps in vcbuild.bat too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, got it :)

set "extra_msbuild_args=%extra_msbuild_args% /p:UseMultiToolTask=True"
set "extra_msbuild_args=%extra_msbuild_args% /p:EnforceProcessCountAcrossBuilds=True"
set "extra_msbuild_args=%extra_msbuild_args% /p:MultiProcMaxCount=%NUMBER_OF_PROCESSORS%"
set "extra_msbuild_args=%extra_msbuild_args% /p:VcpkgEnabled=false"
Copy link
Contributor

Choose a reason for hiding this comment

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

This line was not here before (the other 3 are rewritten). Is this connected with your other PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Partially, if this pull request is approved, the https://github.com/nodejs/node/pull/52181/files will be upgraded to use vcbuild ccache switch directly:)

I'm a little worried, this pr changed too much, which is hard to accept, so I decided to split it out or drop this pull request, but use cmdline to config msbbuild directly, which is enough to make it work.

Btw, I don't like vcbuild.bat, why not use configure.py directly, The windows support for developing node itself is not so good, maybe most guys use linux/mac:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, maybe that's my fault, it seems just setting environment variable is enough, I will check it later

https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-use-environment-variables-in-a-build?view=vs-2022

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@StefanStojanovic Hi Stefan, sorry about my fault, it works by setting msbuild property directly

I do a test

set TrackFileAccess=false
set UseMultiToolTask=true
: allow link symbols redefine
set ForceImportAfterCppTargets=some_build.targets
msbuild ConsoleApplication_with_symbol_redefine.sln

and it works!

@congzhangzh
Copy link
Contributor Author

let's move to #52255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. windows Issues and PRs related to the Windows platform.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants