public void RebuildLibraryAndAPI()
        {
            UpdateMsBuildPath();
            CheckIspcBinary();

            ProjectConfigKind configKind = ProjectConfigKind;
            SimpleVcxProjGen  gen        = new SimpleVcxProjGen();
            //set some proprties

            //eg. IspcFilename=> simple.ispc

            string onlyProjectName = Path.GetFileNameWithoutExtension(IspcFilename);

            gen.ProjectName = onlyProjectName; //project name and output

            string current_dir = Directory.GetCurrentDirectory();
            string tmp_dir     = current_dir + "/temp";

            gen.FullProjSrcPath   = current_dir;
            gen.FullProjBuildPath = tmp_dir;
            string finalProductName = gen.GetFinalProductName(configKind);

            //-----
            CreateDirIfNotExists(tmp_dir);
            //

            string ispc_src       = IspcFilename;
            string ispc_obj       = tmp_dir + "/" + onlyProjectName + ".obj";
            string ispc_llvm_text = tmp_dir + "/" + onlyProjectName + "_ispc.llvm.txt";
            string ispc_cpp       = tmp_dir + "/" + onlyProjectName + "_ispc.cpp";
            string ispc_header    = tmp_dir + "/" + onlyProjectName + "_ispc.h";


            //generate header and object file in temp dir
            var procStartInfo = new System.Diagnostics.ProcessStartInfo(s_ispc,
                                                                        $"{ispc_src} -O2 -o {ispc_obj} -h {ispc_header}");

            //$"{ispc_src} --emit-c++ -o {ispc_cpp}");
            //$"{ispc_src} --emit-llvm-text -o {ispc_llvm_text} -h {ispc_header}");

            procStartInfo.UseShellExecute        = false;
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.RedirectStandardError  = true;

            System.Diagnostics.Process proc = System.Diagnostics.Process.Start(procStartInfo);


            StreamReader errReader = proc.StandardError;
            {
                string line = errReader.ReadLine();
                while (line != null)
                {
                    System.Diagnostics.Debug.WriteLine(line);
                    line = errReader.ReadLine();
                }
            }
            StreamReader outputStrmReader = proc.StandardOutput;

            {
                string line = outputStrmReader.ReadLine();
                while (line != null)
                {
                    System.Diagnostics.Debug.WriteLine(line);
                    line = outputStrmReader.ReadLine();
                }
            }

            proc.WaitForExit();

            int exit_code2 = proc.ExitCode;

            if (exit_code2 != 0)
            {
                throw new NotSupportedException();
            }
            //----------
            //now read auto-gen header

            string c_interface_filename = gen.FullProjSrcPath + "/" + onlyProjectName + ".cpp";

            CodeCompilationUnit cu = ParseAutoGenHeaderFromFile(ispc_header);

            GenerateCBinder(cu, ispc_header, c_interface_filename);

            string cs_method_invoke_filename = onlyProjectName + ".cs"; //save to

            GenerateCsBinder(cu, ispc_header, cs_method_invoke_filename, Path.GetFileName(finalProductName));

            //move cs code to src folder
            if (AutoCsTargetFile != null)
            {
                MoveFileOrReplaceIfExists(cs_method_invoke_filename, AutoCsTargetFile);
            }

            //
            //at this step we have object file and header
            //build a cpp dll with msbuild
            gen.AddObjectFile(ispc_obj);
            gen.AddIncludeFile(ispc_header);
            //add our c-interface
            gen.AddCompileFile(c_interface_filename);

            if (AdditionalInputItems != null)
            {
                foreach (string s in AdditionalInputItems)
                {
                    switch (Path.GetExtension(s))
                    {
                    default: throw new NotSupportedException();

                    case ".c":
                    case ".cpp":
                        gen.AddCompileFile(s);
                        break;

                    case ".h":
                    case ".hpp":
                        gen.AddIncludeFile(s);
                        break;

                    case ".obj":
                        gen.AddObjectFile(s);
                        break;
                    }
                }
            }


            VcxProject project = gen.CreateVcxTemplate();

            XmlOutputGen xmlOutput = new XmlOutputGen();

            project.GenerateOutput(xmlOutput);

            string vxs_projOutputFilename = "ispc_autogen.xml.vcxproj";

            File.WriteAllText(vxs_projOutputFilename, xmlOutput.Output.ToString());

            //debug build or release build

            string p_config = "";

            switch (configKind)
            {
            default: throw new NotSupportedException();

            case ProjectConfigKind.Debug:
                p_config = " /p:configuration=debug";
                break;

            case ProjectConfigKind.Release:
                p_config = " /p:configuration=release";
                break;
            }

            System.Diagnostics.Process proc1 = System.Diagnostics.Process.Start(s_MsBuildPath, vxs_projOutputFilename + p_config);
            proc1.WaitForExit();
            int exit_code1 = proc1.ExitCode;

            if (exit_code1 != 0)
            {
                throw new NotSupportedException();
            }

            //build pass, then copy the result dll back
            MoveFileOrReplaceIfExists(finalProductName, Path.GetFileName(finalProductName));
        }
