-
Notifications
You must be signed in to change notification settings - Fork 259
feat: add MSBuild rule to build MSBuild projects. #1443
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_test") | ||
| load("@rules_foreign_cc//foreign_cc:defs.bzl", "msbuild") | ||
|
|
||
| msbuild( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when I build this on my local I see but |
||
| name = "mylib", | ||
| lib_source = "//msbuild_simple/code:srcs", | ||
| out_lib_dir = "", | ||
| out_static_libs = ["mylib.lib"], | ||
| sln_file = "mysolution.sln", | ||
| target_compatible_with = ["@platforms//os:windows"], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't it only ever be this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is true for MSVC msbuild, which is the one we adding. However, rule() doesn't allow you to set default
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems crazy to have to set this every time you use the rule. Could we use a macro wrapper? |
||
| targets = ["Build"], | ||
| ) | ||
|
|
||
| cc_test( | ||
| name = "mylib_test", | ||
| srcs = ["test_mylib.cpp"], | ||
| target_compatible_with = ["@platforms//os:windows"], | ||
| deps = [":mylib"], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| filegroup( | ||
| name = "srcs", | ||
| srcs = [ | ||
| "mylib.cpp", | ||
| "mylib.h", | ||
| "mylib.vcxproj", | ||
| "mysolution.sln", | ||
| ], | ||
| visibility = ["//msbuild_simple:__subpackages__"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #include "mylib.h" | ||
|
|
||
| std::string hello_mylib(void) { return "Hello from MyLib!"; } | ||
|
|
||
| int add_numbers(int a, int b) { return a + b; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #ifndef MYLIB_H_ | ||
| #define MYLIB_H_ (1) | ||
|
|
||
| #include <string> | ||
|
|
||
| std::string hello_mylib(void); | ||
| int add_numbers(int a, int b); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project DefaultTargets="Build" ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup Label="ProjectConfigurations"> | ||
| <ProjectConfiguration Include="Debug|Win32"> | ||
| <Configuration>Debug</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| <ProjectConfiguration Include="Release|Win32"> | ||
| <Configuration>Release</Configuration> | ||
| <Platform>Win32</Platform> | ||
| </ProjectConfiguration> | ||
| <ProjectConfiguration Include="Debug|x64"> | ||
| <Configuration>Debug</Configuration> | ||
| <Platform>x64</Platform> | ||
| </ProjectConfiguration> | ||
| <ProjectConfiguration Include="Release|x64"> | ||
| <Configuration>Release</Configuration> | ||
| <Platform>x64</Platform> | ||
| </ProjectConfiguration> | ||
| </ItemGroup> | ||
| <PropertyGroup Label="Globals"> | ||
| <VCProjectVersion>17.0</VCProjectVersion> | ||
| <ProjectGuid>{B2C3D4E5-F6A7-8901-BCDE-F01234567890}</ProjectGuid> | ||
| <Keyword>Win32Proj</Keyword> | ||
| <RootNamespace>mylib</RootNamespace> | ||
| <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
| <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| <UseDebugLibraries>true</UseDebugLibraries> | ||
| <PlatformToolset>v143</PlatformToolset> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
| <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| <UseDebugLibraries>false</UseDebugLibraries> | ||
| <PlatformToolset>v143</PlatformToolset> | ||
| <WholeProgramOptimization>true</WholeProgramOptimization> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
| <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| <UseDebugLibraries>true</UseDebugLibraries> | ||
| <PlatformToolset>v143</PlatformToolset> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
| <ConfigurationType>StaticLibrary</ConfigurationType> | ||
| <UseDebugLibraries>false</UseDebugLibraries> | ||
| <PlatformToolset>v143</PlatformToolset> | ||
| <WholeProgramOptimization>true</WholeProgramOptimization> | ||
| <CharacterSet>Unicode</CharacterSet> | ||
| </PropertyGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
| <ImportGroup Label="ExtensionSettings"> | ||
| </ImportGroup> | ||
| <ImportGroup Label="Shared"> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
| </ImportGroup> | ||
| <PropertyGroup Label="UserMacros" /> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir> | ||
| <TargetName>mylib</TargetName> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir> | ||
| <TargetName>mylib</TargetName> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
| <IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir> | ||
| <TargetName>mylib</TargetName> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
| <IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir> | ||
| <TargetName>mylib</TargetName> | ||
| </PropertyGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
| <ClCompile> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <SDLCheck>true</SDLCheck> | ||
| <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| <ConformanceMode>true</ConformanceMode> | ||
| <PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
| </ClCompile> | ||
| <Lib> | ||
| <AdditionalDependencies></AdditionalDependencies> | ||
| </Lib> | ||
| </ItemDefinitionGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
| <ClCompile> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <FunctionLevelLinking>true</FunctionLevelLinking> | ||
| <IntrinsicFunctions>true</IntrinsicFunctions> | ||
| <SDLCheck>true</SDLCheck> | ||
| <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| <ConformanceMode>true</ConformanceMode> | ||
| <PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
| </ClCompile> | ||
| <Lib> | ||
| <AdditionalDependencies></AdditionalDependencies> | ||
| </Lib> | ||
| </ItemDefinitionGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
| <ClCompile> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <SDLCheck>true</SDLCheck> | ||
| <PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| <ConformanceMode>true</ConformanceMode> | ||
| <PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
| </ClCompile> | ||
| <Lib> | ||
| <AdditionalDependencies></AdditionalDependencies> | ||
| </Lib> | ||
| </ItemDefinitionGroup> | ||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
| <ClCompile> | ||
| <WarningLevel>Level3</WarningLevel> | ||
| <FunctionLevelLinking>true</FunctionLevelLinking> | ||
| <IntrinsicFunctions>true</IntrinsicFunctions> | ||
| <SDLCheck>true</SDLCheck> | ||
| <PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
| <ConformanceMode>true</ConformanceMode> | ||
| <PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
| </ClCompile> | ||
| <Lib> | ||
| <AdditionalDependencies></AdditionalDependencies> | ||
| </Lib> | ||
| </ItemDefinitionGroup> | ||
| <ItemGroup> | ||
| <ClInclude Include="mylib.h" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ClCompile Include="mylib.cpp" /> | ||
| </ItemGroup> | ||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
| <ImportGroup Label="ExtensionTargets"> | ||
| </ImportGroup> | ||
| <Target Name="CopyHeaders" AfterTargets="Build"> | ||
| <MakeDir Directories="$(OutDir)include" /> | ||
| <Copy SourceFiles="mylib.h" DestinationFolder="$(OutDir)include" /> | ||
| </Target> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.0.31903.59 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mylib", "mylib.vcxproj", "{B2C3D4E5-F6A7-8901-BCDE-F01234567890}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|x64 = Debug|x64 | ||
| Debug|Win32 = Debug|Win32 | ||
| Release|x64 = Release|x64 | ||
| Release|Win32 = Release|Win32 | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Debug|x64.ActiveCfg = Debug|x64 | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Debug|x64.Build.0 = Debug|x64 | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Debug|Win32.Build.0 = Debug|Win32 | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Release|x64.ActiveCfg = Release|x64 | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Release|x64.Build.0 = Release|x64 | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Release|Win32.ActiveCfg = Release|Win32 | ||
| {B2C3D4E5-F6A7-8901-BCDE-F01234567890}.Release|Win32.Build.0 = Release|Win32 | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {B5C6D7E8-F9A0-1234-5678-90ABCDEF0123} <!-- Another unique GUID --> | ||
| EndGlobalSection | ||
| EndGlobal |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include <iostream> | ||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| #include "mylib.h" | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| // Test the hello_mylib function | ||
| std::string result = hello_mylib(); | ||
| if (result != "Hello from MyLib!") { | ||
| throw std::runtime_error("Wrong result from hello_mylib: " + result); | ||
| } | ||
|
|
||
| // Test the add_numbers function | ||
| int math_result = add_numbers(5, 3); | ||
| if (math_result != 8) { | ||
| throw std::runtime_error("Wrong math_result from add_numbers: " + | ||
| std::to_string(math_result)); | ||
| } | ||
|
|
||
| std::cout << "Everything's fine!"; | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you provide a link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to pinpoint an issue or PR. However, using a later version of bazel solves this problem.
The error was that the target under //msbuild_simple/... what had a target_compatible_with for windows was still being executed on linux.