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

/generateDebugSolution does not work #41

Closed
Nuclearfossil opened this issue Sep 22, 2018 · 10 comments
Closed

/generateDebugSolution does not work #41

Nuclearfossil opened this issue Sep 22, 2018 · 10 comments

Comments

@Nuclearfossil
Copy link

Following along with the example here: https://github.com/ubisoftinc/Sharpmake/blob/master/docs/OVERVIEW.md#create-a-debugging-environment

I've added the /generateDebugSolution option to my build:

..\bin\Sharpmake.Application.exe /sources(@"main.sharpmake.cs") /verbose /generateDebugSolution

The result is as follows:

E:\dev\C++\fbxdebugger\build>..\bin\Sharpmake.Application.exe /sources(@"main.sharpmake.cs") /verbose /generateDebugSolution
[00:00] sharpmake
[00:00]   arguments : /sources(@"main.sharpmake.cs") /verbose /generateDebugSolution
[00:00]   directory : E:\dev\C++\fbxdebugger\build
[00:00]
[00:00] input sources:
[00:00]   E:\dev\C++\fbxdebugger\build\main.sharpmake.cs
[00:00]   building projects and solutions configurations using 8 tasks...
[00:00]     build done in 0.0 sec

Error:
The type "Sharpmake.DebugSolution" does not declare a constructor, please add one to allow Sharpmake to detect source file from construction callstack.
[00:00]         While running E:\dev\C++\fbxdebugger\bin\Sharpmake.Application.exe
        @9/21/2018 11:52:39 PM: Exception message (level 0):
        Unhandled exception in thread pool
        Inner exception message (level 1):
        Cannot create instances of type: DebugSolution, caught exception message Exception has been thrown by the target of an invocation.. Make sure default ctor is public
        Inner exception message (level 2):
        Exception has been thrown by the target of an invocation.
        Inner exception message (level 3):
        The type "Sharpmake.DebugSolution" does not declare a constructor, please add one to allow Sharpmake to detect source file from construction callstack.

        Stack trace:
        Inner exception stack trace (level 3):
   at Sharpmake.Util.GetStackSourceFileTopMostTypeOf(Type type, String& sourceFile)
   at Sharpmake.Solution.Initialize(Type targetType)
   at Sharpmake.DebugSolution..ctor()
        Inner exception stack trace (level 2):
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Sharpmake.Solution.CreateProject(Type solutionType, List`1 fragmentMasks)
        Inner exception stack trace (level 1):
   at Sharpmake.Solution.CreateProject(Type solutionType, List`1 fragmentMasks)
   at Sharpmake.Builder.LoadSolutionType(Type type)
   at Sharpmake.Builder.BuildProjectAndSolutionTask(Object parameter)
   at Sharpmake.ThreadPool.ThreadWork(Object obj)
        Root stack trace (level 0):
   at Sharpmake.ThreadPool.Wait()
   at Sharpmake.Builder.BuildProjectAndSolution()
   at Sharpmake.Application.Program.CreateBuilder(BaseBuildContext context, Argument parameters, Boolean allowCleanBlobs, Boolean generateDebugSolution)
   at Sharpmake.Application.Program.GenerateAll(BaseBuildContext buildContext, Argument parameters)
   at Sharpmake.Application.Program.Main()

my sharpmake source file is as follows:

using System.IO; // for Path.Combine
using Sharpmake; // contains the entire Sharpmake object library.

// Represents the project that will be generated by Sharpmake and that contains
// the sample C++ code.
[Generate]
class BasicsProject : Project
{
    private string ImGuiRootPath;
    public BasicsProject()
    {
        // The name of the project in Visual Studio. The default is the name of
        // the class, but you usually want to override that.
        Name = "Basics";

        // The directory that contains the source code we want to build is the
        // same as this one. This string essentially means "the directory of
        // the script you're reading right now."
        SourceRootPath = @"[project.SharpmakeCsPath]\..\src";
        ImGuiRootPath = @"[project.SourceRootPath}\..extern\imgui";

        SourceFiles.Add(@"[project.ImGuiRootPath]\imgui.cpp");
        SourceFiles.Add(@"[project.ImGuiRootPath]\imgui_draw.cpp");
        SourceFiles.Add(@"[project.ImGuiRootPath]\imgui_widgets.cpp");

        // Specify the targets for which we want to generate a configuration
        // for. Instead of creating multiple targets manually here, we can
        // use the binary OR operator to define multiple targets at once.
        // Sharpmake will generate all combinations possible and generate a
        // target for it.
        //
        // The code below is the same as creating 4 separate targets having
        // those flag combinations:
        //    * Platform.win32, DevEnv.vs2015, Optimization.Debug
        //    * Platform.win32, DevEnv.vs2015, Optimization.Release
        //    * Platform.win64, DevEnv.vs2015, Optimization.Debug
        //    * Platform.win64, DevEnv.vs2015, Optimization.Release
        AddTargets(new Target(
            // we want a target that builds for both 32 and 64-bit Windows.
            Platform.win32 | Platform.win64,

            // we only care about Visual Studio 2017. (Edit as needed.)
            DevEnv.vs2017,

            // of course, we want a debug and a release configuration.
            Optimization.Debug | Optimization.Release));
    }

    // Sets the properties of each configuration (conf) according to the target.
    //
    // This method is called once for every target specified by AddTargets. Since
    // we only want vs2015 targets and we want 32- and 64-bit targets, each having
    // a debug and a release version, we have 1 x 2 x 2 targets to configure, so it
    // will be called 4 times.
    //
    // If we had instead specified vs2012 | vs2015 | vs2017 it would have been
    // called 12 times. (3 x 2 x 2)
    [Configure]
    public void ConfigureAll(Project.Configuration conf, Target target)
    {
        // Specify where the generated project will be. Here we generate the
        // vcxproj in a /generated directory.
        conf.ProjectPath = Path.Combine("[project.SharpmakeCsPath]", "generated");
        conf.IncludePaths.Add(@"[project.SourceRootPath]\..\extern\imgui");
    }    
}

