Class: MilkTea::VendoredSteamworks::Library

Inherits:
MilkTea::VendoredCLibrary::Base show all
Defined in:
lib/milk_tea/bindings/vendored_steamworks.rb

Instance Attribute Summary collapse

Attributes inherited from MilkTea::VendoredCLibrary::Base

#include_roots, #name, #source_root

Instance Method Summary collapse

Methods inherited from MilkTea::VendoredCLibrary::Base

#build_flags, #include_flags

Constructor Details

#initialize(root: MilkTea.root) ⇒ Library

Returns a new instance of Library.



18
19
20
21
22
# File 'lib/milk_tea/bindings/vendored_steamworks.rb', line 18

def initialize(root: MilkTea.root)
  @root = Pathname.new(File.expand_path(root.to_s))
  @build_root = MilkTea.writable_root_for(root).join("tmp/vendored-steamworks")
  super(name: "steamworks", source_root: MilkTea.writable_root_for(root).join("third_party/steamworks-sdk-upstream"))
end

Instance Attribute Details

#build_rootObject (readonly)

Returns the value of attribute build_root.



16
17
18
# File 'lib/milk_tea/bindings/vendored_steamworks.rb', line 16

def build_root
  @build_root
end

#rootObject (readonly)

Returns the value of attribute root.



16
17
18
# File 'lib/milk_tea/bindings/vendored_steamworks.rb', line 16

def root
  @root
end

Instance Method Details

#copy_if_present(path) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/milk_tea/bindings/vendored_steamworks.rb', line 52

def copy_if_present(path)
  return unless path && File.file?(path)

  destination = build_root.join(path.basename)
  return destination.to_s if File.file?(destination) && File.mtime(destination) >= File.mtime(path)

  FileUtils.cp(path, destination)
  destination.to_s
end

#host_platformObject



62
63
64
# File 'lib/milk_tea/bindings/vendored_steamworks.rb', line 62

def host_platform
  MilkTea::Steamworks.host_platform
end


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/milk_tea/bindings/vendored_steamworks.rb', line 24

def link_flags(platform: nil)
  resolved_platform = platform || host_platform

  case resolved_platform
  when :windows
    copied_import_library = build_root.join(MilkTea::Steamworks::IMPORT_LIBRARY_BASENAME_BY_PLATFORM.fetch(resolved_platform))
    return [copied_import_library.to_s] if File.file?(copied_import_library)

    ["-L#{build_root}"]
  else
    ["-L#{build_root}"]
  end
end

#prepare!(env: ENV, cc: ENV.fetch("CC", "cc"), platform: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/milk_tea/bindings/vendored_steamworks.rb', line 38

def prepare!(env: ENV, cc: ENV.fetch("CC", "cc"), platform: nil)
  _resolved_cc = resolved_cc(env, cc)
  FileUtils.mkdir_p(build_root)

  resolved_platform = platform || host_platform
  import_library = MilkTea::Steamworks.import_library_path(root:, env:, platform: resolved_platform, bootstrap: true)
  runtime_library = MilkTea::Steamworks.runtime_library_path(root:, env:, platform: resolved_platform, bootstrap: true)

  copy_if_present(import_library)
  copy_if_present(runtime_library)
rescue Errno::ENOENT => e
  raise tool_not_found(e)
end