Skip to content

Instantly share code, notes, and snippets.

@janwirth
Last active June 17, 2023 02:40
Show Gist options
  • Save janwirth/cbb07005eaa00340dab4e2cf13c18097 to your computer and use it in GitHub Desktop.
Save janwirth/cbb07005eaa00340dab4e2cf13c18097 to your computer and use it in GitHub Desktop.
Build elm for M1
Name: elm
Version: 0.19.1
Synopsis:
The `elm` command line interface.
Description:
This includes commands like `elm make`, `elm repl`, and many others
for helping make Elm developers happy and productive.
Homepage: https://elm-lang.org
License: BSD3
License-file: LICENSE
Author: Evan Czaplicki
Maintainer: info@elm-lang.org
Copyright: Copyright (c) 2011-present, Evan Czaplicki
Category: Compiler, Language
Cabal-version: >=1.9
Build-type: Simple
source-repository head
type: git
location: git://github.com/elm/compiler.git
Flag dev {
Description: Turn off optimization and make warnings errors
Default: False
}
Executable elm
if flag(dev)
ghc-options: -O0 -Wall -Werror
else
ghc-options: -O2 -rtsopts -threaded "-with-rtsopts=-N -qg -A128m"
-- add -eventlog for (elm make src/Main.elm +RTS -l; threadscope elm.eventlog)
-- https://www.oreilly.com/library/view/parallel-and-concurrent/9781449335939/
Hs-Source-Dirs:
compiler/src
builder/src
terminal/impl
terminal/src
other-extensions:
TemplateHaskell
Main-Is:
Main.hs
other-modules:
Bump
Develop
Diff
Init
Install
Make
Publish
Repl
-- terminal args
Terminal
Terminal.Chomp
Terminal.Error
Terminal.Helpers
Terminal.Internal
-- from terminal/
Develop.Generate.Help
Develop.Generate.Index
Develop.StaticFiles
Develop.StaticFiles.Build
-- from builder/
Build
BackgroundWriter
Deps.Bump
Deps.Diff
Deps.Registry
Deps.Solver
Deps.Website
File
Generate
Http
Reporting
Reporting.Exit
Reporting.Exit.Help
Reporting.Task
Stuff
-- Elm things
Elm.Outline
Elm.Details
--
Elm.Compiler.Imports
Elm.Compiler.Type
Elm.Compiler.Type.Extract
Elm.Constraint
Elm.Docs
Elm.Float
Elm.Interface
Elm.Kernel
Elm.Licenses
Elm.Magnitude
Elm.ModuleName
Elm.Package
Elm.String
Elm.Version
-- data structures
Data.Bag
Data.Index
Data.Map.Utils
Data.Name
Data.NonEmptyList
Data.OneOrMore
Data.Utf8
-- json
Json.Decode
Json.Encode
Json.String
-- from compiler/
AST.Canonical
AST.Optimized
AST.Source
AST.Utils.Binop
AST.Utils.Shader
AST.Utils.Type
Canonicalize.Effects
Canonicalize.Environment
Canonicalize.Environment.Dups
Canonicalize.Environment.Foreign
Canonicalize.Environment.Local
Canonicalize.Expression
Canonicalize.Module
Canonicalize.Pattern
Canonicalize.Type
Compile
Generate.Html
Generate.JavaScript
Generate.JavaScript.Builder
Generate.JavaScript.Expression
Generate.JavaScript.Functions
Generate.JavaScript.Name
Generate.Mode
Nitpick.Debug
Nitpick.PatternMatches
Optimize.Case
Optimize.DecisionTree
Optimize.Expression
Optimize.Module
Optimize.Names
Optimize.Port
Parse.Declaration
Parse.Expression
Parse.Keyword
Parse.Module
Parse.Number
Parse.Pattern
Parse.Shader
Parse.Space
Parse.String
Parse.Symbol
Parse.Type
Parse.Variable
Parse.Primitives
Reporting.Annotation
Reporting.Doc
Reporting.Error
Reporting.Error.Canonicalize
Reporting.Error.Docs
Reporting.Error.Import
Reporting.Error.Json
Reporting.Error.Main
Reporting.Error.Pattern
Reporting.Error.Syntax
Reporting.Error.Type
Reporting.Render.Code
Reporting.Render.Type
Reporting.Render.Type.Localizer
Reporting.Report
Reporting.Result
Reporting.Suggest
Reporting.Warning
Type.Constrain.Expression
Type.Constrain.Module
Type.Constrain.Pattern
Type.Error
Type.Instantiate
Type.Occurs
Type.Solve
Type.Type
Type.Unify
Type.UnionFind
Paths_elm
Build-depends:
ansi-terminal >= 0.8,
ansi-wl-pprint >= 0.6.8,
base >=4.11 && <5,
binary >= 0.8 && < 0.9,
bytestring >= 0.9 && < 0.11,
containers >= 0.5.8.2,
directory >= 1.2.3.0 && < 2.0,
edit-distance >= 0.2 && < 0.3,
file-embed,
filelock,
filepath >= 1 && < 2.0,
ghc-prim >= 0.5.2,
haskeline,
HTTP >= 4000.2.5 && < 4000.4,
http-client >= 0.6 && < 0.7,
http-client-tls >= 0.3 && < 0.4,
http-types >= 0.12 && < 1.0,
language-glsl >= 0.3,
mtl >= 2.2.1 && < 3,
network >= 2.4,
parsec,
process,
raw-strings-qq,
scientific,
SHA,
snap-core,
snap-server,
template-haskell,
time >= 1.9.1,
unordered-containers,
utf8-string,
vector,
zip-archive
janiczek 4:15 PM
something like
git clone https://github.com/elm/compiler
cd compiler
nix-shell -p cabal2nix
> cabal2nix --shell ./. >shell.nix
> exit
vim elm.cabal
# remove the upper bound on `network` dep
vim shell.nix
# add this below the `license` line
# buildTools = [ nixpkgs.cabal-install ];
nix-shell
> cabal build -O2
which leaves the binary in ./dist-newstyle/build/aarch64-osx/ghc-8.10.7/elm-0.19.1/x/elm/opt/build/elm/elm
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
let
inherit (nixpkgs) pkgs;
f = { mkDerivation, ansi-terminal, ansi-wl-pprint, base, binary
, bytestring, containers, directory, edit-distance, file-embed
, filelock, filepath, ghc-prim, haskeline, HTTP, http-client
, http-client-tls, http-types, language-glsl, lib, mtl, network
, parsec, process, raw-strings-qq, scientific, SHA, snap-core
, snap-server, template-haskell, time, unordered-containers
, utf8-string, vector, zip-archive
}:
mkDerivation {
pname = "elm";
version = "0.19.1";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
ansi-terminal ansi-wl-pprint base binary bytestring containers
directory edit-distance file-embed filelock filepath ghc-prim
haskeline HTTP http-client http-client-tls http-types language-glsl
mtl network parsec process raw-strings-qq scientific SHA snap-core
snap-server template-haskell time unordered-containers utf8-string
vector zip-archive
];
homepage = "https://elm-lang.org";
description = "The `elm` command line interface";
license = lib.licenses.bsd3;
buildTools = [ nixpkgs.cabal-install ];
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
drv = variant (haskellPackages.callPackage f {});
in
if pkgs.lib.inNixShell then drv.env else drv
@janwirth
Copy link
Author

cabal build --minimize-conflict-set --allow-newer=base --ghc-options=-dynamic seems to be a simpler solution to the dependency problem, however this is only tested for the worker build.

image

@janwirth
Copy link
Author

Working with compiler too.

@sax
Copy link

sax commented Oct 25, 2022

I was wondering if you had succeeded at building elm on M1 more recently than March. Also, what versions of ghc/cabal are you using, and did you have to install other dependencies?

$ cabal --version
cabal-install version 3.6.2.0

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.7

I have llvm@12 installed via homebrew.

When I run cabal, it errors with this message:

[136 of 136] Compiling Crypto.Tutorial  ( Crypto/Tutorial.hs, dist/build/Crypto/Tutorial.o, dist/build/Crypto/Tutorial.dyn_o )

/var/folders/l2/qv3mln15139bf1ffnb7_d73c0000gn/T/ghc38437_0/ghc_1.s:3394:2: error:
     error: instruction requires: sha3
            eor3.16b        v0, v1, v0, v2
            ^
     |
3394 |         eor3.16b        v0, v1, v0, v2
     |  ^

<no location info>: error:
    Error running clang! you need clang installed to use the LLVM backend
    (or GHC tried to execute clang incorrectly)
`clang' failed in phase `Clang (Assembler)'. (Exit code: 1)
cabal: Failed to build cryptonite-0.30 (which is required by exe:elm from
elm-0.19.1). See the build log above for details.

When I try with a newer version of ghc (installed via ghcup) it gives other errors much further up the dependency chain, which is why I'm trying an older tool chain.

@sax
Copy link

sax commented Oct 25, 2022

Ok, I switched to llvm@13 and cabal build -O2 seems to be working.

@janwirth
Copy link
Author

Thanks for sharing this info. I went to just installing elm through npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment