microsoft / BuildXL

Microsoft Build Accelerator
MIT License
902 stars 141 forks source link

Building a C++ VS Solution Using MSBuild #1335

Open Zo11 opened 4 weeks ago

Zo11 commented 4 weeks ago

Hi there, I've been exploring BuildXL to improve our build times, but I've had some issues setting up a simple Hello World test using solution files.

I created the following using Visual Studio 2019:

I can call msbuild HelloWorld.sln and it will successfully build the code.

However, building with BuildXL is a different story.

BuildXL seems to only like it when I specify the vcxproj file in the config, as follows:

config({
    resolvers: [
        {
            kind: "MsBuild",
            root: d`.`,
            moduleName: "HelloWorld",
            msBuildSearchLocations: [d`C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin`],
            fileNameEntryPoints: [r`HelloWorld.vcxproj`]
        }
    ]
});

The code above builds perfectly.

But if I were to use .sln instead:

config({
    resolvers: [
        {
            kind: "MsBuild",
            root: d`.`,
            moduleName: "HelloWorld",
            msBuildSearchLocations: [d`C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin`],
            fileNameEntryPoints: [r`HelloWorld.sln`]
        }
    ]
});

I get:

[0:02] error DX0046: [Pip0819D8CC9E0B31E4, MSBuild.exe (HelloWorld - E:\buildxl_test\HelloWorld.vcxproj), HelloWorld, HelloWorld.BUILDINGSOLUTIONFILE_true.CONFIGURATION_Debug.CURRENTSOLUTIONCONFIGURATIONCONTENTS__SolutionConfiguration______ProjectConfiguration_Project___D1B93E72_56CD_4A11_8B4E_23A5F01B9C76___AbsolutePath__E__buildxl_test_HelloWorld.vcxproj__BuildProjectInSolution__True__Debug_x64__ProjectConfiguration_____SolutionConfiguration_.PLATFORM_x64.SOLUTIONDIR_E__buildxl_test_.SOLUTIONEXT_sln.SOLUTIONFILENAME_HelloWorld.sln.SOLUTIONNAME_HelloWorld.SOLUTIONPATH_E__buildxl_test_HelloWorld.sln, {}, E:\buildxl_test\Out\Logs\MSBuild\HelloWorld.vcxproj\Debug-E__buildxl_test_-E__buildxl_test_HelloWorld.sln-HelloWorld-HelloWorld.sln-_SolutionConfiguration______ProjectConfiguration_Project___D1B93E72_56CD_4A11_8B4E_23A5F01B9C76___AbsolutePath__E__buildxl_test_HelloWorld.vcxproj__BuildProjectInSolution__True__Debug_x64__ProjectConfiguration_____SolutionConfiguration_-sln-true-x64\msbuild.log, 123]Process output directories could not be prepared, path 'E:\buildxl_test\Out\Logs\MSBuild\HelloWorld.vcxproj\Debug-E__buildxl_test_-E__buildxl_test_HelloWorld.sln-HelloWorld-HelloWorld.sln-_SolutionConfiguration______ProjectConfiguration_Project___D1B93E72_56CD_4A11_8B4E_23A5F01B9C76___AbsolutePath__E__buildxl_test_HelloWorld.vcxproj__BuildProjectInSolution__True__Debug_x64__ProjectConfiguration_____SolutionConfiguration_-sln-true-x64\msbuild.log', error code 0000007B: Failed to create directory as current dir : E:\buildxl_test\Out\Logs\MSBuild\HelloWorld.vcxproj\Debug-E__buildxl_test_-E__buildxl_test_HelloWorld.sln-HelloWorld-HelloWorld.sln-_SolutionConfiguration______ProjectConfiguration_Project___D1B93E72_56CD_4A11_8B4E_23A5F01B9C76___AbsolutePath__E__buildxl_test_HelloWorld.vcxproj__BuildProjectInSolution__True__Debug_x64__ProjectConfiguration_____SolutionConfiguration_-sln-true-x64 is a valid reparse point but does not point to an existing target. Complete directory path - 'E:\buildxl_test\Out\Logs\MSBuild\HelloWorld.vcxproj\Debug-E__buildxl_test_-E__buildxl_test_HelloWorld.sln-HelloWorld-HelloWorld.sln-_SolutionConfiguration______ProjectConfiguration_Project___D1B93E72_56CD_4A11_8B4E_23A5F01B9C76___AbsolutePath__E__buildxl_test_HelloWorld.vcxproj__BuildProjectInSolution__True__Debug_x64__ProjectConfiguration_____SolutionConfiguration_-sln-true-x64':
Native: CreateDirectoryW for CreateDirectory failed (0x7B: The filename, directory name, or volume label syntax is incorrect.)

Not sure if I'm missing more settings in the config file to prevent this, but I after reading the options for the MsBuildResolver, nothing really stands out.

Any help would be appreciated!

narasamdya commented 1 week ago

It looks like that, when building solution, BuildXL tried to create a path with a very long name:

Debug-E__buildxl_test_-E__buildxl_test_HelloWorld.sln-HelloWorld-HelloWorld.sln-_SolutionConfiguration______ProjectConfiguration_Project___D1B93E72_56CD_4A11_8B4E_23A5F01B9C76___AbsolutePath__E__buildxl_test_HelloWorld.vcxproj__BuildProjectInSolution__True__Debug_x64__ProjectConfiguration_____SolutionConfiguration_-sln-true-x64

The name has 330 chars, while I think the max is 256.

As a workaround, for now, you may want to enable long path on your system. See here for details.

Zo11 commented 4 hours ago

@narasamdya Thanks for your reply. As it turns out, I had already enabled long paths for another application years ago, so that error message came from a PC with Long Paths already enabled. And this 330 char name is for a hello world solution. If I attempt to build a real-world solution with dozens of projects I get an error message with thousands of characters in the name.

There's probably a bug (feature?) in the code that appends several of the XML (.sln) components to a path when parsing a Visual Studio solution file. I don't know enough about BuildXL to be able to pinpoint where that happens and how to disable that behavior, so I was hoping a more experienced user would help me out.