[CMake] Bash on ubuntu on windows as target

Gilles Khouzam gilles.khouzam at microsoft.com
Mon Aug 22 15:37:59 EDT 2016


I’ve looked more in depth at the issue, and while this doesn’t work yet, we’re looking to enable this in a future Windows Insider Flight for better windows/linux interop.

From: Gilles Khouzam
Sent: Monday, August 15, 2016 13:24
To: 'Tiago Macarios' <tiagomacarios at gmail.com>; csiga.biga at aol.com
Cc: CMake ML <cmake at cmake.org>
Subject: RE: [CMake] Bash on ubuntu on windows as target

That’s an interesting idea,

I’m not sure why cmd is failing to invoke bash properly, but I will try and figure it out.

Also, for addressing invoking bash.exe without copying it to SysWow64, you can reference it by C:\Windows\Sysnative\bash.exe from a 32-bit process. It still doesn’t make the target succeed, but at least it removes the need to copy the file around.

Thanks
~Gilles


From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Tiago Macarios
Sent: Thursday, August 11, 2016 10:12
To: csiga.biga at aol.com<mailto:csiga.biga at aol.com>
Cc: CMake ML <cmake at cmake.org<mailto:cmake at cmake.org>>
Subject: Re: [CMake] Bash on ubuntu on windows as target

Well what I was trying to do was to actually have a target inside the windows build that would trigger the linux build so to build both at the same time. imagine you have a VS project one of the "projects" would be the linux build. So as long as the build folder is different I could have both building in sync everytime. Get the idea?

If I just do a full build inside bash everything works great =)

On Wed, Aug 10, 2016 at 11:23 PM, <"Máté Ferenc Nagy-Egri via CMake <cmake at cmake"@public.kitware.com<mailto:%22Máté%20Ferenc%20Nagy-Egri%20via%20CMake%20%3ccmake at cmake%22 at public.kitware.com>> wrote:
+1 for the initiative. Wouldn’t it make more sense however to make it a CMAKE_SYSTEM_NAME? If I remember correctly that’s how MinGW works, and this should be something very similar.


Feladó: Tiago Macarios<mailto:tiagomacarios at gmail.com>
Elküldve: 2016. augusztus 11., csütörtök 1:51
Címzett: CMake ML<mailto:cmake at cmake.org>
Tárgy: [CMake] Bash on ubuntu on windows as target

Hi All,

Windows 10 anniversary edition comes with support to execute Linux binaries. I have been trying to use it with one of our projects, but I have been getting a weird error. Maybe someone can help me?

The target is pretty simple:

set(BASH "C:\\Windows\\System32\\bash.exe")
set(ARGS "--help")
add_custom_target(linux ${BASH} ${ARGS})

If I then build that project in visual studio (with some extra verbosity) I get:

Target "CustomBuild" in file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets" from project "C:\_Working\delegate\build\linux.vcxproj" (target "_BuildGenerateSourcesAction" depends on it):
Using "CustomBuild" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Build.CppTasks.Common.dll".
Task "CustomBuild"
  Write Tracking Logs:
           x64\Debug\linux\linux.tlog\custombuild.write.1.tlog
  Read Tracking Logs:
           x64\Debug\linux\linux.tlog\custombuild.read.1.tlog
  No output for C:\_WORKING\DELEGATE\BUILD\CMAKEFILES\3FA5525E877A7559336C7D412E1B43B0\LINUX.RULE|C:\_WORKING\DELEGATE\CMAKELISTS.TXT was found in the tracking log; source compilation required.
  C:\_Working\delegate\CMakeLists.txt will be compiled as it was not found in the tracking log.
  C:\_Working\delegate\build\CMakeFiles\3fa5525e877a7559336c7d412e1b43b0\linux.rule will be compiled as it was not found in the tracking log.
  setlocal
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -HC:/_Working/delegate -BC:/_Working/delegate/build --check-stamp-file C:\_Working\delegate\build\CMakeFiles\generate.stamp
  if %errorlevel% neq 0 goto :cmEnd
  :cmEnd
  endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
  :cmErrorLevel
  exit /b %1
  :cmDone
  if %errorlevel% neq 0 goto :VCEnd
  setlocal
  C:\Windows\System32\bash.exe --help
  if %errorlevel% neq 0 goto :cmEnd
  :cmEnd
  endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
  :cmErrorLevel
  exit /b %1
  :cmDone
  if %errorlevel% neq 0 goto :VCEnd
  Building Custom Rule C:/_Working/delegate/CMakeLists.txt
  CMake does not need to re-run because C:\_Working\delegate\build\CMakeFiles\generate.stamp is up-to-date.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code -1073740791.
Done executing task "CustomBuild" -- FAILED.
Done building target "CustomBuild" in project "linux.vcxproj" -- FAILED.


The command line seems correct. If I just copy it to the windows prompt it works fine:

C:\Users\tmc>  C:\Windows\System32\bash.exe --help
GNU bash, version 4.3.11(1)-release-(x86_64-pc-linux-gnu)
Usage:  /bin/bash [GNU long option] [option] ...
        /bin/bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --rcfile
        --restricted
        --verbose
        --version
Shell options:
        -ilrsD or -c command or -O shopt_option         (invocation only)
        -abefhkmnptuvxBCHP or -o option
Type `/bin/bash -c "help set"' for more information about shell options.
Type `/bin/bash -c help' for more information about shell builtin commands.
Use the `bashbug' command to report bugs.


I also tried to use it from the visual studio "external tools" and it seems to work. So I am not sure what is going on. Is there a way to debug custom_targets?

In case anyone tries the example above on a 64 bit machine: You will need to copy bash.exe from system32 to syswow64 since VS is 32 bits.

Tiago


--

Powered by www.kitware.com<http://www.kitware.com>

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160822/59d587ce/attachment-0001.html>


More information about the CMake mailing list