Skip to content

Instantly share code, notes, and snippets.

@gballet
Created February 21, 2019 16:08
Show Gist options
  • Save gballet/971081cc8e140e62df9a390b1700ccf8 to your computer and use it in GitHub Desktop.
Save gballet/971081cc8e140e62df9a390b1700ccf8 to your computer and use it in GitHub Desktop.
Small script to produce the ewasm precompile Go source files from the binaries compiled in ewasm/ewasm=precompiles
#!/usr/bin/env ruby
TARGETDIR = "./target/wasm32-unknown-unknown/release"
GETHDIR = "#{ENV["HOME"]}/go/src/github.com/ethereum/go-ethereum/core/vm"
`find #{TARGETDIR}/ewasm_precompile_*.wasm`.each_line do |line|
if line =~ /#{TARGETDIR}\/ewasm_precompile_(.*)\.wasm/
data = File.read(TARGETDIR+"/ewasm_precompile_#{$1}.wasm").bytes
filename = "#{GETHDIR}/ewasm_precompile_#{$1}.go"
File.open(filename, "w+") do |fd|
fd.puts "// Copyright 2019 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package vm
var ewasm#{$1.capitalize}Code = []byte{#{data.join(", ")}}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment