ninja winepath dependences

43 views
Skip to first unread message

Michael Nazzareno Trimarchi

unread,
Mar 10, 2023, 6:04:37 AM3/10/23
to ninja-build
Hi all

I'm integrated a compiler using wine and I'm using cmake to compile. Now I'm trying to figure out how the dependences are calculate because the path that are in the .ninja_deps
are windows but the machine is linux. The path are created by compiler and ninja I think it uses in filesystem mapping. Is there a way to have some kind of rule that make it working?

Michael

Ben Boeckel

unread,
Mar 10, 2023, 2:21:09 PM3/10/23
to Michael Nazzareno Trimarchi, ninja-build
I don't think so. I think you're best off running a Windows-built
`ninja` binary via `wine` that understands the paths as the compiler
does.

--Ben

Ben Boeckel

unread,
Mar 10, 2023, 6:25:49 PM3/10/23
to Michael Nazzareno Trimarchi, ninja-build
On Sat, Mar 11, 2023 at 00:12:52 +0100, Michael Nazzareno Trimarchi wrote:
> Already tried it and is almost viable. Some problem because I should
> have even cmake for windows but then
> better to move on windows :D

Yes, you should have a Windows-targeting CMake as well as "native" paths
will not be understood otherwise.

--Ben

Michael Nazzareno Trimarchi

unread,
Mar 11, 2023, 4:55:13 AM3/11/23
to Ben Boeckel, ninja-build
Hi
Already tried it and is almost viable. Some problem because I should
have even cmake for windows but then
better to move on windows :D

Michael

> --Ben



--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mic...@amarulasolutions.com
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
in...@amarulasolutions.com
www.amarulasolutions.com

David Turner

unread,
Mar 11, 2023, 4:55:26 AM3/11/23
to Michael Nazzareno Trimarchi, ninja-build


On Fri, Mar 10, 2023 at 3:42 PM Michael Nazzareno Trimarchi <mic...@amarulasolutions.com> wrote:
Hi David

On Fri, Mar 10, 2023 at 3:36 PM David Turner <di...@google.com> wrote:
> Look for `deps = msvc` and `msvc_deps_prefix` in the Ninja documentation. However, these probably cannot deal with your filesystem mapping.
> The simplest thing to do would be to use a wrapper script that rewrites the depfiles generated by your compiler, and ensure Ninja calls it. I don't know enough CMake to tell you how to do that though.
>

Is there any  hook where I can connect my python script in ninja when
it wants to calculate them?

There is no hook. Ninja just invokes the compiler with a flag that tells it where to write the depfile, once this has completed, Ninja parses that depfile to record its content. This parser only supports the GCC and MSVC formats, but does not do any extra processing on the file paths.
You want the depfile generated by the Ninja command to be in a format that is valid to Ninja. Hence try to use a compiler wrapper script that detects the depfile location on the command-line, runs the real command, and if it succeeds, rewrites the depfile content to map files accordingly.

Michael

>>
>> Michael
>>
>> --
>> You received this message because you are subscribed to the Google Groups "ninja-build" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to ninja-build...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/ninja-build/1b0039bf-f985-4080-b9ef-98b50be8c151n%40googlegroups.com.

Michael Nazzareno Trimarchi

unread,
Mar 11, 2023, 4:55:34 AM3/11/23
to David Turner, ninja-build
Hi David

On Fri, Mar 10, 2023 at 3:36 PM David Turner <di...@google.com> wrote:
>
>
>
> On Fri, Mar 10, 2023 at 12:04 PM Michael Nazzareno Trimarchi <mic...@amarulasolutions.com> wrote:
>>
> Look for `deps = msvc` and `msvc_deps_prefix` in the Ninja documentation. However, these probably cannot deal with your filesystem mapping.
> The simplest thing to do would be to use a wrapper script that rewrites the depfiles generated by your compiler, and ensure Ninja calls it. I don't know enough CMake to tell you how to do that though.
>

Is there any hook where I can connect my python script in ninja when
it wants to calculate them?

David Turner

unread,
Mar 11, 2023, 4:55:41 AM3/11/23
to Michael Nazzareno Trimarchi, ninja-build
On Fri, Mar 10, 2023 at 12:04 PM Michael Nazzareno Trimarchi <mic...@amarulasolutions.com> wrote:
Look for `deps = msvc` and `msvc_deps_prefix` in the Ninja documentation. However, these probably cannot deal with your filesystem mapping.
The simplest thing to do would be to use a wrapper script that rewrites the depfiles generated by your compiler, and ensure Ninja calls it. I don't know enough CMake to tell you how to do that though.
 
Michael

Michael Nazzareno Trimarchi

unread,
Mar 11, 2023, 4:55:51 AM3/11/23
to ninja-build
Hi

I now have this script in python to recalculate .d but cmake and ninja
update .ninja_dep after each compilation.
Do we have a smart way to call the script just after dep created by compiler?

Michael

On Fri, Mar 10, 2023 at 12:04 PM Michael Nazzareno Trimarchi
<mic...@amarulasolutions.com> wrote:
>
> --
> You received this message because you are subscribed to the Google Groups "ninja-build" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ninja-build...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ninja-build/1b0039bf-f985-4080-b9ef-98b50be8c151n%40googlegroups.com.



wine_converter.py

Ben Boeckel

unread,
Mar 11, 2023, 2:43:16 PM3/11/23
to Michael Nazzareno Trimarchi, ninja-build
On Sat, Mar 11, 2023 at 19:15:27 +0100, Michael Nazzareno Trimarchi wrote:
> Do you know a way to be called by cmake by the end of each compilation
> step or if I wrap
> the CC CXX compiler, is there an easy way to understand what object
> file is going to generate?
>
> CC=cc-wrap
>
> cc-wrap
> call cc ... -o <objfile>
> wine_converted objfile.d

There is `CMAKE_C_COMPILER_LAUNCHER` for this (and `CMAKE_CXX_…` as
well).

--Ben

Ben Boeckel

unread,
Mar 11, 2023, 9:01:13 PM3/11/23
to Michael Nazzareno Trimarchi, ninja-build
On Sat, Mar 11, 2023 at 23:46:08 +0100, Michael Nazzareno Trimarchi wrote:
> +#!/bin/bash
> +
> +dep="${@: -1}".d
> +"${@}"

You really want to fail on the compiler failing. (`set -e` should help).

> +exec ./wine_converter.py ${dep}

--Ben

Michael Nazzareno Trimarchi

unread,
Mar 12, 2023, 7:11:33 AM3/12/23
to Ben Boeckel, ninja-build
Hi Ben

On Sun, Mar 12, 2023 at 8:53 AM Michael Nazzareno Trimarchi
<mic...@amarulasolutions.com> wrote:
>
> Hi Ben
> Yes clear, but it was just a quick mockup
>
> Thank you

Do you think that it makes sense to push an example of it in a public github?

Michael

Michael Nazzareno Trimarchi

unread,
Mar 12, 2023, 7:11:38 AM3/12/23
to Ben Boeckel, ninja-build
Hi Ben

On Sun, Mar 12, 2023 at 3:01 AM Ben Boeckel <ben.b...@kitware.com> wrote:
>

Michael Nazzareno Trimarchi

unread,
Mar 12, 2023, 7:11:44 AM3/12/23
to Ben Boeckel, ninja-build
On Sat, Mar 11, 2023 at 11:04 PM Michael Nazzareno Trimarchi
<mic...@amarulasolutions.com> wrote:
>
> Hi Ben
> Need to optimize it but this work
>
> +set(compiler_launcher "${CMAKE_CURRENT_LIST_DIR}/compile-wrapper.sh")
> +set(CMAKE_C_COMPILER_LAUNCHER "${compiler_launcher}")
> +set(CMAKE_CXX_COMPILER_LAUNCHER "${compiler_launcher}")
> +
> +configure_file(wine_converter.py wine_converter.py COPYONLY)
>
> file(GLOB_RECURSE SOURCES
> "Master/Sources/Device/*.*"
> diff --git a/compile-wrapper.sh b/compile-wrapper.sh
> new file mode 100755
> index 0000000..8145741
> --- /dev/null
> +++ b/compile-wrapper.sh
> @@ -0,0 +1,7 @@
> +#!/bin/bash
> +
> +dep="${@: -1}".d
> +args=()
> +args+=("$@")
> +"${args[@]}"
> +exec ./wine_converter.py ${dep}

+#!/bin/bash
+
+dep="${@: -1}".d
+"${@}"

+exec ./wine_converter.py ${dep}

>
> Thank you
> Michael

Michael Nazzareno Trimarchi

unread,
Mar 12, 2023, 7:11:49 AM3/12/23
to Ben Boeckel, ninja-build
Hi Ben
Need to optimize it but this work

+set(compiler_launcher "${CMAKE_CURRENT_LIST_DIR}/compile-wrapper.sh")
+set(CMAKE_C_COMPILER_LAUNCHER "${compiler_launcher}")
+set(CMAKE_CXX_COMPILER_LAUNCHER "${compiler_launcher}")
+
+configure_file(wine_converter.py wine_converter.py COPYONLY)

file(GLOB_RECURSE SOURCES
"Master/Sources/Device/*.*"
diff --git a/compile-wrapper.sh b/compile-wrapper.sh
new file mode 100755
index 0000000..8145741
--- /dev/null
+++ b/compile-wrapper.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+dep="${@: -1}".d
+args=()
+args+=("$@")
+"${args[@]}"
+exec ./wine_converter.py ${dep}

Thank you
Michael

Michael Nazzareno Trimarchi

unread,
Mar 12, 2023, 7:11:54 AM3/12/23
to Ben Boeckel, ninja-build
Hi Ben
Do you know a way to be called by cmake by the end of each compilation
step or if I wrap
the CC CXX compiler, is there an easy way to understand what object
file is going to generate?

CC=cc-wrap

cc-wrap
call cc ... -o <objfile>
wine_converted objfile.d

Michael

Ben Boeckel

unread,
Mar 12, 2023, 1:26:27 PM3/12/23
to Michael Nazzareno Trimarchi, ninja-build
On Sun, Mar 12, 2023 at 09:53:42 +0100, Michael Nazzareno Trimarchi wrote:
> Do you think that it makes sense to push an example of it in a public github?

Sounds fine to me. Though I think the more interesting question is "what
refers to this as an example?". It's certainly useful to refer to in
case it ever comes up on discourse.cmake.org, stackoverflow, or other
support channels.

--Ben

Michael Nazzareno Trimarchi

unread,
Mar 12, 2023, 9:16:20 PM3/12/23
to Ben Boeckel, ninja-build
Hi
My use case is to configure the IAR toolchain using wine. There are a
lot of developers
that like to work under linux and their company buys the license for windows.

You can find more here:
https://github.com/IARSystems/cmake-tutorial/pull/24

After that I solve the fact the gdb path using
--use_unix_directory_separators --use_paths_as_written
in compiler option and the the wrapper to avoid continue rebuild when
I change just one file

I need to admit that experience with cmake / ninja was really nice
(less with wine and winepath)

Michael
Reply all
Reply to author
Forward
0 new messages