Last active
April 8, 2021 22:03
-
-
Save mattrutherford/7671e474ea3507be90b9c98113938187 to your computer and use it in GitHub Desktop.
build-wasm-runtimes.rb for Polkadot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Copy this file to an empty directory, make executable (`chmod +x build-wasm-runtimes.rb`) | |
# Run it: `./build-wasm-runtimes.rb` | |
require 'fileutils' | |
require 'pty' | |
# List commits for each desired release | |
RELEASES = [ | |
'72ce1c8', # Polkadot v0.8.29 | |
'99043f7', # Polkadot v0.8.28-1 | |
'2f84569' # Polkadot v0.8.27 | |
] | |
# List of runtimes to build | |
RUNTIMES = [ | |
'polkadot', | |
'kusama' | |
] | |
TRACING_FEATURE = 'with-tracing = ["frame-executive/with-tracing", "sp-io/with-tracing"]' | |
def build_polkadot(commit) | |
puts "Building polkadot..." | |
cmd = 'cargo build --release --features with-tracing' | |
base_dir = Dir.pwd | |
RUNTIMES.each do |runtime| | |
Dir.chdir "#{base_dir}/runtime/#{runtime}" | |
begin | |
PTY.spawn cmd do |stdout, _stdin, _pid| | |
begin | |
stdout.each do |line| | |
puts line | |
end | |
rescue Errno::EIO | |
puts "End of IO" | |
end | |
end | |
rescue PTY::ChildExited | |
puts "Polkadot build exited" | |
end | |
Dir.chdir base_dir | |
file_name = "#{runtime}-runtime/#{runtime}_runtime.compact.wasm" | |
dest_file = "#{commit}-#{file_name}" | |
copy_cmd = "cp -r ./target/release/wbuild/#{file_name} ../tracing-runtimes/#{dest_file}" | |
puts copy_cmd | |
system copy_cmd | |
end | |
end | |
def add_feature() | |
Dir.foreach 'runtime' do |dir| | |
next unless RUNTIMES.include? dir | |
file_name = "./runtime/#{dir}/Cargo.toml" | |
puts "Adding required features to: `#{file_name}`" | |
next unless File.file? file_name | |
file = File.open file_name | |
contents = file.read | |
if contents.length < 1 | |
puts "skipping `#{dir}`..." | |
end | |
file.close | |
return if contents.include? TRACING_FEATURE | |
index = contents.index('[features]') + 10 | |
contents.insert index, "\n#{TRACING_FEATURE}" | |
File.write file_name, contents | |
end | |
end | |
unless File.directory? 'polkadot' | |
unless system 'git clone https://github.com/paritytech/polkadot.git' | |
abort 'Failed to clone polkadot' | |
end | |
end | |
FileUtils.mkdir_p 'tracing-runtimes' | |
RUNTIMES.each do |runtime| | |
FileUtils.mkdir_p "tracing-runtimes/#{runtime}-runtime" | |
end | |
Dir.chdir 'polkadot' | |
RELEASES.each do |commit| | |
runtime_path = "../tracing-runtimes/#{commit}" | |
if File.file? runtime_path | |
puts "Runtime #{runtime_path} exists already, skipping..." | |
next | |
end | |
puts "Building runtime #{commit}..." | |
system 'git reset --hard' | |
system "git checkout #{commit}" | |
add_feature | |
build_polkadot commit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment