Sha256: be529942a7174013437a8eb32f209cb51a755586977645f545df1d0daeab6af4

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require "ffi"

def sys(cmd)
  puts "#{cmd}"
  ret = system(cmd)
  raise "ERROR: '#{cmd}' failed" unless ret
  ret
end

desc "Compile shared library"
task :compile_shared do
  wflags = "-Wall -Wextra -Wmissing-prototypes -Wdiv-by-zero"\
    " -Wbad-function-cast -Wcast-align -Wcast-qual -Wfloat-equal"\
    " -Wmissing-declarations -Wnested-externs -Wno-unknown-pragmas"\
    " -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wswitch-enum"\
    " -Wno-type-limits"

  cpuflag = if RUBY_PLATFORM =~ /arm64/ && RUBY_PLATFORM =~ /darwin/
              "-mcpu=apple-m1"
            else
              "-march=native"
            end

  cflags = "-O3 #{cpuflag} -fPIC -fno-exceptions #{wflags}"
  cwd = ::File.expand_path(::File.dirname(__FILE__))

  ::Dir.chdir(cwd) do
    # main.o: main.c
    #   $(CC) -c $(CFLAGS) $< -o $@
    sys("cc -c #{cflags} main.c -o main.o")

    # main.dylib: main.o
    #   $(CC) $< -shared -o $@
    sys("cc main.o -shared -o main.#{::FFI::Platform::LIBSUFFIX}")
  end
end

task :default => [:compile_shared]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-hydrogen-0.1.4 ext/ffi/hydrogen/Rakefile