Integrate libuv into Wren.
- Add a script that downloads and compiles libuv. - Hook that up to the Makefile so it pulls down libuv on build. - Add a separate "vm" target that just builds the VM library and skips libuv. - Link to libuv when compiling the CLI. - Update the XCode project to link to libuv too. Linux and Windows support isn't done yet, but it should be pretty straightforward to add to the Python script.
This commit is contained in:
Executable
+115
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Downloads and compiles libuv.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
LIB_UV_VERSION = "v1.6.1"
|
||||
LIB_UV_DIR = "build/libuv"
|
||||
|
||||
def ensure_dir(dir):
|
||||
"""Creates dir if not already there."""
|
||||
|
||||
if os.path.isdir(dir):
|
||||
return
|
||||
|
||||
os.makedirs(dir)
|
||||
|
||||
|
||||
def download_libuv():
|
||||
"""Clones libuv into build/libuv and checks out the right version."""
|
||||
|
||||
# Delete it if already there so we ensure we get the correct version if the
|
||||
# version number in this script changes.
|
||||
if os.path.isdir(LIB_UV_DIR):
|
||||
print("Cleaning output directory...")
|
||||
shutil.rmtree(LIB_UV_DIR)
|
||||
|
||||
ensure_dir("build")
|
||||
|
||||
print("Cloning libuv...")
|
||||
run([
|
||||
"git", "clone", "--quiet", "--depth=1",
|
||||
"https://github.com/libuv/libuv.git",
|
||||
LIB_UV_DIR
|
||||
])
|
||||
|
||||
print("Getting tags...")
|
||||
run([
|
||||
"git", "fetch", "--quiet", "--depth=1", "--tags"
|
||||
], cwd=LIB_UV_DIR)
|
||||
|
||||
print("Checking out libuv " + LIB_UV_VERSION + "...")
|
||||
run([
|
||||
"git", "checkout", "--quiet", LIB_UV_VERSION
|
||||
], cwd=LIB_UV_DIR)
|
||||
|
||||
# TODO: Pin gyp to a known-good commit. Update a previously downloaded gyp
|
||||
# if it doesn't match that commit.
|
||||
print("Downloading gyp...")
|
||||
run([
|
||||
"git", "clone", "--quiet", "--depth=1",
|
||||
"https://chromium.googlesource.com/external/gyp.git",
|
||||
LIB_UV_DIR + "/build/gyp"
|
||||
])
|
||||
|
||||
|
||||
def build_libuv_mac():
|
||||
# Create the XCode project.
|
||||
run([
|
||||
"python", LIB_UV_DIR + "/gyp_uv.py", "-f", "xcode"
|
||||
])
|
||||
|
||||
# Compile it.
|
||||
# TODO: Support debug builds too.
|
||||
run([
|
||||
"xcodebuild",
|
||||
"-ARCHS=\"x86_64\"",
|
||||
"-project", LIB_UV_DIR + "/uv.xcodeproj",
|
||||
"-configuration", "Release",
|
||||
"-target", "All"
|
||||
])
|
||||
|
||||
|
||||
def build_libuv_linux():
|
||||
# TODO: Implement me!
|
||||
print("Building for Linux not implemented yet.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def build_libuv_windows():
|
||||
# TODO: Implement me!
|
||||
print("Building for Windows not implemented yet.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def build_libuv():
|
||||
if platform.system() == "Darwin":
|
||||
build_libuv_mac()
|
||||
elif platform.system() == "Linux":
|
||||
build_libuv_linux()
|
||||
elif platform.system() == "Windows":
|
||||
build_libuv_windows()
|
||||
else:
|
||||
print("Unsupported platform: " + platform.system())
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def run(args, cwd=None):
|
||||
"""Spawn a process to invoke [args] and mute its output."""
|
||||
subprocess.check_output(args, cwd=cwd, stderr=subprocess.STDOUT)
|
||||
|
||||
|
||||
def main():
|
||||
download_libuv()
|
||||
build_libuv()
|
||||
|
||||
|
||||
main()
|
||||
+13
-5
@@ -98,19 +98,27 @@ CLI_OBJECTS := $(addprefix $(BUILD_DIR)/cli/, $(notdir $(CLI_SOURCES:.c=.o)))
|
||||
VM_OBJECTS := $(addprefix $(BUILD_DIR)/vm/, $(notdir $(VM_SOURCES:.c=.o)))
|
||||
TEST_OBJECTS := $(patsubst test/api/%.c, $(BUILD_DIR)/test/%.o, $(TEST_SOURCES))
|
||||
|
||||
LIB_UV_DIR := build/libuv
|
||||
|
||||
# Targets ---------------------------------------------------------------------
|
||||
|
||||
# Builds the VM libraries and CLI interpreter.
|
||||
all: bin/$(WREN) lib/lib$(WREN).a lib/lib$(WREN).$(SHARED_EXT)
|
||||
all: vm cli
|
||||
|
||||
# Builds just the VM libraries.
|
||||
vm: lib/lib$(WREN).a lib/lib$(WREN).$(SHARED_EXT)
|
||||
|
||||
# Builds just the CLI interpreter.
|
||||
cli: bin/$(WREN)
|
||||
|
||||
# Builds the API test executable.
|
||||
test: $(BUILD_DIR)/test/$(WREN)
|
||||
|
||||
# Command-line interpreter.
|
||||
bin/$(WREN): $(CLI_OBJECTS) $(VM_OBJECTS)
|
||||
bin/$(WREN): $(CLI_OBJECTS) $(VM_OBJECTS) $(LIB_UV_DIR)/build/Release/libuv.a
|
||||
@printf "%10s %-30s %s\n" $(CC) $@ "$(C_OPTIONS)"
|
||||
@mkdir -p bin
|
||||
@$(CC) $(CFLAGS) -o $@ $^ -lm
|
||||
@$(CC) $(CFLAGS) -L$(LIB_UV_DIR)/build/Release -l uv -o $@ $^ -lm
|
||||
|
||||
# Static library.
|
||||
lib/lib$(WREN).a: $(VM_OBJECTS)
|
||||
@@ -134,7 +142,7 @@ $(BUILD_DIR)/test/$(WREN): $(TEST_OBJECTS) $(VM_OBJECTS) $(BUILD_DIR)/cli/io.o $
|
||||
$(BUILD_DIR)/cli/%.o: src/cli/%.c $(CLI_HEADERS) $(VM_HEADERS)
|
||||
@printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
||||
@mkdir -p $(BUILD_DIR)/cli
|
||||
@$(CC) -c $(CFLAGS) -Isrc/include -o $@ $(FILE_FLAG) $<
|
||||
@$(CC) -c $(CFLAGS) -Isrc/include -I$(LIB_UV_DIR)/include -o $@ $(FILE_FLAG) $<
|
||||
|
||||
# VM object files.
|
||||
$(BUILD_DIR)/vm/%.o: src/vm/%.c $(VM_HEADERS)
|
||||
@@ -148,4 +156,4 @@ $(BUILD_DIR)/test/%.o: test/api/%.c $(VM_HEADERS)
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) -c $(CFLAGS) -Isrc/include -Isrc/cli -o $@ $(FILE_FLAG) $<
|
||||
|
||||
.PHONY: all test
|
||||
.PHONY: all cli test vm
|
||||
|
||||
Reference in New Issue
Block a user