Skip to content
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

Allow GHCup to build & run on OpenBSD #1138

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cabal.project.release
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import: cabal.project.common

optimization: 2

-- The release project file always wants to build with -tar.
-- The tar flag is only there to circumvent complicated errors during
-- development, which sometimes happens due to libarchive.
-- The release project file always wants to build with -tar on the
-- platforms it supports (which are those it provides config.h files
-- for). The tar flag is only there to circumvent complicated errors
-- during development, which sometimes happens due to libarchive.
package ghcup
flags: +tui

Expand Down Expand Up @@ -32,3 +33,6 @@ elif os(freebsd)
xz -system-xz
package *
ghc-options: -split-sections
else
package ghcup
flags: +tar
1 change: 1 addition & 0 deletions lib-opt/GHCup/OptParse/ChangeLog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ changelog ChangeLogOptions{..} runAppState runLogger = do
Darwin -> exec "open" [T.unpack $ decUTF8Safe $ serializeURIRef' uri] Nothing Nothing
Linux _ -> exec "xdg-open" [T.unpack $ decUTF8Safe $ serializeURIRef' uri] Nothing Nothing
FreeBSD -> exec "xdg-open" [T.unpack $ decUTF8Safe $ serializeURIRef' uri] Nothing Nothing
OpenBSD -> exec "xdg-open" [T.unpack $ decUTF8Safe $ serializeURIRef' uri] Nothing Nothing
Windows -> do
let args = "start \"\" " ++ (T.unpack $ decUTF8Safe $ serializeURIRef' uri)
c <- liftIO $ system $ args
Expand Down
10 changes: 10 additions & 0 deletions lib/GHCup/Platform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,17 @@ getPlatform = do
either (const Nothing) Just . versioning . decUTF8Safe'
<$> getFreeBSDVersion
pure $ PlatformResult { _platform = FreeBSD, _distroVersion = ver }
"openbsd" -> do
ver <-
either (const Nothing) Just . versioning . decUTF8Safe'
<$> getOpenBSDVersion
pure $ PlatformResult { _platform = OpenBSD, _distroVersion = ver }
"mingw32" -> pure PlatformResult { _platform = Windows, _distroVersion = Nothing }
what -> throwE $ NoCompatiblePlatform what
lift $ logDebug $ "Identified Platform as: " <> T.pack (prettyShow pfr)
pure pfr
where
getOpenBSDVersion = lift $ fmap _stdOut $ executeOut "uname" ["-r"] Nothing
Copy link
Member

@hasufell hasufell Nov 20, 2024

Choose a reason for hiding this comment

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

Are you sure uname is the OpenBSD version and not just the kernel?

What are the outputs? Are they purely numeric? Otherwise we will have a hard time matching on them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think the BSDs have a kernel version distinct from the OS version, since they're all developed by the same people under a single umbrella; a release is the kernel, plus base packages (userland), plus ports (package repository for that version).

I developed these changes on my real OpenBSD/amd64 machine and tested the uname -r command after reading the man page at the time.

OpenBSD's man page for uname says:

    -r      Print the operating system release.  On OpenBSD, the format is
            digit.digit.

(and digit.digit is underlined, but (GitHub's) Markdown doesn't seem to support that, nor setting monospace font quote without a code block which makes things literal anyway.)

However, I just realised the man page doesn't specify, and I hadn't considered, what would happen on OpenBSD-snapshot or -current (which are non-stable tracks that some OpenBSD users do prefer)? I'm gonna check on a VM now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is what I get on my -snapshot VM:

OpenBSD 7.6-current (GENERIC.MP) #243: Mon Nov 18 13:30:33 MST 2024

Welcome to OpenBSD: The proactively secure Unix-like operating system.

Please use the sendbug(1) utility to report bugs in the system.
Before reporting a bug, please try to reproduce it with the latest
version of the code.  With bug reports, please try to ensure that
enough information to reproduce the problem is enclosed, and if a
known fix for it exists, include that as well.

You have new mail.
foo# uname -r
7.6

I generally stick to release, but I do think the login message starting with 7.6-current is correct, even though it's -snapshot, because according to the docs I just checked, -current is essentially following trunk and can only be done by building from source oneself, and -snapshot is just a snapshot of -current compiled for release as non-stable.

So yeah, -r is always a release number and nothing else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comments on this Reddit thread basically confirm that there's no such thing as a -snapshot track, so that was my bad; snapshots are just compiled releases of the -current track.

Copy link
Member

Choose a reason for hiding this comment

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

getFreeBSDVersion = lift $ fmap _stdOut $ executeOut "freebsd-version" [] Nothing
getDarwinVersion = lift $ fmap _stdOut $ executeOut "sw_vers"
["-productVersion"]
Expand Down Expand Up @@ -306,6 +312,7 @@ getStackGhcBuilds PlatformResult{..} = do
[] -> []
_ -> L.intercalate "-" c)
libComponents
OpenBSD -> pure []
FreeBSD ->
case _distroVersion of
Just fVer
Expand Down Expand Up @@ -343,13 +350,16 @@ getStackOSKey PlatformRequest { .. } =
(A_64 , Darwin ) -> pure "macosx"
(A_32 , FreeBSD) -> pure "freebsd32"
(A_64 , FreeBSD) -> pure "freebsd64"
(A_32 , OpenBSD) -> pure "openbsd32"
(A_64 , OpenBSD) -> pure "openbsd64"
(A_32 , Windows) -> pure "windows32"
(A_64 , Windows) -> pure "windows64"
(A_ARM , Linux _) -> pure "linux-armv7"
(A_ARM64, Linux _) -> pure "linux-aarch64"
(A_Sparc, Linux _) -> pure "linux-sparc"
(A_ARM64, Darwin ) -> pure "macosx-aarch64"
(A_ARM64, FreeBSD) -> pure "freebsd-aarch64"
(A_ARM64, OpenBSD) -> pure "openbsd-aarch64"
(arch', os') -> throwE $ UnsupportedSetupCombo arch' os'

getStackPlatformKey :: (MonadReader env m, MonadFail m, HasLog env, MonadCatch m, MonadIO m)
Expand Down
2 changes: 2 additions & 0 deletions lib/GHCup/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ data Platform = Linux LinuxDistro
| Darwin
-- ^ must exit
| FreeBSD
| OpenBSD
hasufell marked this conversation as resolved.
Show resolved Hide resolved
| Windows
-- ^ must exit
deriving (Eq, GHC.Generic, Ord, Show)
Expand All @@ -237,6 +238,7 @@ platformToString :: Platform -> String
platformToString (Linux distro) = "linux-" ++ distroToString distro
platformToString Darwin = "darwin"
platformToString FreeBSD = "freebsd"
platformToString OpenBSD = "openbsd"
platformToString Windows = "windows"

instance Pretty Platform where
Expand Down
2 changes: 2 additions & 0 deletions lib/GHCup/Types/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ instance ToJSONKey Platform where
FreeBSD -> T.pack "FreeBSD"
Linux (OtherLinux s) -> T.pack ("Linux_" <> s)
Linux d -> T.pack ("Linux_" <> show d)
OpenBSD -> T.pack "OpenBSD"
hasufell marked this conversation as resolved.
Show resolved Hide resolved
Windows -> T.pack "Windows"

instance FromJSONKey Platform where
fromJSONKey = FromJSONKeyTextParser $ \t -> if
| T.pack "Darwin" == t -> pure Darwin
| T.pack "FreeBSD" == t -> pure FreeBSD
| T.pack "OpenBSD" == t -> pure OpenBSD
| T.pack "Windows" == t -> pure Windows
| T.pack "Linux_" `T.isPrefixOf` t -> case
T.stripPrefix (T.pack "Linux_") t
Expand Down
Loading