shim for gcc / clang or package based info which compiler is used #124

Open
opened 2022-05-22 14:10:12 +02:00 by RubenKelevra · 13 comments
Contributor

For more advanced flags to be used we need to provide a list for gcc and one for clang, as they use different flags.

I think this is solved for gentoo by providing an info which compiler is beeing used and thus will remove the unsupported flags.

We could do something similar by having two lists of optional flags for each compiler, so they would just get added depending on which compiler is stored in a variable for each package.

Another option is a shim which takes the place of the clang/gcc binary and adds the flags we want kinda dynamically. This wouldn't require us to keep track of the package's compilers.

I could write a bash shim for that, if you're interested in going this route @anonfunc

For more advanced flags to be used we need to provide a list for gcc and one for clang, as they use different flags. I think this is solved for gentoo by providing an info which compiler is beeing used and thus will remove the unsupported flags. We could do something similar by having two lists of optional flags for each compiler, so they would just get added depending on which compiler is stored in a variable for each package. Another option is a shim which takes the place of the clang/gcc binary and adds the flags we want kinda dynamically. This wouldn't require us to keep track of the package's compilers. I could write a bash shim for that, if you're interested in going this route @anonfunc
Owner

We could do something similar by having two lists of optional flags for each compiler, so they would just get added depending on which compiler is stored in a variable for each package.

As easy as this sounds, who/what does maintain the lists? ALHP can detect the compiler while building sure, but probably not before. Manual sounds like hell.

Another option is a shim which takes the place of the clang/gcc binary and adds the flags we want kinda dynamically. This wouldn't require us to keep track of the package's compilers.

I could write a bash shim for that, if you're interested in going this route @anonfunc

Writing the shim would probably be the easy part. How to integrate it into the build without some hacky packages applied with --overwrite is the question here. And ideally, ALHP should be able to modify the shim or the shim needs to somehow get the things it needs to do (versus a static shim). I though about using a socket bound into the chroot to communicate with the shim, but that sounds like overkill.

Give me some time, I'll think about it. Maybe something good pops up.

> We could do something similar by having two lists of optional flags for each compiler, so they would just get added depending on which compiler is stored in a variable for each package. > As easy as this sounds, who/what does maintain the lists? ALHP can detect the compiler while building sure, but probably not before. Manual sounds like hell. > Another option is a shim which takes the place of the clang/gcc binary and adds the flags we want kinda dynamically. This wouldn't require us to keep track of the package's compilers. > > I could write a bash shim for that, if you're interested in going this route @anonfunc Writing the shim would probably be the easy part. How to integrate it into the build without some hacky packages applied with `--overwrite` is the question here. And ideally, ALHP should be able to modify the shim or the shim needs to somehow get the things it needs to do (versus a static shim). I though about using a socket bound into the chroot to communicate with the shim, but that sounds like overkill. Give me some time, I'll think about it. Maybe something good pops up.
anonfunc added the
enhancement
label 2022-05-23 14:35:24 +02:00
Author
Contributor

We could do something similar by having two lists of optional flags for each compiler, so they would just get added depending on which compiler is stored in a variable for each package.

As easy as this sounds, who/what does maintain the lists? ALHP can detect the compiler while building sure, but probably not before. Manual sounds like hell.

Nah, that's rather simple, as the list is basiclly just part of this project: It's the flags AHLP like to set, like the ones TBD here.

I started writing the shim just as an experiment, I'll report back :)

Another option is a shim which takes the place of the clang/gcc binary and adds the flags we want kinda dynamically. This wouldn't require us to keep track of the package's compilers.

I could write a bash shim for that, if you're interested in going this route @anonfunc

Writing the shim would probably be the easy part. How to integrate it into the build without some hacky packages applied with --overwrite is the question here.
And ideally, ALHP should be able to modify the shim or the shim needs to somehow get the things it needs to do (versus a static shim). I though about using a socket bound into the chroot to communicate with the shim, but that sounds like overkill.

Sure, easy. Add a readonly mount to the chroot, like '/cool_shim' and add it in the the first position of the $PATH. Most build envirments will probably search in the path for the compiler and not assume a fixed path. The shim on the other hand will use a fixed path to the binary and thus call the real binary.

The shim doesn't need nothing, it's completly static like the utils.go right now with the replacements.

Give me some time, I'll think about it. Maybe something good pops up.

Sure :)

> > We could do something similar by having two lists of optional flags for each compiler, so they would just get added depending on which compiler is stored in a variable for each package. > > > > As easy as this sounds, who/what does maintain the lists? ALHP can detect the compiler while building sure, but probably not before. Manual sounds like hell. Nah, that's rather simple, as the list is basiclly just part of this project: It's the flags AHLP like to set, like the ones TBD [here](https://git.harting.dev/ALHP/ALHP.GO/pulls/117). I started writing the shim just as an experiment, I'll report back :) > > Another option is a shim which takes the place of the clang/gcc binary and adds the flags we want kinda dynamically. This wouldn't require us to keep track of the package's compilers. > > > > I could write a bash shim for that, if you're interested in going this route @anonfunc > > Writing the shim would probably be the easy part. How to integrate it into the build without some hacky packages applied with `--overwrite` is the question here. > And ideally, ALHP should be able to modify the shim or the shim needs to somehow get the things it needs to do (versus a static shim). I though about using a socket bound into the chroot to communicate with the shim, but that sounds like overkill. Sure, easy. Add a readonly mount to the chroot, like '/cool_shim' and add it in the the first position of the $PATH. Most build envirments will probably search in the path for the compiler and not assume a fixed path. The shim on the other hand will use a fixed path to the binary and thus call the real binary. The shim doesn't need nothing, it's completly static like the utils.go right now with the replacements. > Give me some time, I'll think about it. Maybe something good pops up. Sure :)
Owner

Nah, that's rather simple, as the list is basiclly just part of this project: It's the flags AHLP like to set, like the ones TBD here.

Oh seems like I misunderstood. I was assuming you wanted to maintain a list of package -> compiler. That would be insane work. Yea separate list for compiler are fine, ofc.

Sure, easy. Add a readonly mount to the chroot, like '/cool_shim' and add it in the the first position of the $PATH. Most build environments will probably search in the path for the compiler and not assume a fixed path. The shim on the other hand will use a fixed path to the binary and thus call the real binary.

Yea, I totally forgot about using the $PATH. That could probably work for almost all projects.

The shim doesn't need nothing, it's completely static like the utils.go right now with the replacements.

Yea, about that. I want to rework that section, since that was a stopgap-measure to begin with. I want to have them separate in a config commited into git, so we can track flag changes more easily. I'll do that as soon as I find time.
So, in that regard, having a dynamic shim would spare us of maintaining two files where flags are set.

> Nah, that's rather simple, as the list is basiclly just part of this project: It's the flags AHLP like to set, like the ones TBD [here](https://git.harting.dev/ALHP/ALHP.GO/pulls/117). > Oh seems like I misunderstood. I was assuming you wanted to maintain a list of package -> compiler. That would be insane work. Yea separate list for compiler are fine, ofc. > Sure, easy. Add a readonly mount to the chroot, like '/cool_shim' and add it in the the first position of the $PATH. Most build environments will probably search in the path for the compiler and not assume a fixed path. The shim on the other hand will use a fixed path to the binary and thus call the real binary. Yea, I totally forgot about using the $PATH. That could probably work for almost all projects. > The shim doesn't need nothing, it's completely static like the utils.go right now with the replacements. Yea, about that. I want to rework that section, since that was a stopgap-measure to begin with. I want to have them separate in a config commited into git, so we can track flag changes more easily. I'll do that as soon as I find time. So, in that regard, having a dynamic shim would spare us of maintaining two files where flags are set.
Author
Contributor

I think the shim should be static and just be fed by enviromental variables, like the regular CPP flags are as well.

So something like

CPP_FLAGS_GCC="-list -of -awsome -flags"
CPP_FLAGS_CLANG="-list -of -other -flags"

and the shim will just take the regular CPP flags, add the GCC/CLANG flags, depending on the compiler called, and "clean" the flags given by the buildroot from everything we don't want to.

I'm somewhere around interation two, as I wasn't happy with the first one I haven't pushed it. ;)

So we can just have a file which get sourced by the shim in the git. So the shim is static and won't be modified, and we can supply custom flags if we have to - for example for the multilib builds.

I think the shim should be static and just be fed by enviromental variables, like the regular CPP flags are as well. So something like CPP_FLAGS_GCC="-list -of -awsome -flags" CPP_FLAGS_CLANG="-list -of -other -flags" and the shim will just take the regular CPP flags, add the GCC/CLANG flags, depending on the compiler called, and "clean" the flags given by the buildroot from everything we don't want to. I'm somewhere around interation two, as I wasn't happy with the first one I haven't pushed it. ;) So we can just have a file which get sourced by the shim in the git. So the shim is static and won't be modified, and we can supply custom flags if we have to - for example for the multilib builds.
Owner

That could also work, sure. Now we just need to figure out how to 'install' the shim into the chroot copy before building.

That could also work, sure. Now we just need to figure out how to 'install' the shim into the chroot copy before building.
Owner

I just finished porting the compiler flags to a separate config file. Adding more build-env-vars should be cake now.

I just finished porting the compiler flags to a separate config file. Adding more build-env-vars should be cake now.
anonfunc added a new dependency 2022-08-05 19:09:57 +02:00
anonfunc removed a dependency 2023-03-14 01:50:03 +01:00
Author
Contributor

Somehow this dropped at the back of my head, sorry for that.

So we still need this for the project, correct?

Somehow this dropped at the back of my head, sorry for that. So we still need this for the project, correct?
Author
Contributor

That could also work, sure. Now we just need to figure out how to 'install' the shim into the chroot copy before building.

I guess the best solution would be, to create a package for the shim and add it to the repository.

This way the package could be just added as an additional package to be installed in the chroot before the build starts. The package would then prepare the environment while beeing installed to use the shims.

> That could also work, sure. Now we just need to figure out how to 'install' the shim into the chroot copy before building. I guess the best solution would be, to create a package for the shim and add it to the repository. This way the package could be just added as an additional package to be installed in the chroot before the build starts. The package would then prepare the environment while beeing installed to use the shims.
Owner

Somehow this dropped at the back of my head, sorry for that.

So we still need this for the project, correct?

If we want to have things like #134 I think it is still needed yes.

That could also work, sure. Now we just need to figure out how to 'install' the shim into the chroot copy before building.

I guess the best solution would be, to create a package for the shim and add it to the repository.

This way the package could be just added as an additional package to be installed in the chroot before the build starts. The package would then prepare the environment while beeing installed to use the shims.

Yep, that was my understanding too.

> Somehow this dropped at the back of my head, sorry for that. > > So we still need this for the project, correct? If we want to have things like #134 I think it is still needed yes. > > That could also work, sure. Now we just need to figure out how to 'install' the shim into the chroot copy before building. > > I guess the best solution would be, to create a package for the shim and add it to the repository. > > This way the package could be just added as an additional package to be installed in the chroot before the build starts. The package would then prepare the environment while beeing installed to use the shims. Yep, that was my understanding too.
Author
Contributor

I guess reading the flags.yaml makes the most sense, to specify what the shim should do, right?

If I add the required fields in the process, would your software ignore them?

I guess reading the flags.yaml makes the most sense, to specify what the shim should do, right? If I add the required fields in the process, would your software ignore them?
Owner

You can add completely new vars to the flags.yaml and they get exported in their respective makepkg.conf. Shim could use these to decide what to do I guess? Or is there something more sophisticated needed?

You can add completely new vars to the flags.yaml and they get exported in their respective makepkg.conf. Shim could use these to decide what to do I guess? Or is there something more sophisticated needed?
Author
Contributor

Ah, okay!

I thought about putting the current version of the flags.yaml into the package and read the yaml file with the shim. But true, makes more sense to read the makepkg.conf for flags.

What's needed is a general definition of what each flag should do and then for the build itself which flags should be used.

So like the common.cflags defines currently that '-O2' should be replaced with '-O3'.

So the shim should need the flags.yaml (or a similar file) available inside the chroot. The question is: Do we want to package the flags.yaml into the package of the shim, or should the flags.yaml be copied while creating the chroot into the chroot?

Ah, okay! I thought about putting the current version of the flags.yaml into the package and read the yaml file with the shim. But true, makes more sense to read the makepkg.conf for flags. What's needed is a general definition of what each flag should do and then for the build itself which flags should be used. So like the common.cflags defines currently that '-O2' should be replaced with '-O3'. So the shim should need the flags.yaml (or a similar file) available inside the chroot. The question is: Do we want to package the flags.yaml into the package of the shim, or should the flags.yaml be copied while creating the chroot into the chroot?
Author
Contributor

Splitting the definition and the active flags allows overriding the flags per package. So if a package does not build with option X, we can just disable it by not setting it in the makepkg.conf.

Splitting the definition and the active flags allows overriding the flags per package. So if a package does not build with option X, we can just disable it by not setting it in the makepkg.conf.
Sign in to join this conversation.
No description provided.