Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to V8 engine instead of Wasmer #28

Merged
merged 53 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a86c658
not entirely working, but getting there
alexdovzhanyn Sep 16, 2024
1b69927
fix path to v8 monolith build
alexdovzhanyn Sep 16, 2024
1610e15
v8 building correctly;
alexdovzhanyn Sep 17, 2024
b1e4305
working v8
alexdovzhanyn Sep 17, 2024
a030edb
add a patch for v8 for c++20 compatibility
alexdovzhanyn Sep 17, 2024
0e5b8a0
clean up makefile
alexdovzhanyn Sep 17, 2024
9f61da5
fix github pipeline
alexdovzhanyn Sep 17, 2024
d5cb7e6
missed a spot
alexdovzhanyn Sep 17, 2024
4208445
install depot tools as part of runner pipeline
alexdovzhanyn Sep 17, 2024
7ca30e1
troubleshoot wasmer dns lookup in runner
alexdovzhanyn Sep 18, 2024
d3e5ec4
try using alternate dns server
alexdovzhanyn Sep 18, 2024
67203f0
try using direct url
alexdovzhanyn Sep 18, 2024
9ef2635
v8 setup in progress
alexdovzhanyn Sep 19, 2024
534beed
build almost fully working
alexdovzhanyn Sep 22, 2024
5401c84
build succeeds, test file fails
alexdovzhanyn Sep 22, 2024
aab501a
v8 running correctly in tests
alexdovzhanyn Sep 23, 2024
3e478b3
working v8 wasm execution. needs cleanup
alexdovzhanyn Sep 24, 2024
b5deaf8
more tests working
alexdovzhanyn Sep 25, 2024
a468701
fix: all tests running
alexdovzhanyn Sep 25, 2024
d415b11
switch to libwee8 instead since its more lightweight
alexdovzhanyn Sep 25, 2024
6933be9
libwee8 working. needs refactor
alexdovzhanyn Sep 26, 2024
38d4e3e
chore: clean up v8 stuff and move into a dedicated runtime singleton
alexdovzhanyn Sep 26, 2024
9b7bb95
chore: finish refactoring codegen tests. still need to get stringrefs…
alexdovzhanyn Sep 27, 2024
803bd8c
Merge branch 'master' of github.com:alexdovzhanyn/ThetaLang into v8-e…
alexdovzhanyn Sep 27, 2024
a005cb8
minor patch
alexdovzhanyn Sep 27, 2024
c09e54c
Merge branch 'master' of github.com:alexdovzhanyn/ThetaLang into v8-e…
alexdovzhanyn Sep 27, 2024
e9c89ce
temp: disable broken stringref test
alexdovzhanyn Sep 27, 2024
829f61b
pull master
alexdovzhanyn Sep 30, 2024
f6cefc8
update workflow files
alexdovzhanyn Oct 1, 2024
b19bb9f
fetch not found?
alexdovzhanyn Oct 1, 2024
61582da
remove which
alexdovzhanyn Oct 1, 2024
6e17044
try outputting depot_tools content
alexdovzhanyn Oct 1, 2024
4d0e201
output github_env var
alexdovzhanyn Oct 1, 2024
9b8b795
try setting path directly
alexdovzhanyn Oct 1, 2024
04c8e20
try change path to persist
alexdovzhanyn Oct 1, 2024
557d076
?
alexdovzhanyn Oct 1, 2024
3b6ce34
show download output
alexdovzhanyn Oct 1, 2024
8029f44
dont use stbuf
alexdovzhanyn Oct 1, 2024
cd940fc
change back to exporting to github_env
alexdovzhanyn Oct 1, 2024
0f8f2e9
what the heck
alexdovzhanyn Oct 1, 2024
66b7081
output directory
alexdovzhanyn Oct 1, 2024
bb47584
tmp
alexdovzhanyn Oct 1, 2024
aa682a4
???
alexdovzhanyn Oct 1, 2024
1e83622
try which again
alexdovzhanyn Oct 1, 2024
cc786f1
echo the path
alexdovzhanyn Oct 1, 2024
130ee8a
try github_path instead
alexdovzhanyn Oct 1, 2024
3c0b243
fix github worker environment variables
alexdovzhanyn Oct 1, 2024
4d78923
fix depot tools path
alexdovzhanyn Oct 1, 2024
f2e7695
dont output wasmer dir in osx build
alexdovzhanyn Oct 1, 2024
e033757
fix: include limits.h for usage in linux readlink
alexdovzhanyn Oct 2, 2024
a7dd367
enable wasm stringref in v8
alexdovzhanyn Oct 2, 2024
712d114
fix: dont use strdup where not necessary
alexdovzhanyn Oct 2, 2024
c4b56af
forgot to include cstring for strcopy
alexdovzhanyn Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ jobs:
- name: Initialize submodules
run: git submodule update --init --recursive

- name: Install Wasmer
run: curl https://get.wasmer.io -sSfL | WASMER_DIR=lib/wasmer sh

- name: Upload Wasmer as artifact
uses: actions/upload-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer
- name: Install depot_tools
run: |
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
echo "${{ github.workspace }}/depot_tools" >> $GITHUB_PATH

- name: Cache CMake build
uses: actions/cache@v3
Expand Down Expand Up @@ -72,12 +68,6 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make LexerTest Executable
run: chmod +x ${{ github.workspace }}/build/LexerTest

Expand All @@ -98,12 +88,6 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make ParserTest Executable
run: chmod +x ${{ github.workspace }}/build/ParserTest

Expand All @@ -124,12 +108,6 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make TypeCheckerTest Executable
run: chmod +x ${{ github.workspace }}/build/TypeCheckerTest

Expand All @@ -149,12 +127,6 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make CodegenTest Executable
run: chmod +x ${{ github.workspace }}/build/CodegenTest

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake on a single platform
name: CMake on OSX

on:
push:
Expand All @@ -20,14 +20,10 @@ jobs:
- name: Initialize submodules
run: git submodule update --init --recursive

- name: Install Wasmer
run: curl https://get.wasmer.io -sSfL | WASMER_DIR=lib/wasmer sh

- name: Upload Wasmer as artifact
uses: actions/upload-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer
- name: Install depot_tools
run: |
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
echo "${{ github.workspace }}/depot_tools" >> $GITHUB_PATH

- name: Cache CMake build
uses: actions/cache@v3
Expand Down Expand Up @@ -69,18 +65,9 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make LexerTest Executable
run: chmod +x ${{ github.workspace }}/build/LexerTest

- name: Output Wasmer directory
run: ls -laR ${{ github.workspace }}/lib/wasmer

- name: Run Lexer Test
working-directory: ${{ github.workspace }}/build
run: ./LexerTest
Expand All @@ -98,12 +85,6 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make ParserTest Executable
run: chmod +x ${{ github.workspace }}/build/ParserTest

Expand All @@ -124,12 +105,6 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make TypeCheckerTest Executable
run: chmod +x ${{ github.workspace }}/build/TypeCheckerTest

Expand All @@ -150,16 +125,9 @@ jobs:
name: build
path: ${{ github.workspace }}/build

- name: Download Wasmer artifacts
uses: actions/download-artifact@v4
with:
name: wasmer
path: ${{ github.workspace }}/lib/wasmer

- name: Make CodegenTest Executable
run: chmod +x ${{ github.workspace }}/build/CodegenTest

- name: Run Codegen Test
working-directory: ${{ github.workspace }}/build
run: ./CodegenTest

93 changes: 51 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
cmake_minimum_required(VERSION 3.10)
project(Theta)

# Set the global C++ standard to 17 for Binaryen by default
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DBUILD_TESTS=OFF -Wno-maybe-uninitialized")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Include ExternalProject module
include(ExternalProject)

# Define source directories
set(SRC_DIR src)
set(LEXER_DIR ${SRC_DIR}/lexer)
set(COMPILER_DIR ${SRC_DIR}/compiler)
set(PARSER_DIR ${SRC_DIR}/parser)
set(EXCEPTIONS_DIR ${SRC_DIR}/exceptions)
set(AST_DIR ${PARSER_DIR}/ast)
set(OPTIMIZATION_DIR ${COMPILER_DIR}/optimization)
set(TEST_DIR test)
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set(TEST_DIR ${CMAKE_SOURCE_DIR}/test)
set(CATCH2_DIR ${TEST_DIR}/catch2)
set(BINARYEN_DIR lib/binaryen)
set(WASMER_DIR lib/wasmer)

# Collect all source files except main.cpp
file(GLOB SRC_FILES
"${SRC_DIR}/*.cpp"
"${LEXER_DIR}/*.cpp"
"${PARSER_DIR}/*.cpp"
"${EXCEPTIONS_DIR}/*.cpp"
"${COMPILER_DIR}/*.cpp"
"${AST_DIR}/*.cpp"
"${OPTIMIZATION_DIR}/*.cpp"
)
set(BINARYEN_DIR ${CMAKE_SOURCE_DIR}/lib/binaryen)
set(V8_DIR ${CMAKE_SOURCE_DIR}/lib/v8) # Path to V8 directory in your project

# Collect all source files recursively from the src directory
file(GLOB_RECURSE SRC_FILES "${SRC_DIR}/*.cpp")
list(REMOVE_ITEM SRC_FILES "${CMAKE_SOURCE_DIR}/theta.cpp")

# Add main source file separately
set(MAIN_SRC "${CMAKE_SOURCE_DIR}/theta.cpp")

# Collect test source files
file(GLOB TEST_SRC_FILES "${TEST_DIR}/*.cpp")
# Add Binaryen
add_subdirectory(${BINARYEN_DIR})

# Add executable for the main program
add_executable(theta ${SRC_FILES} ${MAIN_SRC})
Expand Down Expand Up @@ -65,36 +55,61 @@ else()
target_link_libraries(theta readline)
endif()

# Add Binaryen
add_subdirectory(${BINARYEN_DIR})
# Include directories for Binaryen, catch2, and V8
include_directories(${SRC_DIR} ${CATCH2_DIR} ${BINARYEN_DIR}/src ${V8_DIR}/src/v8/include ${V8_DIR}/src/v8/third_party/wasm-api)

# Add the V8 external project
ExternalProject_Add(
v8_external
PREFIX ${CMAKE_SOURCE_DIR}/lib/v8
SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib/v8
DOWNLOAD_COMMAND
bash ${CMAKE_SOURCE_DIR}/scripts/fetch_v8.sh
UPDATE_COMMAND ""
CONFIGURE_COMMAND
bash -c "DEPOT_TOOLS_UPDATE=0 gclient config https://chromium.googlesource.com/v8/v8.git && cd src/v8 && git checkout branch-heads/12.5 && gclient sync"
BUILD_COMMAND
bash ${CMAKE_SOURCE_DIR}/scripts/build_v8.sh
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
#LOG_DOWNLOAD ON
LOG_CONFIGURE ON
)

# Ensure theta depends on v8_external and the patching step
add_dependencies(theta v8_external)# v8_patched)

# Include directories
include_directories(${SRC_DIR} ${CATCH2_DIR} ${BINARYEN_DIR}/src)
# Create imported target for V8 without INTERFACE_INCLUDE_DIRECTORIES
add_library(v8_libwee8 STATIC IMPORTED GLOBAL)
set_target_properties(v8_libwee8 PROPERTIES
IMPORTED_LOCATION "${V8_DIR}/src/v8/out.gn/wee8/obj/libwee8.a"
)

# Include Wasmer C API
include_directories(${WASMER_DIR}/include)
# Add the V8 include directory directly to the theta target
target_include_directories(theta PRIVATE ${V8_DIR}/src/v8/third_party/wasm-api)

# Link Wasmer library
find_library(WASMER_LIB wasmer HINTS ${WASMER_DIR}/lib)
# Link theta against V8
target_link_libraries(theta v8_libwee8 pthread dl)

# Link Wasmer and other libraries to the main target
target_link_libraries(theta ${WASMER_LIB} binaryen)
# Link Binaryen (with C++17, set earlier as the global standard)
target_link_libraries(theta binaryen)

# Create build directories if they don't exist
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test/fixtures)

# Add Catch2 files to the project
set(CATCH2_FILES ${CATCH2_DIR}/catch_amalgamated.cpp)

# Define a target for Catch2 with main function
# Define a target for Catch2 with the main function
add_library(Catch2Main OBJECT ${CATCH2_FILES})
target_compile_definitions(Catch2Main PUBLIC CATCH_CONFIG_MAIN)

# Add test executables
file(GLOB TEST_SRC_FILES "${TEST_DIR}/*.cpp")
foreach(TEST_SRC ${TEST_SRC_FILES})
get_filename_component(TEST_NAME ${TEST_SRC} NAME_WE)
add_executable(${TEST_NAME} ${TEST_SRC} ${SRC_FILES} $<TARGET_OBJECTS:Catch2Main>)
target_link_libraries(${TEST_NAME} ${WASMER_LIB} readline binaryen)
target_link_libraries(${TEST_NAME} readline binaryen v8_libwee8 pthread dl)
endforeach()

# Custom target to copy fixtures
Expand All @@ -104,9 +119,3 @@ add_custom_target(copy-fixtures ALL

# Install target to create a symlink
install(CODE "execute_process(COMMAND ln -sf ${CMAKE_BINARY_DIR}/theta /usr/local/bin/theta)")

# Link Binaryen to the test targets
foreach(TEST_SRC ${TEST_SRC_FILES})
get_filename_component(TEST_NAME ${TEST_SRC} NAME_WE)
target_link_libraries(${TEST_NAME} binaryen)
endforeach()
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ capsule DataStructures {
```sh
git submodule update --init --recursive
```
3. **Install depot_tools**
```sh
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH:/path/to/depot_tools"
```
3. **Install Wasmer**
```sh
curl https://get.wasmer.io -sSfL | WASMER_DIR=lib/wasmer sh
Expand Down
15 changes: 15 additions & 0 deletions scripts/build_v8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

cd src/v8


# Generate build files
#gn gen out.gn/x64.release --args='dcheck_always_on=false is_component_build=false is_debug=false target_cpu="x64" use_custom_libcxx=false v8_monolithic=true v8_use_external_startup_data=false v8_enable_pointer_compression=false'


# Build V8
#ninja -C out.gn/x64.release v8_monolith #platform v8_init v8_libbase

gn gen out.gn/wee8 --args='is_component_build=false use_custom_libcxx=false v8_enable_fast_mksnapshot=true v8_enable_i18n_support=false v8_use_external_startup_data=false is_debug=false symbol_level=1 v8_enable_handle_zapping=false'

ninja -C out.gn/wee8 wee8
10 changes: 10 additions & 0 deletions scripts/fetch_v8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -x

if [ ! -d v8/build ]; then
echo "Fetching V8..."
fetch v8
else
echo "Syncing V8..."
gclient sync
fi
Loading
Loading