diff --git a/Formula/cartesi-machine-emulator@0.20.rb b/Formula/cartesi-machine-emulator@0.20.rb new file mode 100644 index 0000000..3cbc720 --- /dev/null +++ b/Formula/cartesi-machine-emulator@0.20.rb @@ -0,0 +1,49 @@ +class CartesiMachineEmulatorAT020 < Formula + desc "Off-chain implementation of the Cartesi Machine" + homepage "https://github.com/cartesi/machine-emulator" + url "https://github.com/cartesi/machine-emulator/archive/refs/tags/v0.20.0.tar.gz" + sha256 "3746abb72d45dd2388f79fc24b048fe306db8e1f9f7e072176e51b95c4453949" + license "LGPL-3.0-only" + + livecheck do + url :stable + regex(/^v?(0\.20(?:\.\d+)+)$/i) + end + + # Versioned emulator kept for consumers that still target the 0.20 C API, + # namely cartesi-rollups-node. Keg-only so it never shadows the current + # cartesi-machine-emulator formula. + keg_only :versioned_formula + + depends_on "boost" => :build + depends_on "llvm" => :build + depends_on "pkg-config" => :build + depends_on "libomp" + depends_on "libslirp" + depends_on "lua@5.4" + + patch :p1 do + url "https://github.com/cartesi/machine-emulator/releases/download/v0.20.0/add-generated-files.diff" + sha256 "d9c2afcefc2759e7cd37bbedc83d54c81515f0fddb671103b489b8789aee33bb" + end + + def install + ENV.llvm_clang # use brew llvm clang + cartesi_prefix = (etc/"cartesi/images") + cartesi_prefix.mkpath + (share/"cartesi-machine").mkpath + system "make", "BREW_PREFIX=#{prefix}" + system "make", "install", "PREFIX=#{prefix}", "IMAGES_RUNTIME_PATH=#{cartesi_prefix.realpath}" + + # lua@5.4 is keg-only, so `lua5.4` is not on PATH at runtime. Rewrite the + # generated wrapper scripts to invoke it by absolute path. + inreplace [bin/"cartesi-machine", bin/"cartesi-machine-stored-hash"], + /^lua5\.4 /, "#{formula_opt_bin("lua@5.4")}/lua5.4 " + end + + test do + assert_match(/cartesi-machine #{version}/, shell_output("#{bin}/cartesi-machine --version | head -1")) + assert_path_exists include/"cartesi-machine/machine-c-api.h" + assert_path_exists include/"cartesi-machine/jsonrpc-machine-c-api.h" + end +end diff --git a/Formula/cartesi-rollups-node.rb b/Formula/cartesi-rollups-node.rb new file mode 100644 index 0000000..cd770c9 --- /dev/null +++ b/Formula/cartesi-rollups-node.rb @@ -0,0 +1,57 @@ +class CartesiRollupsNode < Formula + desc "Reference implementation of the Cartesi Rollups Node" + homepage "https://github.com/cartesi/rollups-node" + url "https://github.com/cartesi/rollups-node/archive/refs/tags/v2.0.0-alpha.12.tar.gz" + sha256 "8fcf4d775c7637b7698e642c70c31b7c16af28b77c118207a90d93da6187fc9a" + license "Apache-2.0" + + livecheck do + url :stable + regex(/^v?(\d+(?:\.\d+)+(?:-alpha\.\d+)?)$/i) + end + + depends_on "go" => :build + # 2.0.0-alpha.x builds against the 0.20 C API (machine-c-api.h), which the + # current cartesi-machine-emulator (0.21) renamed and changed. + depends_on "cartesi-machine-emulator@0.20" + + def install + emulator = Formula["cartesi-machine-emulator@0.20"] + + # The emulator is keg-only, so point cgo at its headers and libraries and + # bake an rpath so the node binaries find libcartesi at runtime. + ENV["CGO_CFLAGS"] = "-I#{emulator.opt_include}" + ENV["CGO_LDFLAGS"] = "-L#{emulator.opt_lib}" + ldflags = %W[ + -s -w + -X github.com/cartesi/rollups-node/internal/version.BuildVersion=#{version} + -r #{emulator.opt_lib} + ] + + # These link against libcartesi and spawn `cartesi-jsonrpc-machine`, which + # lives in the keg-only emulator and is therefore not on PATH. Build them + # into bin, then let env_script_all_files move everything currently in bin + # to libexec/bin and leave wrappers in bin that prepend the emulator's bin. + machine_binaries = %w[node advancer validator] + machine_binaries.each do |name| + system "go", "build", *std_go_args(ldflags:, output: bin/"cartesi-rollups-#{name}"), + "./cmd/cartesi-rollups-#{name}" + end + bin.env_script_all_files(libexec/"bin", PATH: "#{emulator.opt_bin}:$PATH") + + # The remaining services and tools are pure Go. + other_binaries = %w[cli evm-reader claimer jsonrpc-api prt machine-tool] + other_binaries.each do |name| + system "go", "build", *std_go_args(ldflags:, output: bin/"cartesi-rollups-#{name}"), + "./cmd/cartesi-rollups-#{name}" + end + end + + test do + assert_match "cartesi-rollups-cli version #{version}", shell_output("#{bin}/cartesi-rollups-cli --version") + # Exercises the wrapper and dynamic linking against the keg-only emulator. + assert_match "cartesi-rollups-node version #{version}", shell_output("#{bin}/cartesi-rollups-node --version") + assert_match "cartesi-rollups-advancer version #{version}", + shell_output("#{bin}/cartesi-rollups-advancer --version") + end +end diff --git a/README.md b/README.md index 1c5818a..0268bdb 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,10 @@ Homebrew 5.x and earlier there is no `brew trust` command and no trust step is n | [`cartesi`](Formula/cartesi.rb) | CLI for developing Cartesi applications ([cartesi/cli](https://github.com/cartesi/cli)) | | [`cartesi-machine`](Formula/cartesi-machine.rb) | Metapackage that pulls in the emulator plus the Linux and rootfs images | | [`cartesi-machine-emulator`](Formula/cartesi-machine-emulator.rb) | Off-chain implementation of the Cartesi Machine ([cartesi/machine-emulator](https://github.com/cartesi/machine-emulator)) | +| [`cartesi-machine-emulator@0.20`](Formula/cartesi-machine-emulator@0.20.rb) | Keg-only emulator 0.20, kept for `cartesi-rollups-node` which still targets its C API | | [`cartesi-machine-linux-image`](Formula/cartesi-machine-linux-image.rb) | Kernel image for the Cartesi Machine ([cartesi/machine-linux-image](https://github.com/cartesi/machine-linux-image)) | | [`cartesi-machine-rootfs-image`](Formula/cartesi-machine-rootfs-image.rb) | Rootfs image for the Cartesi Machine ([cartesi/machine-guest-tools](https://github.com/cartesi/machine-guest-tools)) | +| [`cartesi-rollups-node`](Formula/cartesi-rollups-node.rb) | Reference implementation of the Cartesi Rollups Node ([cartesi/rollups-node](https://github.com/cartesi/rollups-node)) | | [`xgenext2fs`](Formula/xgenext2fs.rb) | Ext2 filesystem generator for embedded systems ([cartesi/genext2fs](https://github.com/cartesi/genext2fs)) | `cartesi-machine` is the recommended entry point: it is a metapackage with no files of its own that @@ -79,6 +81,21 @@ brew install cartesi cartesi --version ``` +Install the Rollups Node and its services: + +```shell +brew install cartesi-rollups-node +cartesi-rollups-node --version +cartesi-rollups-cli --help +``` + +`cartesi-rollups-node` pulls in `cartesi-machine-emulator@0.20`, a keg-only build of the emulator +that the 2.0.0-alpha node series still compiles against. It does not conflict with the current +`cartesi-machine-emulator` and is not linked into `bin`; the node binaries find it on their own. +Running the node still needs a PostgreSQL database and an Ethereum JSON-RPC endpoint, configured +through `CARTESI_*` environment variables as described in the +[node documentation](https://github.com/cartesi/rollups-node). + The image formulae install their payloads into `$(brew --prefix)/etc/cartesi/images`, symlinked as `linux.bin` and `rootfs.ext2`. The emulator is configured at build time to look there, so it picks up the images automatically once both formulae are installed.