Skip to content

Commit e876ab8

Browse files
committed
darwin: partial merge of Charly Gordon's Darwin patch
1 parent 623905b commit e876ab8

File tree

7 files changed

+49
-19
lines changed

7 files changed

+49
-19
lines changed

common/string_utils.c2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ public fn void split_cmd_args(const char* input, char* cmd, char* args) @(unused
6161
}
6262
}
6363

64+
public fn bool endsWith(const char* text, const char* tail) {
65+
usize len1 = strlen(text);
66+
usize len2 = strlen(tail);
67+
if (len2 > len1) return false;
68+
return (strcmp(&text[len1-len2], tail) == 0);
69+
}
70+

common/target_info.c2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public type Abi enum u8 { Unknown, GNU, GNU_EABI, MACHO, WIN32, Rv32G }
3131
const char*[] system_names = { "unknown", "linux", "darwin", "cygwin" }
3232
static_assert(elemsof(System), elemsof(system_names));
3333

34-
const char*[] arch_names = { "unknown", "i686", "arm", "x86_64", "arm_64", "riscv32" }
34+
const char*[] arch_names = { "unknown", "i686", "arm", "x86_64", "arm64", "riscv32" }
3535
static_assert(elemsof(Arch), elemsof(arch_names));
3636

3737
const char*[] vendor_names = { "unknown", "apple" }

compiler/plugin_mgr.c2

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import file_utils;
2020
import plugin_info;
2121
import string_list;
2222
import string_pool;
23+
import string_utils;
2324

2425
import c_errno local;
2526
import constants;
@@ -29,6 +30,12 @@ import stdio;
2930
import stdlib;
3031
import string local;
3132

33+
#if SYSTEM_DARWIN
34+
const char *lib_ext = ".dylib";
35+
#else
36+
const char *lib_ext = ".so";
37+
#endif
38+
3239
type Plugin struct {
3340
u32 name; // in auxPool
3441
bool is_global;
@@ -97,11 +104,7 @@ fn bool is_plugin(const Dirent* entry) {
97104
const char* filename = entry.d_name;
98105
if (entry.d_type != DT_REG) return false;
99106
if (filename[0] == '.') return false;
100-
usize len = strlen(filename);
101-
if (len < 5) return false;
102-
if (strcmp(&filename[len-3], ".so") != 0) return false;
103-
104-
return true;
107+
return string_utils.endsWith(filename, lib_ext);
105108
}
106109

107110
public fn void Mgr.show(const Mgr* m) {
@@ -140,7 +143,7 @@ fn bool Mgr.loadPlugin(Mgr* m, u32 name, u32 options, bool is_global) {
140143
const char* name_str = m.auxPool.idx2str(name);
141144

142145
char[128] filename;
143-
stdio.sprintf(filename, "lib%s.so", name_str);
146+
stdio.sprintf(filename, "lib%s%s", name_str, lib_ext);
144147

145148
char[constants.Max_path] fullname; // TODO use string_buffer?
146149

env.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ echo 'setting C2 environment'
22
export C2_LIBDIR=~/c2_libs
33
export C2_PLUGINDIR=~/c2_plugins
44
export CC=clang
5-
export CXX=clang++
65
#complete -W '-a -A -b -c -C -d -f -h -m -q -Q -r -s -S -t -T -v --check --create --fast --help --help-recipe --showlibs --showplugins --targets --test' c2c

generator/c_generator.c2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ public fn void build(const char* output_dir)
12991299
i32 retval = process_utils.run_args(dir, "make", LogFile, "-j");
13001300
if (retval != 0) {
13011301
console.error("error during external C compilation");
1302-
console.log("see %s%s for defails", dir, LogFile);
1302+
console.log("see %s%s for details", dir, LogFile);
13031303
}
13041304
}
13051305

generator/c_generator_special.c2

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import file_utils;
2525
import module_list;
2626
import string_buffer;
2727
import string_list;
28+
import target_info;
2829

2930
import string;
3031
import stdio;
@@ -144,12 +145,21 @@ fn void Generator.createMakefile(Generator* gen,
144145
break;
145146
case DynamicLibrary:
146147
out.add("CFLAGS+=-fPIC\n");
147-
stdio.sprintf(target_name, "lib%s.so", gen.target);
148+
if (gen.targetInfo.sys == target_info.System.Darwin) {
149+
stdio.sprintf(target_name, "lib%s.dylib", gen.target);
150+
} else {
151+
stdio.sprintf(target_name, "lib%s.so", gen.target);
152+
}
148153
out.print("all: ../%s\n\n", target_name);
149154

150155
out.print("../%s: $(objects) $(headers)\n", target_name);
151-
out.print("\t\t$(CC) $(LDFLAGS) $(objects) -shared -o ../%s -Wl,-soname,%s.1 -Wl,--version-script=exports.version $(LDFLAGS2)\n",
152-
target_name, target_name);
156+
157+
if (gen.targetInfo.sys == target_info.System.Darwin) {
158+
out.print("\t\t$(CC) $(LDFLAGS) $(objects) -shared -o ../%s $(LDFLAGS2)\n", target_name);
159+
} else {
160+
out.print("\t\t$(CC) $(LDFLAGS) $(objects) -shared -o ../%s -Wl,-soname,%s.1 -Wl,--version-script=exports.version $(LDFLAGS2)\n",
161+
target_name, target_name);
162+
}
153163
break;
154164
}
155165

install_plugins.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#!/bin/sh
2+
3+
if [ $(uname -s) = 'Darwin' ] ; then
4+
LIB_EXT='.dylib'
5+
else
6+
LIB_EXT='.so'
7+
fi
8+
29
set -e
310
mkdir -p $C2_PLUGINDIR
4-
cp output/deps_generator/libdeps_generator.so $C2_PLUGINDIR
5-
cp output/git_version/libgit_version.so $C2_PLUGINDIR
6-
cp output/load_file/libload_file.so $C2_PLUGINDIR
7-
cp output/refs_generator/librefs_generator.so $C2_PLUGINDIR
8-
cp output/shell_cmd/libshell_cmd.so $C2_PLUGINDIR
9-
cp output/unit_test/libunit_test.so $C2_PLUGINDIR
10-
strip $C2_PLUGINDIR/*.so
11+
cp output/deps_generator/libdeps_generator$LIB_EXT $C2_PLUGINDIR
12+
cp output/git_version/libgit_version$LIB_EXT $C2_PLUGINDIR
13+
cp output/load_file/libload_file$LIB_EXT $C2_PLUGINDIR
14+
cp output/refs_generator/librefs_generator$LIB_EXT $C2_PLUGINDIR
15+
cp output/shell_cmd/libshell_cmd$LIB_EXT $C2_PLUGINDIR
16+
cp output/unit_test/libunit_test$LIB_EXT $C2_PLUGINDIR
17+
18+
if [ $(uname -s) != 'Darwin' ] ; then
19+
strip $C2_PLUGINDIR/*$LIB_EXT
20+
fi
21+

0 commit comments

Comments
 (0)