Skip to content

Use Base.o_* instead of raw {#const O_*} #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2025
Merged

Conversation

GulinSS
Copy link
Contributor

@GulinSS GulinSS commented Apr 25, 2025

stage1 cross compilers can use different values instead of system-defined. GHC JS Backend overrides these constants to be compatible with Node.js environment.

Details of investigation.

Interface stability tests have the following overridden constants:

  o_APPEND :: GHC.Internal.Foreign.C.Types.CInt
  o_BINARY :: GHC.Internal.Foreign.C.Types.CInt
  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
  o_EXCL :: GHC.Internal.Foreign.C.Types.CInt
  o_NOCTTY :: GHC.Internal.Foreign.C.Types.CInt
  o_NONBLOCK :: GHC.Internal.Foreign.C.Types.CInt
  o_RDONLY :: GHC.Internal.Foreign.C.Types.CInt
  o_RDWR :: GHC.Internal.Foreign.C.Types.CInt
  o_TRUNC :: GHC.Internal.Foreign.C.Types.CInt
  o_WRONLY :: GHC.Internal.Foreign.C.Types.CInt

Blocks: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13856

@GulinSS GulinSS marked this pull request as draft April 25, 2025 16:38
@GulinSS
Copy link
Contributor Author

GulinSS commented Apr 25, 2025

Set to draft while https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13856 is in progress

`stage1` cross compilers could use different values instead of
system-defined. GHC JS Backend change these constants to be compatible
with Node.js environment.
@GulinSS
Copy link
Contributor Author

GulinSS commented Apr 25, 2025

It became actual after

https://gitlab.haskell.org/ghc/ghc/-/issues/25190
https://gitlab.haskell.org/ghc/ghc/-/issues/23697

Which were raised after

haskell/cabal#10366

These changes are for restoring consistency across cross compile targets with packages which have custom Setup.hs build rules.

@GulinSS
Copy link
Contributor Author

GulinSS commented Apr 27, 2025

@GulinSS GulinSS marked this pull request as ready for review April 27, 2025 05:09
@hasufell hasufell requested a review from Bodigrim April 28, 2025 13:22
-- them overridden.
-- For example GHC JS Backend provides its own constants
-- which should be used at the target of cross compilation
-- into Node.JS environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you reference a GHC source file which contain overriding logic for JS backend? It would help future readers.

Copy link
Contributor Author

@GulinSS GulinSS Apr 29, 2025

Choose a reason for hiding this comment

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

Yes, we have a test which can be referenced for such overridings:

grep -rn testsuite -e 'o_CREAT'

testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs:13590:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
testsuite/tests/interface-stability/base-exports.stdout:10544:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
testsuite/tests/interface-stability/base-exports.stdout-mingw32:10812:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt
testsuite/tests/interface-stability/base-exports.stdout-ws-32:10544:  o_CREAT :: GHC.Internal.Foreign.C.Types.CInt

So, files testsuite/tests/interface-stability/base-exports.stdout* can be useful to determine which targets have foreigns (exports? 🤔 ).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actual overrides are collected at ./libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs. For example o_CREAT:

JS Backend

foreign import javascript unsafe "(() => { return h$base_o_creat; })"    o_CREAT    :: CInt

Other

foreign import ccall unsafe "HsBase.h __hscore_o_creat"  o_CREAT  :: CInt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably need create a [Note] there at sources?

fdOption2Int AppendOnWrite = (#const O_APPEND)
fdOption2Int NonBlockingRead = (#const O_NONBLOCK)
fdOption2Int AppendOnWrite = (Base.o_APPEND)
fdOption2Int NonBlockingRead = (Base.o_NONBLOCK)
fdOption2Int SynchronousWrites = (#const O_SYNC)
Copy link
Contributor

@Bodigrim Bodigrim Apr 28, 2025

Choose a reason for hiding this comment

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

Is there a reason for the inconsistency, beyond GHC exporting incomplete set? Could you please raise an issue on GHC side to provide a complete set in future? (We can leave unix source code inconsistent for the time being, but I'd like this to be rectified in future)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

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

I'm fine with accepting a tactical fix, but it raises questions about viability of hsc2hs for cross-compilation. What's the plan? CC @bgamari @mpickering

@GulinSS
Copy link
Contributor Author

GulinSS commented Apr 29, 2025

I'm fine with accepting a tactical fix, but it raises questions about viability of hsc2hs for cross-compilation. What's the plan? CC @bgamari @mpickering

@bgamari sent a response here. If I understand it correctly, tactical fix is OK but for further changes we need to do something with base if CLC OK. The main point is to prevent having a dependency on ghc-internal from unix and use base instead.

Copy link
Contributor

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

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

LGTM, but we really need someone to resurrect CI before merging. I won't have time for this until next week unfortunately.

@GulinSS
Copy link
Contributor Author

GulinSS commented Apr 30, 2025

resurrect CI before merging

I did obvious fixes for the CI, but need some clues about NetBSD / OpenBSD.

@hasufell
Copy link
Member

hasufell commented Apr 30, 2025

NetBSD and OpenBSD are constantly broken. I don't mind if we ignore them.

@GulinSS
Copy link
Contributor Author

GulinSS commented Apr 30, 2025

NetBSD is surprisingly fine. But OpenBSD is failed because 7.6 is a minimal version. We use image of 7.5 which was not updated by its author. Cirrus itself does not support OpenBSD OOTB.

I have no rights to merge, so, I am needed to wait.

@hasufell hasufell merged commit 47d5fc4 into haskell:master Apr 30, 2025
26 of 27 checks passed
@GulinSS GulinSS deleted the wip/T24603 branch April 30, 2025 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants