Skip to content

Reorganise how MKEXE_VIA_CC is built to make it correct for MSVC#12909

Merged
nojb merged 1 commit into
ocaml:trunkfrom
shym:cl-link
Jan 17, 2024
Merged

Reorganise how MKEXE_VIA_CC is built to make it correct for MSVC#12909
nojb merged 1 commit into
ocaml:trunkfrom
shym:cl-link

Conversation

@shym
Copy link
Copy Markdown
Contributor

@shym shym commented Jan 17, 2024

This PR is joint work with @dra27. It brings changes that are required to restore the MSVC port and should make no difference to other ports.

MSVC cl command-line option /link allows to pass options to the linker using the following scheme:

cl [cl arguments...] /link [link arguments...]

In order to accomodate all our supported C compilers, this requires a reshuffling of how the MKEXE_VIA_CC command line is built so that $oc_exe_ldflags are indeed inserted after the /link for cl. This commit also ensures that /link ($mkexe_via_cc_ldflags_prefix) is inserted exactly once on the cl command line (rather than once per argument, which is how flexlink expects these arguments). Finally, this commit moves the usage of mkexe_via_cc_extra_cmd (which is used only for the MSVC toolchain, to inject the manifest in the executable) to the MKEXE_VIA_CC variable instead of hiding it into mkexe_via_cc_ldflags where it doesn't belong.

For non-MSVC ports, this commit:

  • removes the $(OC_EXE_LDFLAGS) Makefile variable as it is no longer used,
  • reorders the ${oc_exe_ldflags} after the $(CFLAGS),
    all which are hopefully innocuous enough.

Copy link
Copy Markdown
Contributor

@nojb nojb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nojb
Copy link
Copy Markdown
Contributor

nojb commented Jan 17, 2024

A changes entry would be nice (in the "internal" category). Thanks!

@shym
Copy link
Copy Markdown
Contributor Author

shym commented Jan 17, 2024

I added the Changes entry in the "Internal/Compiler-libs" section. Maybe it would fit better in the "Build system" section?

@nojb
Copy link
Copy Markdown
Contributor

nojb commented Jan 17, 2024

I added the Changes entry in the "Internal/Compiler-libs" section. Maybe it would fit better in the "Build system" section?

Yes, sorry, indeed.

MSVC cl command-line option `/link` allows to pass options to the linker
using the following scheme:
  `cl [cl arguments...] /link [link arguments...]`

In order to accomodate all our supported C compilers, this requires a
reshuffling of how the MKEXE_VIA_CC command line is built so that
`$oc_exe_ldflags` are indeed inserted after the `/link` for cl.
This commit also ensures that `/link` (`$mkexe_via_cc_ldflags_prefix`)
is inserted exactly once on the cl command line (rather than once per
argument, which is how flexlink expects these arguments).
Finally, this commit moves the usage of `mkexe_via_cc_extra_cmd` (which
is used only for the MSVC toolchain, to inject the manifest in the
executable) to the MKEXE_VIA_CC variable instead of hiding it into
`mkexe_via_cc_ldflags` where it doesn't belong.

For non-MSVC ports, this commit:
- removes the `$(OC_EXE_LDFLAGS)` Makefile variable as it is no longer
  used,
- and reorders the `${oc_exe_ldflags}` after the `$(CFLAGS)`.

Co-authored-by: Samuel Hym <samuel.hym@rustyne.lautre.net>
@nojb nojb merged commit f3f3a9c into ocaml:trunk Jan 17, 2024
@nojb
Copy link
Copy Markdown
Contributor

nojb commented Jan 17, 2024

Thanks!

@shym shym deleted the cl-link branch January 18, 2024 11:16
dra27 added a commit to dra27/ocaml that referenced this pull request Feb 1, 2024
…ml#12909)

MSVC cl command-line option `/link` allows to pass options to the linker
using the following scheme:
  `cl [cl arguments...] /link [link arguments...]`

In order to accomodate all our supported C compilers, this requires a
reshuffling of how the MKEXE_VIA_CC command line is built so that
`$oc_exe_ldflags` are indeed inserted after the `/link` for cl.
This commit also ensures that `/link` (`$mkexe_via_cc_ldflags_prefix`)
is inserted exactly once on the cl command line (rather than once per
argument, which is how flexlink expects these arguments).
Finally, this commit moves the usage of `mkexe_via_cc_extra_cmd` (which
is used only for the MSVC toolchain, to inject the manifest in the
executable) to the MKEXE_VIA_CC variable instead of hiding it into
`mkexe_via_cc_ldflags` where it doesn't belong.

For non-MSVC ports, this commit:
- removes the `$(OC_EXE_LDFLAGS)` Makefile variable as it is no longer
  used,
- and reorders the `${oc_exe_ldflags}` after the `$(CFLAGS)`.

Co-authored-by: David Allsopp <david.allsopp@metastack.com>
(cherry picked from commit f3f3a9c)
dra27 added a commit to dra27/ocaml that referenced this pull request Feb 1, 2024
…ml#12909)

MSVC cl command-line option `/link` allows to pass options to the linker
using the following scheme:
  `cl [cl arguments...] /link [link arguments...]`

In order to accomodate all our supported C compilers, this requires a
reshuffling of how the MKEXE_VIA_CC command line is built so that
`$oc_exe_ldflags` are indeed inserted after the `/link` for cl.
This commit also ensures that `/link` (`$mkexe_via_cc_ldflags_prefix`)
is inserted exactly once on the cl command line (rather than once per
argument, which is how flexlink expects these arguments).
Finally, this commit moves the usage of `mkexe_via_cc_extra_cmd` (which
is used only for the MSVC toolchain, to inject the manifest in the
executable) to the MKEXE_VIA_CC variable instead of hiding it into
`mkexe_via_cc_ldflags` where it doesn't belong.

For non-MSVC ports, this commit:
- removes the `$(OC_EXE_LDFLAGS)` Makefile variable as it is no longer
  used,
- and reorders the `${oc_exe_ldflags}` after the `$(CFLAGS)`.

Co-authored-by: David Allsopp <david.allsopp@metastack.com>
(cherry picked from commit f3f3a9c)
@dra27 dra27 mentioned this pull request Feb 1, 2024
2 tasks
dra27 added a commit to dra27/ocaml that referenced this pull request Feb 13, 2024
…ml#12909)

MSVC cl command-line option `/link` allows to pass options to the linker
using the following scheme:
  `cl [cl arguments...] /link [link arguments...]`

In order to accomodate all our supported C compilers, this requires a
reshuffling of how the MKEXE_VIA_CC command line is built so that
`$oc_exe_ldflags` are indeed inserted after the `/link` for cl.
This commit also ensures that `/link` (`$mkexe_via_cc_ldflags_prefix`)
is inserted exactly once on the cl command line (rather than once per
argument, which is how flexlink expects these arguments).
Finally, this commit moves the usage of `mkexe_via_cc_extra_cmd` (which
is used only for the MSVC toolchain, to inject the manifest in the
executable) to the MKEXE_VIA_CC variable instead of hiding it into
`mkexe_via_cc_ldflags` where it doesn't belong.

For non-MSVC ports, this commit:
- removes the `$(OC_EXE_LDFLAGS)` Makefile variable as it is no longer
  used,
- and reorders the `${oc_exe_ldflags}` after the `$(CFLAGS)`.

Co-authored-by: David Allsopp <david.allsopp@metastack.com>
(cherry picked from commit f3f3a9c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants