Is it possible to build Google V8 engine using Microsoft VC++ compiler? - v8

Some time ago I used instruction from V8 developers how to build V8 using their old metabuild system GYP and Microsoft VC++ compiler (from Visual Studio). It was pretty simple: use GYP to generate .sln file, build it with Microsoft VC++ compiler. Unfortunately, this instruction is not available anymore, because Google switched to another metabuild system (called GN) and abandoned GYP.
That's not really a problem, because GN also can create sln file - but, as far as I understand, they don't support Microsoft compiler anymore. They ship and use clang to build V8 on Windows (even when you build it from Visual Studio).
So, my question is: is it possible for current trunk of V8 code to create sln file, which can be opened in Visual Studio (let's say 2017) and can be build using Microsoft C++ compiler ?

These are three separate questions: (1) Is it possible to use GN to generate .sln files to open in Visual Studio? (2) Is it possible to compile V8 with the MSVC compiler? (3) Is it possible to build V8 from within Visual Studio?
(1) Yes. In short, run gn gen --ide=vs. See https://www.chromium.org/developers/gn-build-configuration.
(2) Yes. Put is_clang = false into your args.gn (editable by running gn args out\my_build_folder), then compile with ninja as usual. This is continuously tested, so it's guaranteed to keep working (as long as the MSVC compiler is officially supported by V8).
(3) I don't think so. You can try with the generated .sln, but the build process is fairly complicated (several stages of building one tool and then running it to generate output used by the next step), and I think the .sln mostly just contains a list of files, but no specific instructions for how to compile them.

Related

Visual Studio, CMake and Toolchain Files

before I explain my current problem with Visual Studio in combination with CMake, I try to explain what I want to accomplish as there might be a better solution.
At our company we have a huge code base mainly written in C for QNX. For development we are using the standard IDE QNX momentics. As this is based on a quite old eclipse version ... the whole IDE sucks.
I'm currently evaluating to use Visual Studio as a replacement. With a really simple HelloWorld-programm I was able to build and debug the project from within VS using CMake and a CMakeSettings.json.
As our code base is basically organized in a tree-like structure, I've created a typical hierarchy of CMakeLists.txt which allows me to build single/multiple projects.
As QNX delivers its own compiler I've created a toolchain file, this is running fine so far, the required toolchain is invoked once a build is triggered via cmake.
Now for the part that I'm struggling with:
How to use this CMake setup in order to develop/debug code from VS?
I had two ideas in mind which don't really work or I'm doing something wrong.
Use the CMake generator for VS 2019 and generate a complete solution. Problem: The toolchain file is not "used" as all projects will be setup with the internal VS compilers. Is there any way to get this working? I thought calling cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE=$FILE would do the job. Additionally: how would I incorporate the debugger configuration? With this solution the CMakeSettings.json seems to be ignored as VS solutions are used.
Use File->Open->CMake to open the root project. Shouldn't this show all "contained" projects which also include a CMakeLists.txt as projects? I can only see the folder tree in the Solution Explorer. Build a single project from the solution explorer is also not possible ... there is simply no option.
Anyone with experience on this topic?
Minor comment please limit questions to 1 question in the future. Multiple questions clutters questions and makes search results worse.
============================================================
I'll answer question #1 this part of question number 1.
"Use the CMake generator for VS 2019 and generate a complete solution. Problem: The toolchain file is not "used" as all projects will be setup with the internal VS compilers. Is there any way to get this working? I thought calling cmake -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE=$FILE would do the job."
Instead of using Visual Studio as your generator try using "Ninja" instead. Ninja will work if your toolchain code is correct. Toolchains and visual studio are complicated to say the least. If you wanna go down that rabbit hole I can help but that's a separate question
Basically try switching to Ninja instead of Visual Studio as your generator for CMakeSettings.json. Ninja is very easy to write toolchains for.
======================================================================
"Additionally: how would I incorporate the debugger configuration?"
The MSDN articles are actually quite good. I figured it out this week. In my opinion the debugger configurations are more powerful with the CMake approach than vanilla visual studio.
Configure CMake debugging sessions
https://learn.microsoft.com/en-us/cpp/build/configure-cmake-debugging-sessions?view=msvc-160
"Tutorial: Debug a CMake project on a remote Windows machine"
https://learn.microsoft.com/en-us/cpp/build/cmake-remote-debugging?view=msvc-160
Trust me once it clicks you'll love it.

What is the benefit of building with CMake?

I am working on SFML and I am curious about the option that I can compile it myself. I found it in tutorials, but from the first line I became confused:
CMake is an open-source meta build system. Instead of building SFML, it builds what builds SFML: Visual Studio solutions ...
There is a build option in visual studio too, is there any difference between that build and CMake build?
What does it mean that it builds what builds SFML? It means library files?
Visual studio solutions? What does it mean? As far as i know, when i open a new project it is within a solution and i can add new projects to this solution (I am confused about why there must be more than one project in a solution too!).
What does it mean that CMake builds a solution? And what is it for?
There is sourcecode. People want to compile it. It is difficult and annoying to type the compile commands into a terminal.
People invent build systems, to make 1.) more easy. For example make files or what Visual Studio integrates and stores in its files, called solution.
There are projects, that are cross-platform. They could provide make files, solution files, files for Xcode, Eclipse and so on. This becomes difficult and annoying.
People invent systems, that creates build system to ease 3.). From a common set of files, several different build systems can be steered.
In your actual case: CMake creates the solution file, you can open the solution file and built SFML with that.
CMake is a wonderful tool for cross-platform development without the hassle of maintaining separate build utilities. On Windows, CMake can create a Visual Studio solution file based on its CMakeLists.txt file. On Linux, generally CMake outputs a makefile. CMake is compatible with many build tools, I recommend reading more of there documentation on their website to gain more information.
Edit: Just to be more clear. CMake literally builds what builds SFML since it creates the Visual Studio solution used to build SFML.
A build in VS for a solution is building the library itself. A CMake build generates the VS solution with which you would use to build the library.
See 1.
A VS solution is the full buildable setup containing 1 or more projects. Solutions can contain multiple projects since VS has a limitation on only 1 output per project. If you want multiple outputs (e.g. 4 dlls) each output needs it's own project.

Compiling the opus-codec API library

First, going to be honest. I'm a c#/java-language-level dweller. So I have no idea about how to compile native-C projects such as opus.
I've tried doing it myself, and I've tried googling it. I simply need help compiling the opus-codec API (on Windows).
Once I have the library compiled, I'll build a wrapper for it's API.
While my searches have indeed found opus wrappers targeting my current project's language (c#), I can't find an up-to-date one. I don't know if it matters, but I need it for it's VoIP capabilities.
Sorry for my stupidity in the matter.
[UPDATE]
After compiling with Visual Studio 2010: Ultimate, I have a .lib library file. I need a .dll. I don't know what I'm doing. Help?
In a C project there is going to be some way to drive a build of all the object files, libraries, etc. Basically the same thing as maven build in Java, just with different tools. You will have to have the right tools if you don't.
On unix systems it's usually Makefile driven, running command line programs that compile and link the program or library that is being built. In GUI environments like XCode or Visual Studio, there are ways to run the build directly from the UI.
Looking at the source tree, there's a directory with a number of Visual Studio 2010 projects in it - https://git.xiph.org/?p=opus.git;a=tree;f=win32/VS2010
If you're using Visual Studio, loading that up and trying a build to see if it still works is where I'd start. Or perhaps have a look at Any way to do Visual Studio "project only" build from command line? or other questions that reference msbuild.

How to use GCC with Microsoft Visual Studio?

I am creating a very large project (a few thousand lines) and so would rather not use Notepad++. An IDE would make it so much easier. I have experience with Microsoft Visual Studio and love it. Is there some easy way to use Cygwin's GCC from within Microsoft Visual Studio?
Alternately, are there any other good Windows IDEs for GCC besides NetBeans and Eclipse? (I hate both of them with a passion.)
There are several ways to go here:
Option 1: Create a Custom Build Tool
Visual Studio 2005 and newer will let you register custom build tools. They tell the IDE how to transform files of one form (e.g. a .cpp file) into another form (e.g. an .obj file).
So far as I know, no one has done this yet for GCC. And, doing it yourself requires writing COM code, which is probably too deep a pool to dive into just for a single project. You'd have to have a compelling reason to take this project on.
You then have to manually adjust each project to tell it to use the custom build tool instead of the default, since you're using a file name extension (.cpp, probably) that Visual C++ already knows about. You'll run into trouble if you try to mix the VC++ and g++ compilers for a single executable built from multiple modules.
On the plus side, if you were looking to start an open source project, this sounds like a good one to me. I expect you'd quickly gather a big user base.
Option 2: Makefile Project
Start Visual Studio and say File > New Project.
In the Visual C++ section, select Makefile Project
Fill out the Makefile Project Wizard:
Build command line: make
Clean commands: make clean
Rebuild command line: make clean all
You can leave the Output (for debugging) field alone if you've named your executable after the project name and it lands where Visual Studio expects to find it.
Leave the rest of the fields alone unless you know what they are and why you want to change them. As an example, you might choose to pass a -D flag on the Preprocessor definitions line to get separate debug and release outputs. If you know you want this, you know how to set it up, so I'm not going to make this long answer even longer in order to explain it.
You'll be asked the same set of questions for the Release build. If you want to bother with separate debug and release builds, you'd make any changes here.
Having done all this, you still have to create the Makefile, and add a make.exe to your PATH. As with the debug vs. release question, going into that level of detail would push this answer off topic.
As ugly as this looks, it's still easier than creating custom build tools. Plus, you say you need to port to Unix eventually, so you're going to need that Makefile anyway.
Option 3: Cross-Platform Development
You say you want to port this program to Unix at some point, but that doesn't mean you must use GCC on Windows now. It is quite possible to write your program so that it builds under Visual C++ on Windows and GCC/Makefiles on *ix systems.
There are several tools that make this easier. One very popular option is CMake, which is available as an installation time option in newer versions of Visual Studio. There are many alternatives such as SCons and Bakefile.
Clang
You can use the Clang compiler with Visual Studio to target Android, iOS, and Windows.
If you are targeting Android, you can use the Clang/LLVM compiler that ships with the Android NDK and toolchain to build your project. Likewise, Visual Studio can use Clang running on a Mac to build projects targeting iOS. Support for Android and iOS is included in the “Mobile Development with C++” workload. For more information about targeting Android or iOS check out our posts tagged with the keywords “Android” and “iOS”.
If you are targeting Windows, you have a few options:
Use Clang/LLVM; “Clang for Windows” includes instructions to install Clang/LLVM as a platform toolset in Visual Studio.
Use Clang to target Windows with Clang/C2 (Clang frontend with Microsoft Code Generation).
GCC
If your project targets Linux or Android, you can consider using GCC. Visual Studio’s C++ Android development natively supports building your projects with the GCC that ships with the Android NDK, just like it does for Clang. You can also target Linux – either remotely or locally with the Windows Subsystem for Linux – with GCC.
Check out our post on Visual C++ for Linux Development for much more info about how to use Visual Studio to target Linux with GCC. If you are specifically interested in targeting WSL locally, check out Targeting WSL from Visual Studio.
Source: https://devblogs.microsoft.com/cppblog/use-any-c-compiler-with-visual-studio/
I'm from the future.
I keep (poking at) a C/C++ toolchain using Visual Code on Win/Lin/Mac and MinGW installed from Choclatey.
(This was done for my sanity - install GDB and GCC however you want)
I've run it with GCC and GDB with IntelliSense using MS's own weird JSON makefiles.
Someday, someone (you?) will write a Gradle or Python script to generate these; for now the examples online in the docs seem to work.
It seems to require three types of JSON thing;
a single IntelliSense configuration for the whole workspace
a Debugging Configuration entry for each binary you want to debug
these can invoke the build tasks
a Build Task per-artifact
I don't think that there's a "require" or "dependency" thingie-mah-bob; sorry

How do I set up CUDA v4.0 to work nicely with Visual Studio 2010? [duplicate]