Exemple #2
0
        internal VcxProject CreateVcxTemplate()
        {
            VcxProject proj = new VcxProject();
            {
                _proj_config = ProjectConfigKind.Debug;

                ConfigSetup();
                ProjectConfiguration projConfig = NewProjectConfig();
                proj.Configurations.Add(projConfig);
            }
            {
                _proj_config = ProjectConfigKind.Release;

                ConfigSetup();
                ProjectConfiguration projConfig = NewProjectConfig();
                proj.Configurations.Add(projConfig);
            }

            GlobalsPropertyGroup globalsProp = proj.GlobalsPropertyGroup;

            globalsProp.ProjectGuid = "{" + Guid.NewGuid() + "}";
            globalsProp.WindowsTargetPlatformVersion = "10.0.18362.0";
            globalsProp.Keyword     = "Win32Proj";
            globalsProp.Platform    = _platform;
            globalsProp.ProjectName = ProjectName; //TODO:
            globalsProp.VCProjectUpgraderObjectName = "NoUpgrade";

            //
            proj.ProjectFileVersion = _projFileVersion;
            proj.CppDefaultProp     = new Import {
                Project = @"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
            };
            proj.CppProp = new Import {
                Project = @"$(VCTargetsPath)\Microsoft.Cpp.props"
            };
            //---------------

            proj.InputItems = _inputs;


            foreach (InputItem item in _inputs)
            {
                //resolve path to abs path
                if (!Path.IsPathRooted(item.Include) ||
                    !File.Exists(item.Include))
                {
                    throw new NotSupportedException();
                }
            }

            proj.PropertySheets = new PropertySheets()
            {
                Import = new Import()
                {
                    Label     = "LocalAppDataPlatform",
                    Project   = @"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props",
                    Condition = @"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')",
                }
            };

            return(proj);
        }
Exemple #3
0
 public string GetFinalProductName(ProjectConfigKind configKind)
 {
     _proj_config = configKind;
     ConfigSetup();
     return(_finalProductFilename);
 }
        public void RebuildLibraryAndAPI()
        {
            UpdateMsBuildPath();


            ProjectConfigKind configKind = ProjectConfigKind;
            SimpleVcxProjGen  gen        = new SimpleVcxProjGen();
            //set some proprties

            //eg. IspcFilename=> simple.ispc

            string onlyProjectName = ProjectName;

            gen.ProjectName = onlyProjectName; //project name and output

            string current_dir = Directory.GetCurrentDirectory();
            string tmp_dir     = current_dir + "/temp";

            gen.FullProjSrcPath   = current_dir;
            gen.FullProjBuildPath = tmp_dir;
            string finalProductName = gen.GetFinalProductName(configKind);

            //build ispc
            if (!Directory.Exists(tmp_dir))
            {
                Directory.CreateDirectory(tmp_dir);
            }
            //-------------
            //save primary source and header
            string prim_src_filename    = tmp_dir + "/main_src.cpp";
            string prim_header_filename = tmp_dir + "/main_src.h";

            File.WriteAllText(prim_src_filename, PrimarySource);
            File.WriteAllText(prim_header_filename, PrimaryHeader);
            gen.AddCompileFile(prim_src_filename);
            gen.AddIncludeFile(prim_header_filename);

            //string c_interface_filename = gen.FullProjSrcPath + "/" + onlyProjectName + ".cpp";

            //CodeCompilationUnit cu = ParseAutoGenHeaderFromFile(ispc_header);

            //GenerateCBinder(cu, ispc_header, c_interface_filename);

            //string cs_method_invoke_filename = onlyProjectName + ".cs"; //save to

            //GenerateCsBinder(cu, ispc_header, cs_method_invoke_filename, Path.GetFileName(finalProductName));

            ////move cs code to src folder
            //if (AutoCsTargetFile != null)
            //{
            //    MoveFileOrReplaceIfExists(cs_method_invoke_filename, AutoCsTargetFile);
            //}

            //-------------

            if (AdditionalInputItems != null)
            {
                foreach (string s in AdditionalInputItems)
                {
                    switch (Path.GetExtension(s))
                    {
                    default: throw new NotSupportedException();

                    case ".c":
                    case ".cpp":
                        gen.AddCompileFile(s);
                        break;

                    case ".h":
                    case ".hpp":
                        gen.AddIncludeFile(s);
                        break;

                    case ".obj":
                        gen.AddObjectFile(s);
                        break;
                    }
                }
            }

            VcxProject   project   = gen.CreateVcxTemplate();
            XmlOutputGen xmlOutput = new XmlOutputGen();

            project.GenerateOutput(xmlOutput);

            string vxs_projOutputFilename = "myvcx_autogen.xml.vcxproj";

            File.WriteAllText(vxs_projOutputFilename, xmlOutput.Output.ToString());

            //debug build or release build

            string p_config = "";

            switch (configKind)
            {
            default: throw new NotSupportedException();

            case ProjectConfigKind.Debug:
                p_config = " /p:configuration=debug";
                break;

            case ProjectConfigKind.Release:
                p_config = " /p:configuration=release";
                break;
            }

            System.Diagnostics.Process proc1 = System.Diagnostics.Process.Start(s_MsBuildPath, vxs_projOutputFilename + p_config);
            proc1.WaitForExit();
            int exit_code1 = proc1.ExitCode;

            if (exit_code1 != 0)
            {
                throw new NotSupportedException();
            }
            //build pass, then copy the result dll back
            MoveFileOrReplaceIfExists(finalProductName, Path.GetFileName(finalProductName));
        }