// Represents the solution that will be generated and that will contain the
// project with the sample code.
[Generate]
class BasicsSolution : Solution
{
    public BasicsSolution()
    {
        // The name of the solution.
        Name = "Basics";

        // As with the project, define which target this solution builds for.
        // It's usually the same thing.
        AddTargets(new Target(
            Platform.win32 | Platform.win64,
            DevEnv.vs2017,
            Optimization.Debug | Optimization.Release));
    }

    // Configure for all 4 generated targets. Note that the type of the
    // configuration object is of type Solution.Configuration this time.
    // (Instead of Project.Configuration.)
    [Configure]
    public void ConfigureAll(Solution.Configuration conf, Target target)
    {
        // Puts the generated solution in the /generated folder too.
        conf.SolutionPath = @"[solution.SharpmakeCsPath]\generated";

        // Adds the project described by BasicsProject into the solution.
        // Note that this is done in the configuration, so you can generate
        // solutions that contain different projects based on their target.
        //
        // You could, for example, exclude a project that only supports 64-bit
        // from the 32-bit targets.
        conf.AddProject<BasicsProject>(target);
    }

    [Main]
    public static void SharpmakeMain(Arguments sharpmakeArgs)
    {
        // Tells Sharpmake to generate the solution described by BasicsSolution.
        sharpmakeArgs.Generate<BasicsSolution>();
    }
}
@kudaba
Copy link
Contributor

kudaba commented Sep 23, 2018

It looks like a problem with sharpmake source itself. I just tested adding /generateDebugSolution to both master and dev branche versions of UpdateSharpmakeProjects.bat after compiling locally, and with no local changes, and it works fine. What commit are you based off of and do you have any local changes to sharpmake itself?

@Nuclearfossil
Copy link
Author

Hullo Mr. Savoie - long time no see ;)

This is straight off master with zero changes

@kudaba
Copy link
Contributor

kudaba commented Sep 24, 2018

Hihi, been a while :D

How exactly are you building your binary? I tried again with a clean repo and built from Sharpmake.sln (using VS2017). If you do that and add /generateDebugSolution to UpdateSharpmakeProjects.bat(32) does that bat file run without error?

@Nuclearfossil
Copy link
Author

Nuclearfossil commented Sep 25, 2018 via email

@fpuma
Copy link

fpuma commented Dec 7, 2018

Hello @Nuclearfossil ,
I was having this same issue.
Once you compile the Sharpmake.Application from the solution, make sure that you copy the following files from the "Sharpmake.Application/bin/release" (or debug if you compiled debug) into the sharpmake.cs files of your build:
neededfiles

Then you can use a .bat file like this one to create the debug solution:

@echo off Sharpmake.Application.exe /sources(@"solution.sharpmake.cs") /verbose /generateDebugSolution pause

generatedebugsharpmakesolution.txt
(Change the .txt extension for .bat)

The reason why it was failing for me was because I did not copy the .pdb files, I guess to create a debug solution it needs them.
You can also do this from the .sln of the sharpmake source, but you would need to change some debug fields in the Sharpmake.Application properties (I do not know if this is actually what you want, let me know if it is)

Hope this helps,

Cheers.

@BryanRobertson
Copy link

I only just noticed this issue (also hi everyone! :) )
I had the same problem a few months back, and it turned out that the /generateDebugSolution commandline switch only worked for me if I compiled Sharpmake in Debug.

Not sure if that's still the case

@kudaba
Copy link
Contributor

kudaba commented Apr 5, 2019

There's definitely something odd going on, I have a setup closer to fpuma and it's been working flawlessly for the last year using the Release built binaries. My bat file just does the following:

call bin\Sharpmake.Application.exe "/sources(@"SharpMake\Main.cs") /verbose /generateDebugSolution"

And it's called from the root of my project. Not sure why I have the extra quotes in there, it seems to run fine if I remove them. I also have not problems running from the generated debug solution or running debug or release directly from the Sharpmake solutions either. In addition to the binaries that fpuma lists I'm also copying over Microsoft.Build.Utilities.v4.0.dll and Microsoft.VisualStudio.Setup.Configuration.Interop.dll.

(Hi Bryan!)

@Teknogrebo
Copy link

I got the same issue. Copying over all dlls and pdbs from my release build fixed it. Can somebody please update the documentation so that it is up to date?

@GamingMinds-UlfW
Copy link

It seems that even the release version needs Sharpmake.pdb. The reason is that Solution.cs file tries to get a source file for the DebugProject project used in Debug solution creation. It does so by utilizing StackTrace . The DebugProject however is located in DebugProjectGenerator.cs inside the Sharpmake source.
Without the pdb file, there is no source file info for that file, and the code throws an exception. Unfortunately using "Embedded" Debug symbols does not work, that was my first attempt at fixing it.
So the only solutions I can think of -apart from just shipping the .pdb file- would be either to externalize the parts of DebugProjectGenerator.cs which generate the Debug solution, or to rewrite the code in some way to work without the source file.

At the moment I don't have time to try either, so I just wanted to share my findings in case someone else wants to have a go at it.

@belkiss
Copy link
Contributor

belkiss commented Apr 23, 2021

Closing this, if you take the .zip files with the prebuilt sharpmake binaries it works :)

@belkiss belkiss closed this as completed Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants