Skip to content

Commit 3259e24

Browse files
committed
use patch for build
1 parent 31d06a4 commit 3259e24

File tree

2 files changed

+247
-3
lines changed

2 files changed

+247
-3
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,22 @@ jobs:
3535
~/.ghc-wasm/add_to_github_path.sh
3636
popd
3737
38-
- name: checkout
38+
- name: Checkout Pandoc-wasm
3939
uses: actions/checkout@v4
4040

41-
- name: checkout
41+
- name: Checkout Pandoc
4242
uses: actions/checkout@v4
4343
with:
44-
repository: johanneswilm/pandoc
44+
repository: jgm/pandoc
4545
ref: main
4646
path: pandoc
4747

48+
- name: Patch Pandoc sources
49+
run: |
50+
cd pandoc
51+
patch -p1 < ../patch/pandoc.patch
52+
cd ..
53+
4854
- name: gen-plan-json
4955
run: |
5056
pushd pandoc
@@ -77,6 +83,15 @@ jobs:
7783
wasmtime run --dir $PWD::/ -- dist/pandoc.wasm pandoc/README.md -o pandoc/README.rst
7884
head --lines=20 pandoc/README.rst
7985
86+
- name: Upload to release
87+
uses: svenstaro/upload-release-action@v2
88+
with:
89+
repo_token: ${{ secrets.GITHUB_TOKEN }}
90+
file: dist/pandoc.wasm
91+
asset_name: pandoc.wasm
92+
tag: ${{ github.ref }}
93+
overwrite: true
94+
8095
- name: upload-pages-artifact
8196
uses: actions/upload-pages-artifact@v3
8297
with:

patch/pandoc.patch

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
diff --git a/cabal.project b/cabal.project
2+
index 4ca6da52e630..b3a4ffcbb87b 100644
3+
--- a/cabal.project
4+
+++ b/cabal.project
5+
@@ -2,10 +2,147 @@ packages: .
6+
pandoc-lua-engine
7+
pandoc-server
8+
pandoc-cli
9+
-tests: True
10+
-flags: +embed_data_files
11+
+tests: False
12+
+
13+
constraints: skylighting-format-blaze-html >= 0.1.1.3,
14+
skylighting-format-context >= 0.1.0.2,
15+
-- for now (commercialhaskell/stackage#7545):
16+
data-default-class <= 0.2, data-default <= 0.8
17+
18+
+allow-newer: all:zlib
19+
+
20+
+package aeson
21+
+ flags: -ordered-keymap
22+
+
23+
+package crypton
24+
+ ghc-options: -optc-DARGON2_NO_THREADS
25+
+
26+
+package digest
27+
+ flags: -pkg-config
28+
+
29+
+package pandoc
30+
+ flags: +embed_data_files
31+
+
32+
+package pandoc-cli
33+
+ flags: -lua -server
34+
+
35+
+allow-newer:
36+
+ all:Cabal,
37+
+ all:Cabal-syntax,
38+
+ all:array,
39+
+ all:base,
40+
+ all:binary,
41+
+ all:bytestring,
42+
+ all:containers,
43+
+ all:deepseq,
44+
+ all:directory,
45+
+ all:exceptions,
46+
+ all:filepath,
47+
+ all:ghc,
48+
+ all:ghc-bignum,
49+
+ all:ghc-boot,
50+
+ all:ghc-boot-th,
51+
+ all:ghc-compact,
52+
+ all:ghc-experimental,
53+
+ all:ghc-heap,
54+
+ all:ghc-internal,
55+
+ all:ghc-platform,
56+
+ all:ghc-prim,
57+
+ all:ghc-toolchain,
58+
+ all:ghci,
59+
+ all:haskeline,
60+
+ all:hpc,
61+
+ all:integer-gmp,
62+
+ all:mtl,
63+
+ all:os-string,
64+
+ all:parsec,
65+
+ all:pretty,
66+
+ all:process,
67+
+ all:rts,
68+
+ all:semaphore-compat,
69+
+ all:stm,
70+
+ all:system-cxx-std-lib,
71+
+ all:template-haskell,
72+
+ all:text,
73+
+ all:time,
74+
+ all:transformers,
75+
+ all:unix,
76+
+ all:xhtml
77+
+
78+
+constraints:
79+
+ Cabal installed,
80+
+ Cabal-syntax installed,
81+
+ array installed,
82+
+ base installed,
83+
+ binary installed,
84+
+ bytestring installed,
85+
+ containers installed,
86+
+ deepseq installed,
87+
+ directory installed,
88+
+ exceptions installed,
89+
+ filepath installed,
90+
+ ghc installed,
91+
+ ghc-bignum installed,
92+
+ ghc-boot installed,
93+
+ ghc-boot-th installed,
94+
+ ghc-compact installed,
95+
+ ghc-experimental installed,
96+
+ ghc-heap installed,
97+
+ ghc-internal installed,
98+
+ ghc-platform installed,
99+
+ ghc-prim installed,
100+
+ ghc-toolchain installed,
101+
+ ghci installed,
102+
+ haskeline installed,
103+
+ hpc installed,
104+
+ integer-gmp installed,
105+
+ mtl installed,
106+
+ os-string installed,
107+
+ parsec installed,
108+
+ pretty installed,
109+
+ process installed,
110+
+ rts installed,
111+
+ semaphore-compat installed,
112+
+ stm installed,
113+
+ system-cxx-std-lib installed,
114+
+ template-haskell installed,
115+
+ text installed,
116+
+ time installed,
117+
+ transformers installed,
118+
+ unix installed,
119+
+ xhtml installed
120+
+
121+
+-- https://github.com/haskell/network/pull/598
122+
+source-repository-package
123+
+ type: git
124+
+ location: https://github.com/haskell-wasm/network.git
125+
+ tag: ab92e48e9fdf3abe214f85fdbe5301c1280e14e9
126+
+
127+
+source-repository-package
128+
+ type: git
129+
+ location: https://github.com/haskell-wasm/foundation.git
130+
+ tag: 8e6dd48527fb429c1922083a5030ef88e3d58dd3
131+
+ subdir: basement
132+
+
133+
+source-repository-package
134+
+ type: git
135+
+ location: https://github.com/haskell-wasm/hs-memory.git
136+
+ tag: a198a76c584dc2cfdcde6b431968de92a5fed65e
137+
+
138+
+source-repository-package
139+
+ type: git
140+
+ location: https://github.com/haskell-wasm/xml.git
141+
+ tag: bc793dc9bc29c92245d3482a54d326abd3ae1403
142+
+ subdir: xml-conduit
143+
+
144+
+-- https://github.com/haskellari/splitmix/pull/73
145+
+source-repository-package
146+
+ type: git
147+
+ location: https://github.com/amesgen/splitmix
148+
+ tag: 5f5b766d97dc735ac228215d240a3bb90bc2ff75
149+
+
150+
+source-repository-package
151+
+ type: git
152+
+ location: https://github.com/amesgen/cborg
153+
+ tag: c3b5c696f62d04c0d87f55250bfc0016ab94d800
154+
+ subdir: cborg
155+
diff --git a/pandoc-cli/pandoc-cli.cabal b/pandoc-cli/pandoc-cli.cabal
156+
index 5b904b9906bd..66d92a1875f3 100644
157+
--- a/pandoc-cli/pandoc-cli.cabal
158+
+++ b/pandoc-cli/pandoc-cli.cabal
159+
@@ -61,7 +61,7 @@ common common-options
160+
161+
common common-executable
162+
import: common-options
163+
- ghc-options: -rtsopts -with-rtsopts=-A8m -threaded
164+
+ ghc-options: -rtsopts -with-rtsopts=-H64m
165+
166+
executable pandoc
167+
import: common-executable
168+
@@ -74,6 +74,10 @@ executable pandoc
169+
text
170+
other-modules: PandocCLI.Lua
171+
, PandocCLI.Server
172+
+
173+
+ if arch(wasm32)
174+
+ ghc-options: -optl-Wl,--export=__wasm_call_ctors,--export=hs_init_with_rtsopts,--export=malloc,--export=wasm_main
175+
+
176+
if flag(nightly)
177+
cpp-options: -DNIGHTLY
178+
build-depends: template-haskell,
179+
diff --git a/pandoc-cli/src/pandoc.hs b/pandoc-cli/src/pandoc.hs
180+
index 019d0adedb15..520a858c89a2 100644
181+
--- a/pandoc-cli/src/pandoc.hs
182+
+++ b/pandoc-cli/src/pandoc.hs
183+
@@ -1,5 +1,7 @@
184+
{-# LANGUAGE CPP #-}
185+
+{-# LANGUAGE ScopedTypeVariables #-}
186+
{-# LANGUAGE TemplateHaskell #-}
187+
+
188+
{- |
189+
Module : Main
190+
Copyright : Copyright (C) 2006-2024 John MacFarlane
191+
@@ -34,6 +36,13 @@ import qualified Language.Haskell.TH as TH
192+
import Data.Time
193+
#endif
194+
195+
+#if defined(wasm32_HOST_ARCH)
196+
+import Control.Exception
197+
+import Foreign
198+
+import Foreign.C
199+
+import System.IO
200+
+#endif
201+
+
202+
#ifdef NIGHTLY
203+
versionSuffix :: String
204+
versionSuffix = "-nightly-" ++
205+
@@ -44,6 +53,24 @@ versionSuffix :: String
206+
versionSuffix = ""
207+
#endif
208+
209+
+#if defined(wasm32_HOST_ARCH)
210+
+
211+
+foreign export ccall "wasm_main" wasm_main :: Ptr CChar -> Int -> IO ()
212+
+
213+
+wasm_main :: Ptr CChar -> Int -> IO ()
214+
+wasm_main raw_args_ptr raw_args_len =
215+
+ catch act (\(err :: SomeException) -> hPrint stderr err)
216+
+ where
217+
+ act = do
218+
+ args <- words <$> peekCStringLen (raw_args_ptr, raw_args_len)
219+
+ free raw_args_ptr
220+
+ engine <- getEngine
221+
+ res <- parseOptionsFromArgs options defaultOpts "pandoc.wasm" $ args <> ["/in", "-o", "/out"]
222+
+ case res of
223+
+ Left e -> handleOptInfo engine e
224+
+ Right opts -> convertWithOpts engine opts
225+
+#endif
226+
+
227+
main :: IO ()
228+
main = E.handle (handleError . Left) $ do
229+
prg <- getProgName

0 commit comments

Comments
 (0)