Skip to content

Commit

Permalink
Merge pull request #408 from savi-lang/add/macos-kernel-framework-hea…
Browse files Browse the repository at this point in the history
…ders

Add Kernel.framework/Headers search path for C compilation on MacOS.
  • Loading branch information
jemc authored Oct 9, 2022
2 parents 50a8081 + ed7fe1a commit a713c32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions spec/integration/run-ffi-link-c-files/vendor/mylib_add.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
// We included some headers mainly to test that the compiler can find them.
// We may or may not actually use features of them here.

int mylib_add(int a, int b)
{
Expand Down
3 changes: 3 additions & 0 deletions spec/integration/run-ffi-link-c-files/vendor/mylib_sub.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
// We included some headers mainly to test that the compiler can find them.
// We may or may not actually use features of them here.

int mylib_sub(int a, int b)
{
Expand Down
9 changes: 7 additions & 2 deletions src/savi/compiler/binary_object.cr
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Savi::Compiler::BinaryObject
out_args
end

def self.each_sysroot_include_path(ctx)
def self.each_sysroot_include_path(ctx, target)
Binary.new.each_sysroot_lib_path(ctx, ctx.code_gen.target_info) { |lib_path|
include_path = File.join(lib_path, "include")
yield include_path if Dir.exists?(include_path)
Expand All @@ -223,13 +223,18 @@ class Savi::Compiler::BinaryObject

include_path = File.join(lib_path, "../../include")
yield include_path if Dir.exists?(include_path)

if target.macos?
include_path = File.join(lib_path, "../../System/Library/Frameworks/Kernel.framework/Headers")
yield include_path if Dir.exists?(include_path)
end
}
end

def self.invoke_c_compiler(ctx, target, c_file_path) : LLVM::Module
compile_args = get_default_c_flags(ctx)
compile_args << "-triple" << ctx.code_gen.target_machine.triple
each_sysroot_include_path(ctx) { |include_path|
each_sysroot_include_path(ctx, target) { |include_path|
compile_args << "-isystem" << include_path
}
compile_args << "-fgnuc-version=4.2.1" if target.macos?
Expand Down

0 comments on commit a713c32

Please sign in to comment.