Class: RubyWasm::BuildTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/ruby_wasm/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, target:, src:, toolchain: nil, build_dir: nil, rubies_dir: nil, **options) {|_self| ... } ⇒ BuildTask

Returns a new instance of BuildTask.

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ruby_wasm/rake_task.rb', line 33

def initialize(
  name,
  target:,
  src:,
  toolchain: nil,
  build_dir: nil,
  rubies_dir: nil,
  **options
)
  @name = name
  @target = target
  @build_dir = build_dir || File.join(Dir.pwd, "build")
  @rubies_dir = rubies_dir || File.join(Dir.pwd, "rubies")
  @toolchain = (toolchain || RubyWasm::Toolchain.get(target, @build_dir))

  @libyaml = RubyWasm::LibYAMLProduct.new(@build_dir, @target, @toolchain)
  @zlib = RubyWasm::ZlibProduct.new(@build_dir, @target, @toolchain)
  @wasi_vfs = RubyWasm::WasiVfsProduct.new(@build_dir)
  @source = RubyWasm::BuildSource.new(src, @build_dir)
  @baseruby = RubyWasm::BaseRubyProduct.new(@build_dir, @source)
  @openssl = RubyWasm::OpenSSLProduct.new(@build_dir, @target, @toolchain)

  build_params =
    RubyWasm::BuildParams.new(options.merge(name: name, target: target))

  @crossruby =
    RubyWasm::CrossRubyProduct.new(
      build_params,
      @build_dir,
      @rubies_dir,
      @baseruby,
      @source,
      @toolchain
    )
  yield self if block_given?

  @crossruby.with_libyaml @libyaml
  @crossruby.with_zlib @zlib
  @crossruby.with_wasi_vfs @wasi_vfs
  @crossruby.with_openssl @openssl

  # Rake.verbose can be Object.new by default, so compare with true explicitly.
  executor = RubyWasm::BuildExecutor.new(verbose: Rake.verbose == true)

  desc "Cross-build Ruby for #{@target}"
  task name do
    next if File.exist? @crossruby.artifact
    @crossruby.build(executor)
  end
  namespace name do
    task :remake do
      @crossruby.build(executor, remake: true)
    end
    task :reconfigure do
      @crossruby.build(executor, reconfigure: true)
    end
    task :clean do
      @crossruby.clean(executor)
    end
  end
end

Instance Attribute Details

#baserubyObject (readonly)

BaseRuby product to build.



28
29
30
# File 'lib/ruby_wasm/rake_task.rb', line 28

def baseruby
  @baseruby
end

#crossrubyObject (readonly)

CrossRuby product to build.



31
32
33
# File 'lib/ruby_wasm/rake_task.rb', line 31

def crossruby
  @crossruby
end

#libyamlObject (readonly)

LibYAML product to build.



19
20
21
# File 'lib/ruby_wasm/rake_task.rb', line 19

def libyaml
  @libyaml
end

#nameObject

Name of the task.



6
7
8
# File 'lib/ruby_wasm/rake_task.rb', line 6

def name
  @name
end

#sourceObject (readonly)

Source to build from.



9
10
11
# File 'lib/ruby_wasm/rake_task.rb', line 9

def source
  @source
end

#targetObject (readonly)

Target to build for.



12
13
14
# File 'lib/ruby_wasm/rake_task.rb', line 12

def target
  @target
end

#toolchainObject (readonly)

Toolchain for the build. Defaults to the Toolchain.get for the target.



16
17
18
# File 'lib/ruby_wasm/rake_task.rb', line 16

def toolchain
  @toolchain
end

#wasi_vfsObject (readonly)

wasi-vfs product used by the crossruby.



25
26
27
# File 'lib/ruby_wasm/rake_task.rb', line 25

def wasi_vfs
  @wasi_vfs
end

#zlibObject (readonly)

zlib product to build.



22
23
24
# File 'lib/ruby_wasm/rake_task.rb', line 22

def zlib
  @zlib
end

Instance Method Details

#hexdigestObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ruby_wasm/rake_task.rb', line 95

def hexdigest
  require "digest"
  digest = Digest::SHA256.new
  @source.cache_key(digest)
  @crossruby.cache_key(digest)
  digest << @build_dir
  digest << @rubies_dir
  digest << @target
  digest << @toolchain.name
  digest << @libyaml.name
  digest << @zlib.name
  digest << @openssl.name
  digest << @wasi_vfs.name
  digest.hexdigest
end