{"id":13565089,"url":"https://github.com/SWI-Prolog/swipl-wasm","last_synced_at":"2025-04-03T22:30:34.587Z","repository":{"id":55060173,"uuid":"138418470","full_name":"SWI-Prolog/swipl-wasm","owner":"SWI-Prolog","description":"Run SWI-Prolog in your browser using WebAssemply","archived":true,"fork":false,"pushed_at":"2022-08-29T16:13:05.000Z","size":1109,"stargazers_count":76,"open_issues_count":6,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-04T18:46:02.760Z","etag":null,"topics":["prolog","swi-prolog","webassembly"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SWI-Prolog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-23T16:52:39.000Z","updated_at":"2024-10-23T01:12:50.000Z","dependencies_parsed_at":"2022-08-14T10:31:12.643Z","dependency_job_id":null,"html_url":"https://github.com/SWI-Prolog/swipl-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWI-Prolog%2Fswipl-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWI-Prolog%2Fswipl-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWI-Prolog%2Fswipl-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWI-Prolog%2Fswipl-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SWI-Prolog","download_url":"https://codeload.github.com/SWI-Prolog/swipl-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247089719,"owners_count":20881822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["prolog","swi-prolog","webassembly"],"created_at":"2024-08-01T13:01:40.600Z","updated_at":"2025-04-03T22:30:33.153Z","avatar_url":"https://github.com/SWI-Prolog.png","language":"HTML","funding_links":[],"categories":["HTML"],"sub_categories":[],"readme":"\u003e This repository is superseeded by the normal SWI-Prolog development\n\u003e distribution, see https://github.com/SWI-Prolog/swipl-wasm.  See\n\u003e https://swi-prolog.discourse.group/t/swi-prolog-in-the-browser-using-wasm/5650\n\u003e for updates on the WASM port.\n\n# SWI-Prolog ported to WebAssembly\n\nThis repository contains instructions to compile a Prolog\nimplementation SWI-Prolog (\u003chttp://swi-prolog.org\u003e) to\nWebAssembly.\n\n## Compilation\n\nThese compilation instructions assume Linux-based\nhost machine. The resulting WebAssembly binary is\nplatform-independent.\n\n### Preparation\n\nYou need to download the Emscripten compiler. Follow\nthe instruction on its [homepage][em-install].\n\n[em-install]:http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html\n\nAfter the successful installation load the Emscripten\nenvironment into the current terminal session (adjust path):\n\n```sh\nsource ./emsdk_env.sh\n```\n\n### Dependencies\n\nSWI-Prolog depends on zlib. To compile it to WebAssembly:\n\n```sh\nwget https://zlib.net/zlib-1.2.11.tar.gz -O \"$HOME/zlib-1.2.11.tar.gz\"\ntar -xf \"$HOME/zlib-1.2.11.tar.gz\" -C \"$HOME\"\ncd \"$HOME/zlib-1.2.11\"\nemconfigure ./configure\nemmake make\n```\n\nThis will download and build zlib into the `zlib-1.2.11`\nsubdirectory in your home directory.\n\n### Build SWI-Prolog\n\n```sh\ngit clone https://github.com/rla/swipl-devel.git \"$HOME/swipl-devel\"\ncd \"$HOME/swipl-devel\"\ngit fetch\ngit checkout wasm\n./prepare\n```\n\nThis will ask:\n\n```\nDo you want me to run git submodule update --init? [Y/n]\n```\n\nAs we are not yet building packages, say \"n\".\n\nIf it asks:\n\n```\nCould not find documentation.  What do you want to do?\n```\n\nThen say \"3\". We do not need documentation to build it.\n\nAfter this we can run configure and compile:\n\n```sh\ncd \"$HOME/swipl-devel/src\"\nLDFLAGS=-L\"$HOME/zlib-1.2.11\" \\\n  LIBS=-lzlib \\\n  CPPFLAGS=-I\"$HOME/zlib-1.2.11\" \\\n  COFLAGS=-O3 emconfigure ./configure \\\n    --disable-mt \\\n    --disable-gmp \\\n    --disable-custom-flags\nemmake make\n```\n\nThis will build the necessary 3 files in `$HOME/swipl-devel/src`.\nSee \"Distribution\".\n\n## Distribution\n\nBinary distribution (in the `dist` directory) contains\nthe files:\n\n * `swipl-web.wasm` - binary distribution of SWI-Prolog executable.\n * `swipl-web.dat` - necessary files to initialize the runtime and the library.\n * `swipl-web.js` - JavaScript wrapper that loads the wasm code and prepares the\n   virtual filesystem with the runtime initialization file and the library.\n\n## Usage\n\nPlease see \"Foreign Language Interface\" (FLI) in the SWI-Prolog manual. A very limited\nset of function findings into JavaScript can be seen in the demo.\nThe bindings use [cwrap][cwrap] from Emscripten.\n\n[cwrap]:https://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html#cwrap\n\nGeneral workflow:\n\n * Set up a stub [Module object][module] with `noInitialRun: true` and other options.\n * Set up FLI bindings in `Module.onRuntimeInitialized`.\n * Use the bindings to call `PL_initialise`.\n * Set up the location for standard library.\n * Use the [FS API][fs] to write code files into the virtual filesystem.\n * Load the code files from SWI-Prolog side using `consult/1` or a similar way.\n * Interact with SWI-Prolog through its FLI.\n\n[module]:https://kripken.github.io/emscripten-site/docs/api_reference/module.html\n[fs]:https://kripken.github.io/emscripten-site/docs/api_reference/Filesystem-API.html\n\n### Demo\n\nSee `example/index.html` as a simple example. It can be found online at\n\u003chttp://demos.rlaanemets.com/swi-prolog-wasm/example/\u003e. The commented code\ninside the demo provides the documentation.\n\nTo test it out locally, you need to serve the files through an HTTP server.\n\n## TODO\n\n * Provide full set of bindings?\n * A way to call JavaScript from SWI-Prolog.\n * Compile and add useful packages.\n * Provide a mechanism to load packs?\n * Easier way to turn Prolog terms into JS objects?\n * See where WebAssembly goes and what interfaces\n   could be added (direct DOM access?).\n\n## License\n\nSWI-Prolog is covered with the Simplified BSD license. See \u003chttp://www.swi-prolog.org/license.html\u003e\n\nzlib is covered with the zlib license. See \u003chttps://zlib.net/zlib_license.html\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSWI-Prolog%2Fswipl-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSWI-Prolog%2Fswipl-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSWI-Prolog%2Fswipl-wasm/lists"}