On Tue, Feb 14, 2023 at 09:04:47AM +0100, Stéphane Glondu wrote:
> Hi,
>
> Le 08/02/2023 à 10:58, Emilio Pozuelo Monfort a écrit :
> > What is the purpose of having the build flags in a file in the .deb?
>
> ocamlc can act as a driver for the C compiler, to compile C stubs with the
> "right" flags. These flags are basically the CFLAGS ocaml was compiled with,
> plus some additional OCaml-specific flags (like -fwrapv).
>
> But I wonder now: shouldn't the CFLAGS part be queried from the environment
> at use time, rather than at OCaml compilation time? This setting of a non-C
> compiler calling a C compiler must happen often... I don't know what's the
> practice elsewhere.
I can't speak of many other systems, but at least with Perl's XS
(the standard way to write Perl modules parts of which are compiled C code)
and two of the ways this can be done in Python, it is the same:
the C compiler's name and flags are recorded at the time the "wrapper" is
built, so that they can be used later. At least IMHO, this has two main
benefits:
- people (or programs) that want to build a Perl/Python/OCaml/whatever
module do not have to know anything about C compilers, flags, optimization,
language-specific libraries[1] , etc. The consumers tell their own language
ecosystem "look, I need to compile something that has C parts in it, go do
something about it", and the wrapper for the C compiler knows exactly what
to do
- everything is compiled using the same compiler[2], the same optimization
flags, the same libraries, etc., so one module that has C parts in it can
call the C functions from another module directly with no fear of any kind
of calling convention mismatch or whatever
- to reinforce the previous point: everything is compiled using the same
recorded settings *no matter what* environment variables or paths there
may be in the current user's execution environment, so that nothing will
break if somebody has the wrong environment variable defined when they
build a module a couple of months later. Of course, there are some cases
when some such systems allow additional flags to be specified or
overridden, but IMHO it is good that this must be done explicitly and is
most often not done at all, so that everything is built in the same way
and it can all work together
[1] At least with Perl and Python, C code very often invokes functions from
the Perl/Python standard library, the C code does not know how to create
a list or how to invoke a Perl/Python function, so it has to use
the language's internal libraries for that.
[2] Well, okay, that's not strictly true, since the binary called "gcc" now
may not be the same that was provided by the C compiler package a couple
of months ago, but it ought to be guaranteed to generate compatible code
and object files.
So yeah, I'd say that "record the C compiler flags at build time" is
pretty much standard practice for such interface providers.
G'luck,
Peter
--
Peter Pentchev roam@ringlet.net roam@debian.org pp@storpool.com
PGP key: http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13
Attachment:
signature.asc
Description: PGP signature