aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-30 15:41:37 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-30 15:41:37 -0400
commit38d6189d4335bbcdc38f0c31cf769082b96f22fa (patch)
tree430c133eafe0284d0bc10e7571b42bbf02b34aca
parent494e4ef006cd66ee1d91ea23de9da085bec1e8db (diff)
Further support for .dylib files on mac by changing syntax for library
imports to `use -lfoo` instead of `use foo.so`
-rw-r--r--.gitignore1
-rw-r--r--docs/c-interoperability.md8
-rw-r--r--docs/compilation.md2
-rw-r--r--docs/libraries.md8
-rw-r--r--docs/tomo.1.md2
-rw-r--r--examples/commands/commands.tm2
-rw-r--r--examples/game/raylib.tm2
-rw-r--r--examples/http/http.tm2
-rw-r--r--examples/tomo-install/tomo-install.tm12
-rw-r--r--src/parse.c4
-rw-r--r--src/tomo.c2
11 files changed, 27 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
index 3496cf72..e64daf96 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
.build
*.o
*.so
+*.dylib
*.tm.c
*.tm.h
*.tm.o
diff --git a/docs/c-interoperability.md b/docs/c-interoperability.md
index 3328b39d..3c5bbff1 100644
--- a/docs/c-interoperability.md
+++ b/docs/c-interoperability.md
@@ -6,10 +6,10 @@ make this possible, there are a few tools available.
## Using C Libraries
-In order to link against a compiled shared library, you can use `use libfoo.so`
-to cause Tomo to add `-l:libfoo.so` to the linker flags when compiling your
-final executable. You can also use `use <foo.h>` or `use ./foo.h` to cause Tomo
-to insert a corresponding `#include` when compiling your code.
+In order to link against a compiled shared library, you can use `use -lfoo` to
+cause Tomo to add `-lfoo` to the linker flags when compiling your final
+executable. You can also use `use <foo.h>` or `use ./foo.h` to cause Tomo to
+insert a corresponding `#include` when compiling your code.
You can also `use ./foo.c` or `use ./foo.S` to use C or assembly source files
from inside a Tomo source file.
diff --git a/docs/compilation.md b/docs/compilation.md
index 27161115..8591f677 100644
--- a/docs/compilation.md
+++ b/docs/compilation.md
@@ -24,7 +24,7 @@ graph that looks like this:
```
For a more complicated example, imagine `foo.tm` imports `baz.tm` and both are
-being compiled into a shared library, `libfoo.so`:
+being compiled into a shared library, `libfoo.so` (or `libfoo.dylib` on Mac):
```
+---------------------------------------+
diff --git a/docs/libraries.md b/docs/libraries.md
index 983497fa..551b011a 100644
--- a/docs/libraries.md
+++ b/docs/libraries.md
@@ -119,16 +119,16 @@ Finally, the resulting binary can be executed to actually run the program!
In Tomo, a shared library is built out of a *directory* that contains multiple
`.tm` files. Each `.tm` file in the directory (excluding those that start with
an underscore) will be compiled and linked together to produce a single
-`libwhatever.so` file and `whatever.h` file that can be used by other Tomo
-projects. You can build a library by running `tomo -L dirname/` or `tomo -L` in
-the current directory.
+`libwhatever.so` file (or `libwhatever.dylib` on Mac) and `whatever.h` file
+that can be used by other Tomo projects. You can build a library by running
+`tomo -L dirname/` or `tomo -L` in the current directory.
### Installing
If you additionally add the `-I` flag, Tomo will copy the entire directory
(excluding files and directories that begin with `.` such as `.git`) into
`~/.local/share/tomo/installed/` and create a symbolic link for the library's
-`.so` file in `~/.local/share/tomo/lib/`.
+`.so` file (or `.dylib` file on Mac) in `~/.local/share/tomo/lib/`.
### Using Shared Libraries
diff --git a/docs/tomo.1.md b/docs/tomo.1.md
index c641d0d3..b95a25e4 100644
--- a/docs/tomo.1.md
+++ b/docs/tomo.1.md
@@ -48,7 +48,7 @@ C code, which is then compiled using a C compiler of your choice.
: Compile the input file to an executable.
`-L`, `--library`
-: Compile the input files to a library `.so` file and header.
+: Compile the input files to a shared library file and header.
`-I`, `--install`
: Install the compiled executable or library.
diff --git a/examples/commands/commands.tm b/examples/commands/commands.tm
index be18b776..70a2303b 100644
--- a/examples/commands/commands.tm
+++ b/examples/commands/commands.tm
@@ -1,7 +1,7 @@
# Functions for running system commands
use ./commands.c
-use libunistring.so
+use -lunistring
extern run_command:func(exe:Text, args:[Text], env:{Text,Text}, input:[Byte]?, output:&[Byte]?, error:&[Byte]? -> Int32)
extern command_by_line:func(exe:Text, args:[Text], env:{Text,Text} -> func(->Text?)?)
diff --git a/examples/game/raylib.tm b/examples/game/raylib.tm
index faa6f227..fc0affb9 100644
--- a/examples/game/raylib.tm
+++ b/examples/game/raylib.tm
@@ -1,5 +1,5 @@
# Raylib wrapper for some functions and structs
-use libraylib.so
+use -lraylib
use <raylib.h>
use <raymath.h>
diff --git a/examples/http/http.tm b/examples/http/http.tm
index 2555986f..12203faf 100644
--- a/examples/http/http.tm
+++ b/examples/http/http.tm
@@ -1,6 +1,6 @@
# A simple HTTP library built using CURL
-use libcurl.so
+use -lcurl
use <curl/curl.h>
struct HTTPResponse(code:Int, body:Text)
diff --git a/examples/tomo-install/tomo-install.tm b/examples/tomo-install/tomo-install.tm
index 0205c380..0a6c608d 100644
--- a/examples/tomo-install/tomo-install.tm
+++ b/examples/tomo-install/tomo-install.tm
@@ -61,14 +61,22 @@ func main(paths:[Path]):
curl @curl_flags @url | tar xz -C ~/.local/share/tomo/installed --strip-components=1 --one-top-level=@hash
echo @original_url > ~/.local/share/tomo/installed/@hash/source.url
tomo -L ~/.local/share/tomo/installed/@hash
- ln -f -s ../installed/@hash/lib@hash.so ~/.local/share/tomo/lib/lib@hash.so
+ if [ "`uname -s`" = "Darwin" ]; then
+ ln -f -s ../installed/@hash/lib@hash.dylib ~/.local/share/tomo/lib/lib@hash.dylib
+ else
+ ln -f -s ../installed/@hash/lib@hash.so ~/.local/share/tomo/lib/lib@hash.so
+ fi
`:get_output()!)
if alias:
say($Shell(
set -exuo pipefail
ln -f -s @hash ~/.local/share/tomo/installed/@alias
- ln -f -s lib@hash.so ~/.local/share/tomo/lib/lib@alias.so
+ if [ "`uname -s`" = "Darwin" ]; then
+ ln -f -s lib@hash.dylib ~/.local/share/tomo/lib/lib@alias.dylib
+ else
+ ln -f -s lib@hash.so ~/.local/share/tomo/lib/lib@alias.so
+ fi
):get_output()!)
say("$\[1]Installed $url!$\[]")
diff --git a/src/parse.c b/src/parse.c
index 0eba5d2a..5e2894f0 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -2487,14 +2487,14 @@ PARSER(parse_use) {
int what;
if (name[0] == '<' || ends_with(name, ".h")) {
what = USE_HEADER;
+ } else if (starts_with(name, "-l")) {
+ what = USE_SHARED_OBJECT;
} else if (ends_with(name, ".c")) {
what = USE_C_CODE;
} else if (ends_with(name, ".S") || ends_with(name, ".s")) {
what = USE_ASM;
} else if (starts_with(name, "./") || starts_with(name, "/") || starts_with(name, "../") || starts_with(name, "~/")) {
what = USE_LOCAL;
- } else if (ends_with(name, ".so")) {
- what = USE_SHARED_OBJECT;
} else {
what = USE_MODULE;
diff --git a/src/tomo.c b/src/tomo.c
index 9d53a8f4..e6a6becf 100644
--- a/src/tomo.c
+++ b/src/tomo.c
@@ -625,7 +625,7 @@ void build_file_dependency_graph(Path_t path, Table_t *to_compile, Table_t *to_l
break;
}
case USE_SHARED_OBJECT: {
- Text_t lib = Text$format("-l:%s", use->path);
+ Text_t lib = Text$from_str(use->path);
Table$set(to_link, &lib, ((Bool_t[1]){1}), Table$info(&Text$info, &Bool$info));
break;
}