Class: RubyWasm::OpenSSLProduct

Inherits:
AutoconfProduct show all
Defined in:
lib/ruby_wasm/build/product/openssl.rb

Constant Summary collapse

OPENSSL_VERSION =
"3.2.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AutoconfProduct

#system_triplet_args, #tools_args

Constructor Details

#initialize(build_dir, target, toolchain) ⇒ OpenSSLProduct

Returns a new instance of OpenSSLProduct.



10
11
12
13
14
# File 'lib/ruby_wasm/build/product/openssl.rb', line 10

def initialize(build_dir, target, toolchain)
  @build_dir = build_dir
  @target = target
  super(target, toolchain)
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/ruby_wasm/build/product/openssl.rb', line 6

def target
  @target
end

Instance Method Details

#build(executor) ⇒ Object



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
# File 'lib/ruby_wasm/build/product/openssl.rb', line 59

def build(executor)
  return if File.exist?(File.join(install_root, "lib", "libssl.a"))

  executor.mkdir_p File.dirname(product_build_dir)
  executor.rm_rf product_build_dir
  executor.mkdir_p product_build_dir
  tarball_path =
    File.join(product_build_dir, "openssl-#{OPENSSL_VERSION}.tar.gz")
  executor.system "curl",
                  "-o",
                  tarball_path,
                  "-L",
                  "https://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"
  executor.system "tar",
                  "xzf",
                  tarball_path,
                  "-C",
                  product_build_dir,
                  "--strip-components=1"

  executor.system "./Configure", *configure_args, chdir: product_build_dir
  # Use "install_sw" instead of "install" because it tries to install docs and it's very slow.
  # OpenSSL build system doesn't have well support for parallel build, so force -j1.
  executor.system "make",
                  "-j1",
                  "install_dev",
                  "DESTDIR=#{destdir}",
                  chdir: product_build_dir
end

#configure_argsObject



32
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
# File 'lib/ruby_wasm/build/product/openssl.rb', line 32

def configure_args
  args = %w[
    gcc
    -static
    -no-asm
    -no-threads
    -no-afalgeng
    -no-ui-console
    -no-tests
    -no-sock
    -no-dgram
    --libdir=lib
    -Wl,--allow-undefined
  ]
  if @target == "wasm32-unknown-wasi"
    args.concat %w[
                  -D_WASI_EMULATED_SIGNAL
                  -D_WASI_EMULATED_PROCESS_CLOCKS
                  -D_WASI_EMULATED_MMAN
                  -D_WASI_EMULATED_GETPID
                  -DNO_CHMOD
                  -DHAVE_FORK=0
                ]
  end
  args + tools_args
end

#destdirObject



20
21
22
# File 'lib/ruby_wasm/build/product/openssl.rb', line 20

def destdir
  File.join(product_build_dir, "opt")
end

#install_rootObject



24
25
26
# File 'lib/ruby_wasm/build/product/openssl.rb', line 24

def install_root
  File.join(destdir, "usr", "local")
end

#nameObject



28
29
30
# File 'lib/ruby_wasm/build/product/openssl.rb', line 28

def name
  "openssl-#{OPENSSL_VERSION}-#{target}"
end

#product_build_dirObject



16
17
18
# File 'lib/ruby_wasm/build/product/openssl.rb', line 16

def product_build_dir
  File.join(@build_dir, target, "openssl-#{OPENSSL_VERSION}")
end