aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-03-18 16:56:01 +0000
committergingerBill <bill@gingerbill.org>2024-03-18 16:56:01 +0000
commit00344e1323dc6d9baf09c26f31c409f26a0a1cca (patch)
tree5d1fe0eeaabb93f802cb32f709155355b5b5a777
parent009b6f44e379e7644e0f2987663d52186dea5656 (diff)
Add check to people trying to `foreign import` C files.
-rw-r--r--src/checker.cpp16
-rw-r--r--src/string.cpp7
2 files changed, 23 insertions, 0 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index 72c0ae574..fb7d401ab 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -4806,6 +4806,22 @@ gb_internal void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) {
return;
}
+ for (String const &path : fl->fullpaths) {
+ String ext = path_extension(path);
+ if (str_eq_ignore_case(ext, ".c") ||
+ str_eq_ignore_case(ext, ".cpp") ||
+ str_eq_ignore_case(ext, ".cxx") ||
+ str_eq_ignore_case(ext, ".h") ||
+ str_eq_ignore_case(ext, ".hpp") ||
+ str_eq_ignore_case(ext, ".hxx") ||
+ false
+ ) {
+ error(fl->token, "With 'foreign import', you cannot import a %.*s file directory, you must precompile the library and link against that", LIT(ext));
+ break;
+ }
+ }
+
+
// if (fl->collection_name != "system") {
// char *c_str = gb_alloc_array(heap_allocator(), char, fullpath.len+1);
// defer (gb_free(heap_allocator(), c_str));
diff --git a/src/string.cpp b/src/string.cpp
index bd703b2a6..f762dca40 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -104,6 +104,13 @@ gb_internal gb_inline bool str_eq_ignore_case(String const &a, String const &b)
return false;
}
+template <isize N>
+gb_internal gb_inline bool str_eq_ignore_case(String const &a, char const (&b_)[N]) {
+ String b = {cast(u8 *)b_, N-1};
+ return str_eq_ignore_case(a, b);
+}
+
+
gb_internal void string_to_lower(String *s) {
for (isize i = 0; i < s->len; i++) {
s->text[i] = gb_char_to_lower(s->text[i]);