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

Clang error when VS not installed #161

Open
sammyfreg opened this issue Dec 26, 2021 · 6 comments
Open

Clang error when VS not installed #161

sammyfreg opened this issue Dec 26, 2021 · 6 comments

Comments

@sammyfreg
Copy link

I just updated to the latest release of Sharpmake (0.18.1) , and noticed a solution generation error tied to the Clang toolset.

I have VS2019 installed and can successfully generate MSBuild and Clang build configs.

I then added the VS2022 config to my DevEnv, before actually installing VisualStudio 2022. This was done as a test, but I would like the generation to not fail and just skip a Visual Studio version, when it cannot be found, since I do not expect users to have all versions installed.

Thank you.

Here's the output log

sharpmake 0.18.1
  arguments: /sources(@"Build/shared.sharpmake.cs", @"Build/nocompatibility.sharpmake.cs", @"Build/netImgui.sharpmake.cs")
  directory: C:\GitHub\NetImguiDev
  platform: win64 - Microsoft Windows 10.0.19042
  compiled with framework: .NETCoreApp,Version=v5.0
  running on framework: .NET 5.0.6

. . . 

Couldn't find C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64 to lookup version
    generation done in 0.3 sec
[ERROR]
Error:
Couldn't find C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64 to lookup version
        While running C:\GitHub\NetImguiDev\Build\Sharpmake\Sharpmake.Application.exe
        @12/26/2021 18:34:21: Exception message (level 0):
        Error encountered while generating NetImgui.ProjectNetImgui32_Default
        Inner exception message (level 1):
        Couldn't find C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64 to lookup version

        Stack trace:
        Inner exception stack trace (level 1):
   at Sharpmake.Util.GetClangVersionFromLLVMInstallDir(String llvmInstallDir)
   at Sharpmake.ClangForWindows.Settings.<>c__DisplayClass14_0.<ClangVersionVsEmbedded>b__0(DevEnv d)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Sharpmake.ClangForWindows.Settings.ClangVersionVsEmbedded(DevEnv devEnv)
   at Sharpmake.ClangForWindows.GetWindowsClangIncludePath(DevEnv devEnv)
   at Sharpmake.Windows.Win64Platform.GetPlatformIncludePathsWithPrefixImpl(IGenerationContext context)
   at Sharpmake.BasePlatform.GetPlatformIncludePaths(IGenerationContext context)
   at Sharpmake.Generators.VisualStudio.Vcxproj.FillIncludeDirectoriesOptions(GenerationContext context)
   at Sharpmake.Generators.VisualStudio.Vcxproj.GenerateConfOptions(GenerationContext context)
   at Sharpmake.Generators.VisualStudio.Vcxproj.GenerateImpl(GenerationContext context, IList`1 generatedFiles, IList`1 skipFiles)
   at Sharpmake.Generators.VisualStudio.Vcxproj.Generate(Builder builder, Project project, List`1 configurations, String projectFile, List`1 generatedFiles, List`1 skipFiles)
   at Sharpmake.Generators.GeneratorManager.Generate(Builder builder, Project project, List`1 configurations, String projectFile, List`1 generatedFiles, List`1 skipFiles)
   at Sharpmake.Builder.GenerateProjectFile(Object arg)
        Root stack trace (level 0):
   at Sharpmake.Application.Program.CreateBuilderAndGenerate(BaseBuildContext buildContext, Argument parameters, Boolean generateDebugSolution)
   at Sharpmake.Application.Program.GenerateAll(BaseBuildContext buildContext, Argument parameters)
   at Sharpmake.Application.Program.Main()
@belkiss
Copy link
Contributor

belkiss commented Dec 26, 2021

Heya!

When you say just skip a Visual Studio version, what behavior do you think makes the most sense? Not generate the files at all? Or generate faulty ones? We could also add a bool to control the behavior when a required value is missing.

Just a side note, for your use case, you could set ClangForWindows.Settings.LLVMInstallDir to the path of your current LLVM install (like the one embedded in your vs2019 installation), to make the generation succeed?

@sammyfreg
Copy link
Author

I was thinking of not generating the solution at all, if the Visual Studio install directory is not found. But this is a behaviour change beyond this clang error, so maybe at the very least, not generate the clang build target.

My usercase is that I have 1 batfile generating 1 solution file per VS version (17, 19, 22). Each with MSBuild and Clang build targets (except 17). Users of my library (NetImgui) can then generates the solutions and open the one matching the version that they have installed.

Maybe it could be a new solution/project option, to ignore a DevEnv output, if it is not found on the PC.

As for manually specifying the clang install dir, I cannot do that, since I do not know/control the setup of people using my library.

Thank you.

@belkiss
Copy link
Contributor

belkiss commented Dec 26, 2021

So far sharpmake was allowed to generate projects and solutions even if the requirements to open them were not fulfilled, so I'm leaning towards doing that, maybe adding a warning though that we're using a fallback value for the clang version. I'll leave the issue open until it is fixed (no ETA though...).

Also, you can very well chose to short-circuit one or more DevEnv from your SharpmakeMain, by adding calls to the utility methods IsVisualStudioInstalled and then adding a global fragment mask depending on the values returned.

Something like:

[Sharpmake.Main]
public static void SharpmakeMain(Sharpmake.Arguments arguments)
{
    DevEnv foundDevEnv = 0;
    foreach (var devEnv in new [] { DevEnv.vs2017, DevEnv.vs2019, DevEnv.vs2022 })
    {
        if (Util.IsVisualStudioInstalled(devEnv))
            foundDevEnv |= devEnv;
    }
    if (foundDevEnv == 0)
        throw new Error("Couldn't find any installed visual studio version!");

    arguments.AddFragmentMask(foundDevEnv);

    ... // here the rest of your main
}

This will force sharpmake to only generate for the installed visual studio versions.

(note that I wrote that in the github comment so apologies if it doesn't compile because of typos!).

@sammyfreg
Copy link
Author

That code snippet is doing exactly what I would like, thank you, I will try it tomorrow.

I haven't tested to see what happen when requesting a Clang target, without it installed by the VS setup, it'll try it and see.

@sammyfreg
Copy link
Author

The method Util.IsVisualStudioInstalled is not accessible and IsVisualStudio2019Installed / IsVisualStudio2022Installed are missing.

I ended creating this method and calling it when adding my Targets in Project/Solution constructors. Works like a charm, though not a fan of the hardcoded 'clang.exe' file check.

// Generates a solution for each Visual Studio version found
// Note: Add a Clang target when detected isntalled for that Visual Studio version
static public NetImguiTarget[] CreateTargets()
{		
	List<NetImguiTarget> targets = new List<NetImguiTarget>();
	foreach (var devEnv in new [] { DevEnv.vs2017, DevEnv.vs2019, DevEnv.vs2022 })
	{				
		if( Util.DirectoryExists(devEnv.GetVisualStudioDir()) ){
			Compiler compiler = Compiler.MSBuild;
			if(Util.FileExists(ClangForWindows.Settings.LLVMInstallDirVsEmbedded(devEnv) + @"\bin\clang.exe" )){
				compiler |= Compiler.Clang;
			}
			targets.Add(new NetImguiTarget{DevEnv = devEnv, Compiler = compiler});
		}
	}
	return targets.ToArray();
}

@belkiss
Copy link
Contributor

belkiss commented Dec 27, 2021

Arf sorry about that. Glad you found a way though :)

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

No branches or pull requests

3 participants
@belkiss @sammyfreg and others