Skip to content

Commit 7a6de19

Browse files
committed
add cross compilation 🥴
1 parent dc91194 commit 7a6de19

10 files changed

Lines changed: 232 additions & 84 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extend_config({
2+
:executor_target => "aarch64-unknown-linux-gnu"
3+
})

‎.github/workflows/genvm-all.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ jobs:
112112
needs: [pre-commit]
113113
uses: ./.github/workflows/genvm-build-template.yaml
114114
with:
115-
build_type: debug
116115
runs_on: ubuntu-latest
116+
preloads: ""
117+
install_also: ""
117118
secrets: inherit
118119

119120
# build-genvm-release-ubuntu-latest:

‎.github/workflows/genvm-build-template.yaml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ name: GenVM build GenVM template
22
on:
33
workflow_call:
44
inputs:
5-
build_type:
5+
preloads:
66
type: string
77
required: true
8-
description: build type
8+
description: preloads
9+
install_also:
10+
type: string
11+
required: true
12+
description: install_also
913
runs_on:
1014
type: string
1115
required: true
@@ -31,13 +35,13 @@ jobs:
3135
- name: Get source
3236
uses: ./.github/actions/get-src
3337
with:
34-
install_also: --genvm --rust
38+
install_also: --genvm --rust ${{ inputs.install_also }}
3539
third_party: executor/third-party/wasmtime executor/third-party/wasm-tools
3640
- name: install tools and configure
3741
run: |
3842
cd "$GITHUB_WORKSPACE" && \
3943
source env.sh && \
40-
./tools/ya-build/ya-build config --preload .ci/${{ inputs.build_type }}-conf.rb
44+
./tools/ya-build/ya-build config ${{ inputs.preloads }}
4145
- name: build
4246
run: |
4347
cd "$GITHUB_WORKSPACE" && \

‎.github/workflows/release.yml‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,28 @@ jobs:
2222
uses: ./.github/workflows/genvm-build-template.yaml
2323
secrets: inherit
2424
with:
25-
build_type: release
2625
runs_on: ubuntu-latest
26+
preloads: --preload .ci/release-conf.rb
27+
install_also: ""
28+
29+
release-build-genvm-release-ubuntu-latest-aarch64:
30+
uses: ./.github/workflows/genvm-build-template.yaml
31+
secrets: inherit
32+
with:
33+
runs_on: ubuntu-latest
34+
preloads: --preload .ci/release-conf.rb --preload .ci/executor-target-linux-aarch64.rb
35+
install_also: --cross-linux-aarch64
2736

2837
release-build-genvm-release-macos-latest:
2938
uses: ./.github/workflows/genvm-build-template.yaml
3039
secrets: inherit
3140
with:
32-
build_type: release
3341
runs_on: macos-latest
42+
preloads: --preload .ci/release-conf.rb
43+
install_also: ""
3444

3545
release-publish:
36-
needs: [build-runners, release-build-genvm-release-ubuntu-latest, release-build-genvm-release-macos-latest]
46+
needs: [build-runners, release-build-genvm-release-ubuntu-latest, release-build-genvm-release-macos-latest, release-build-genvm-release-ubuntu-latest-aarch64]
3747
runs-on: ubuntu-latest
3848
permissions:
3949
contents: write # Needed for creating releases
@@ -45,6 +55,8 @@ jobs:
4555
mv ${{ needs.release-build-genvm-release-ubuntu-latest.outputs.artifact_name }} genvm-linux-amd64.zip && \
4656
wget -q ${{ needs.release-build-genvm-release-macos-latest.outputs.artifact_url }} && \
4757
mv ${{ needs.release-build-genvm-release-macos-latest.outputs.artifact_name }} genvm-macos-arm64.zip && \
58+
wget -q ${{ needs.release-build-genvm-release-ubuntu-latest-aarch64.outputs.artifact_url }} && \
59+
mv ${{ needs.release-build-genvm-release-ubuntu-latest-aarch64.outputs.artifact_name }} genvm-linux-arm64.zip && \
4860
true
4961
5062
- name: Create Release
@@ -54,6 +66,7 @@ jobs:
5466
files: |
5567
genvm-runners.zip
5668
genvm-linux-amd64.zip
69+
genvm-linux-arm64.zip
5770
genvm-macos-arm64.zip
5871
name: Release ${{ github.ref_name }}
5972
draft: false

‎build-scripts/install/install-deps.rb‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
OptionParser.new do |opts|
2323
opts.on '--genvm'
2424
opts.on '--rust'
25+
opts.on '--cross-linux-aarch64'
26+
opts.on '--zig'
2527
opts.on '--rust-det'
2628
opts.on '--os'
2729
opts.on '--wasi'
@@ -90,6 +92,7 @@ def find_executable(name)
9092
end.call()
9193

