homebrew-core/Formula/emscripten.rb

121 lines
3.6 KiB
Ruby

require "language/node"
class Emscripten < Formula
desc "LLVM bytecode to JavaScript compiler"
homepage "https://emscripten.org/"
# Emscripten is available under 2 licenses, the MIT license and the
# University of Illinois/NCSA Open Source License.
license "MIT"
stable do
url "https://github.com/emscripten-core/emscripten/archive/1.40.1.tar.gz"
sha256 "e15ad7ffa1cce35c25cac7c797d6daa0c5868905eaaf5ed1431a8228b8803dfc"
resource "fastcomp" do
url "https://github.com/emscripten-core/emscripten-fastcomp/archive/1.40.1.tar.gz"
sha256 "c34868ab566e9f073df319d9872608cef47ed1ea74852acacb12a22fd7c99a4c"
end
resource "fastcomp-clang" do
url "https://github.com/emscripten-core/emscripten-fastcomp-clang/archive/1.40.1.tar.gz"
sha256 "9ce4612df39684348d78acb711ec10bee98ad4ac136fb0dcb70d4c884b8bb6b3"
end
end
livecheck do
url :head
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
cellar :any
rebuild 1
sha256 "8b21f38d1065a89301c3cce79c0bce448089d536280ae6d1cbe97ee3a98b183d" => :catalina
sha256 "476a8b8a00f535d160cbb8a08f82c5256d46a434703ecd86d2ed10ec5cea36fe" => :mojave
sha256 "09ad53bb82328357f106bbb01b06caa9a02c3daedc9d3ea4f7419badbaa66e17" => :high_sierra
end
head do
url "https://github.com/emscripten-core/emscripten.git"
resource "fastcomp" do
url "https://github.com/emscripten-core/emscripten-fastcomp.git"
end
resource "fastcomp-clang" do
url "https://github.com/emscripten-core/emscripten-fastcomp-clang.git"
end
end
depends_on "cmake" => :build
depends_on "binaryen"
depends_on "node"
depends_on "python@3.8"
depends_on "yuicompressor"
def install
ENV.cxx11
# All files from the repository are required as emscripten is a collection
# of scripts which need to be installed in the same layout as in the Git
# repository.
libexec.install Dir["*"]
(buildpath/"fastcomp").install resource("fastcomp")
(buildpath/"fastcomp/tools/clang").install resource("fastcomp-clang")
cmake_args = std_cmake_args.reject { |s| s["CMAKE_INSTALL_PREFIX"] }
cmake_args = [
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_INSTALL_PREFIX=#{libexec}/llvm",
"-DLLVM_TARGETS_TO_BUILD='X86;JSBackend'",
"-DLLVM_INCLUDE_EXAMPLES=OFF",
"-DLLVM_INCLUDE_TESTS=OFF",
"-DCLANG_INCLUDE_TESTS=OFF",
"-DOCAMLFIND=/usr/bin/false",
"-DGO_EXECUTABLE=/usr/bin/false",
]
mkdir "fastcomp/build" do
system "cmake", "..", *cmake_args
system "make"
system "make", "install"
end
cd libexec do
system "npm", "install", *Language::Node.local_npm_install_args
rm_f "node_modules/ws/builderror.log" # Avoid references to Homebrew shims
end
%w[em++ em-config emar emcc emcmake emconfigure emlink.py emmake
emranlib emrun emscons].each do |emscript|
(bin/emscript).write_env_script libexec/emscript, PYTHON: Formula["python@3.8"].opt_bin/"python3"
end
end
def post_install
system bin/"emcc"
inreplace "#{libexec}/.emscripten" do |s|
s.gsub! /^(LLVM_ROOT.*)/, "#\\1\nLLVM_ROOT = \"#{opt_libexec}/llvm/bin\"\\2"
s.gsub! /^(BINARYEN_ROOT.*)/, "#\\1\nBINARYEN_ROOT = \"#{Formula["binaryen"].opt_prefix}\"\\2"
end
end
test do
# Fixes "Unsupported architecture" Xcode prepocessor error
ENV.delete "CPATH"
(testpath/"test.c").write <<~EOS
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
EOS
system bin/"emcc", "test.c", "-o", "test.js", "-s", "NO_EXIT_RUNTIME=0"
assert_equal "Hello World!", shell_output("node test.js").chomp
end
end