Direct Question: How do I create a simple hello world CUDA project within visual studio 2010?
Background: I've written CUDA kernels. I'm intimately familiar with the .vcproj files from Visual Studio 2005 -- tweaked several by hand. In VS 2005, if I want to build a CUDA kernel, I add a custom build rule and then explicitly define the nvcc call to build the files.
I have migrated to Win 7, and VS 2010 because I really want to try out nSight. I have nSight 1.5 installed. But this is where I'm totally lost. If I proceed as before, nvcc reports that it only supports msvc 8.0 & 9.0. But the website clearly states that it supports VS 2010.
I read somewhere else that I need to have VS 2008 (msvc 9.0) also installed -- my word. Doing so now.
But I'm guessing that at least part of my problems stem from the homegrown custom build tool specifications. Several websites talk about adding a *.rules file to the build, but I've gathered that this is only applicable to VS 2008. Under "Build Customizations" I see CUDA 3.1 and 3.2, but when I add kernels to the project they aren't built. Another website proclaims that the key is three files: Cuda.props Cuda.xml Cuda.targets, but it doesn't say how or where to add these files -- or rather I'll gamble that I just don't understand the notes referenced in the website.
So does anyone know how to create a simple project in VS 2010 which builds a CUDA kernel -- using either the nSight 1.5 setup or the NvCudaRuntimeApi.v3.2.rules file which ships with the CUDA 3.2 RC?
Thanks in advance! I'd offer a bounty, but I only have 65 points total.
CUDA TOOLKIT 4.0 and later
The build customisations file (installed into the Program Files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations directory) "teaches" Visual Studio how to compile and link any .cu files in your project into your application. If you chose to skip installing the customisations, or if you installed VS2010 after CUDA, you can add them later by following the instructions in Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\extras\visual_studio_integration.
Create a new project using the standard MS wizards (e.g. an empty console project)
Implement your host (serial) code in .c or .cpp files
Add the NVIDIA build customisation (right click on the project, Build customizations, tick the relevant CUDA box)
See note 1 if using CUDA 4.0
Implement your wrappers and kernels in .cu files
If you added .cu files before the build customisations, then you'll need to set the type of the .cu files to CUDA C/C++ (right-click on the file, Properties, set Item Type)
Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> Input add cudart.lib to the Additional Dependencies)
Then just build your project and the .cu files will be compiled to .obj and added to the link automatically
Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall wrapper calls exit() if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!
NOTE
For CUDA 4.0 only you may need to apply this fix to the build customisations. This patch fixes the following message:
The result "" of evaluating the value "$(CudaBuildTasksPath)" of the "AssemblyFile" attribute in the element is not valid
This answer applies to CUDA 3.2, from 4.0 onwards CUDA supports the VC 10 compiler directly, see other answers for more information
You need either VS 2008 or the 6.1 Windows SDK installed. That's because NSight 1.5 RC or the CUDA 3.2 SDK use the VC 9 compiler under the hood. I've got this working successfully with 2008 installed and am told it should work with the SDK but haven't tried.
With NSight 1.5 and/or the CUDA 3.2 SDK you shouldn't need to muck with any custom build rules. I've been there and it's painful. With the latest builds all that goes away:
Create your VC++ project.
Add a .CU file to it.
Select the project file in the Solution Explorer.
Open Project | Build Customizations...
Check the "CUDA 3.2 (.targets,
.props)" customization.
Select a .CU file in your project and hit Alt-Enter to show it's properties.
Make sure it's Item Type is set to "CUDA C/C++"
It should just build. Let me know if this helps and if you run into problems as this is from memory.
The good news it getting CUDA working with VS 2010 just got much easier.
Ade
BTW: I'll update my blog post.
Another Good tutorial here:
http://www.stevenmarkford.com/installing-nvidia-cuda-with-visual-studio-2010/
if you get an error about '<' note this step (from a previous answer):
If you added .cu files before the build customisations, then you'll need to set the type of the .cu files to CUDA C/C++ (right-click on the file, Properties, set Item Type)
But if you follow their steps, it should work!

Resources