9294
logger.info("detected target is #{TARGET_TRIPLE}")
95+
$logger = logger
9396

9497
OS = (Proc.new {
9598
re = {
@@ -127,6 +130,7 @@ def find_executable(name)
127130

128131
download_dir = root.join('tools', 'downloaded')
129132
download_dir.mkpath()
133+
$download_dir = download_dir
130134

131135
logger.debug("download dir is #{download_dir}")
132136

@@ -148,6 +152,9 @@ def load_packages_from_lists(dir)
148152

149153
if options[:os]
150154
load_packages_from_lists 'os'
155+
#if options[:'cross-linux-aarch64']
156+
# load_packages_from_lists 'os-linux-aarch64'
157+
#end
151158
end
152159

153160
if not RUBY_VERSION =~ /^3\./
@@ -166,6 +173,27 @@ def load_packages_from_lists(dir)
166173
raise "rustup not found" if rustup.nil?
167174
end
168175

176+
if options[:'cross-linux-aarch64']
177+
# ZIG
178+
# FIXME(kp2pml30) check platform
179+
require_relative './src/webget.rb'
180+
download_to = download_dir.join('zig.tar.xz')
181+
read_file(
182+
uri: URI("https://ziglang.org/builds/zig-linux-x86_64-0.14.0-dev.2238+1db8cade5.tar.xz"),
183+
path: download_to
184+
)
185+
extract_tar(download_dir.join('zig'), download_to)
186+
187+
# openssl
188+
download_to = download_dir.join('openssl-aarch.tar.xz')
189+
read_file(
190+
uri: URI("http://mirror.archlinuxarm.org/aarch64/core/openssl-3.4.0-1-aarch64.pkg.tar.xz"),
191+
path: download_to,
192+
use_ssl: false,
193+
)
194+
extract_tar(download_dir.join('cross-aarch64-libs'), download_to, trim_first: false)
195+
end
196+
169197
if options[:rust]
170198
puts `cd "#{root}" && #{rustup} show active-toolchain || #{rustup} toolchain install`
171199
run_command(rustup, 'component', 'add', 'rustfmt', chdir: root)
@@ -181,10 +209,19 @@ def load_packages_from_lists(dir)
181209
run_command(rustup, 'component', 'add', '--toolchain', cur_toolchain, 'rust-std', chdir: ext_path)
182210
end
183211

212+
if options[:rust] and options[:'cross-linux-aarch64']
213+
ext_path = root.join('executor')
214+
cur_toolchain = run_command(rustup, 'show', 'active-toolchain', chdir: ext_path)
215+
cur_toolchain = cur_toolchain.lines.map { |l| l.strip }.filter { |l| l.size != 0 }.last
216+
cur_toolchain = /^([a-zA-Z0-9\-_]+)/.match(cur_toolchain)[1]
217+
logger.debug("installing for toolchain #{cur_toolchain}")
218+
run_command(rustup, 'target', 'add', '--toolchain', cur_toolchain, 'aarch64-unknown-linux-gnu', chdir: ext_path)
219+
run_command(rustup, 'component', 'add', '--toolchain', cur_toolchain, 'rust-std', chdir: ext_path)
220+
end
221+
184222
if options[:wasi]
185223
logger.debug("downloading runners dependencies")
186-
src = Pathname.new(__FILE__).parent.join('src', 'wasi-sdk.rb').read
187-
eval(src, binding)
224+
require_relative './src/wasi-sdk.rb'
188225

189226
if find_executable('docker').nil?
190227
logger.error("docker is required")
Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,26 @@
1-
wasi_dir = download_dir.join('wasi-sdk-24')
1+
wasi_dir = $download_dir.join('wasi-sdk-24')
22

3-
def read_file(uri:, path:)
4-
loop {
5-
request = Net::HTTP::Get.new(uri)
6-
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
7-
http.request(request) { |response|
8-
case response
9-
when Net::HTTPRedirection
10-
uri = URI(response['location'])
11-
when Net::HTTPSuccess
12-
File.open(path, 'wb') { |file|
13-
response.read_body { |chunk|
14-
file.write chunk
15-
}
16-
}
17-
return
18-
else
19-
raise "invalid response #{response}"
20-
end
21-
}
22-
end
23-
}
24-
end
3+
require_relative './webget.rb'
254

265
if wasi_dir.exist?()
27-
logger.info("wasi-sdk-24 already exists")
6+
$logger.info("wasi-sdk-24 already exists")
287
else
29-
download_to = download_dir.join('wasi-sdk-24.tar.gz')
8+
download_to = $download_dir.join('wasi-sdk-24.tar.gz')
309
if not download_to.exist?
31-
logger.info("downloading wasi-sdk-24 to #{download_to}")
32-
Net::HTTP.start("github.com") do |http|
33-
plat = case PLATFORM
34-
when 'amd64'
35-
'x86_64'
36-
when 'aarch64'
37-
'arm64'
38-
else
39-
raise "unsupported platform"
40-
end
41-
puts "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-#{plat}-#{OS}.tar.gz"
42-
read_file(
43-
uri: URI("https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-#{plat}-#{OS}.tar.gz"),
44-
path: download_to
45-
)
46-
end
47-
end
48-
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(download_to))
49-
begin
50-
tar_extract.rewind
51-
dest = nil
52-
g_name = Proc.new { |v|
53-
names = v.split('/')
54-
wasi_dir.join(*names[1...names.size])
55-
}
56-
tar_extract.each do |entry|
57-
if entry.full_name == '././@LongLink'
58-
dest = g_name.call(entry.read.strip)
59-
next
60-
end
61-
dest ||= g_name.call(entry.full_name)
62-
if entry.directory?
63-
dest.mkpath
64-
elsif entry.file?
65-
File.open dest, "wb" do |f|
66-
f.write entry.read
67-
end
68-
FileUtils.chmod entry.header.mode, dest, :verbose => false
69-
elsif entry.header.typeflag == '2' #Symlink!
70-
File.symlink entry.header.linkname, dest
71-
end
72-
dest = nil
10+
$logger.info("downloading wasi-sdk-24 to #{download_to}")
11+
plat = case PLATFORM
12+
when 'amd64'
13+
'x86_64'
14+
when 'aarch64'
15+
'arm64'
16+
else
17+
raise "unsupported platform"
7318
end
74-
ensure
75-
tar_extract.close
19+
puts "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-#{plat}-#{OS}.tar.gz"
20+
read_file(
21+
uri: URI("https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-#{plat}-#{OS}.tar.gz"),
22+
path: download_to
23+
)
7624
end
25+
extract_tar(wasi_dir, download_to)
7726
end
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
def read_file(uri:, path:, use_ssl: true)
2+
if path.exist?
3+
$logger.info("already exists #{path}, skipping download")
4+
return
5+
end
6+
$logger.info("downloading #{uri} => #{path}")
7+
loop {
8+
request = Net::HTTP::Get.new(uri)
9+
Net::HTTP.start(uri.host, uri.port, :use_ssl => use_ssl) do |http|
10+
http.request(request) { |response|
11+
case response
12+
when Net::HTTPRedirection
13+
uri = URI(response['location'])
14+
when Net::HTTPSuccess
15+
File.open(path, 'wb') { |file|
16+
response.read_body { |chunk|
17+
file.write chunk
18+
}
19+
}
20+
return
21+
else
22+
raise "invalid response #{response}"
23+
end
24+
}
25+
end
26+
}
27+
end
28+
29+
def extract_tar(base_dir, path, trim_first: true)
30+
if base_dir.exist?
31+
$logger.info("already exists #{base_dir}, skipping extraction")
32+
return
33+
end
34+
base_dir.mkpath
35+
if path.to_s.end_with?('.xz')
36+
begin
37+
Gem::Specification::find_by_name('ruby-xz')
38+
rescue Gem::LoadError
39+
require 'rubygems/commands/install_command'
40+
cmd = Gem::Commands::InstallCommand.new
41+
cmd.handle_options ['--user-install', 'ruby-xz']
42+
begin
43+
cmd.execute
44+
rescue Gem::SystemExitException
45+
end
46+
end
47+
require 'xz'
48+
decomp = path.sub_ext('.tar')
49+
XZ::decompress_file(path, decomp)
50+
tar_extract = Gem::Package::TarReader.new(File.open(decomp))
51+
else
52+
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(path))
53+
end
54+
begin
55+
tar_extract.rewind
56+
dest = nil
57+
g_name = Proc.new { |v|
58+
names = v.split('/')
59+
if trim_first
60+
base_dir.join(*names[1...names.size])
61+
else
62+
base_dir.join(*names)
63+
end
64+
}
65+
tar_extract.each do |entry|
66+
if entry.full_name == '././@LongLink'
67+
dest = g_name.call(entry.read.strip)
68+
next
69+
end
70+
dest ||= g_name.call(entry.full_name)
71+
if entry.directory?
72+
dest.mkpath
73+
elsif entry.file?
74+
File.open dest, "wb" do |f|
75+
f.write entry.read
76+
end
77+
FileUtils.chmod entry.header.mode, dest, :verbose => false
78+
elsif entry.header.typeflag == '2' #Symlink!
79+
File.symlink entry.header.linkname, dest
80+
end
81+
dest = nil
82+
end
83+
ensure
84+
tar_extract.close
85+
end
86+
end

0 commit comments

Comments
 (0)