Skip to content

Commit

Permalink
Merge pull request #186 from blade-lang/odyssey
Browse files Browse the repository at this point in the history
Odyssey to Dev
  • Loading branch information
mcfriend99 authored Aug 14, 2023
2 parents adb833d + 7565ba5 commit 023e6e8
Show file tree
Hide file tree
Showing 463 changed files with 25,614 additions and 403,389 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [ main, dev ]
branches: [ main, dev, odyssey ]
pull_request:
branches: [ main ]

Expand All @@ -20,7 +20,7 @@ jobs:
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.18.x'
cmake-version: '3.25.2'
# - name: Initialize CodeQL
# uses: github/codeql-action/init@v1
# with:
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.18.x'
cmake-version: '3.25.2'
- uses: actions/checkout@v2
- name: Compile
run: |
Expand All @@ -71,7 +71,7 @@ jobs:
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.18.x'
cmake-version: '3.25.2'
- name: Setup WinLibs
uses: bwoodsend/[email protected]
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.18.x'
cmake-version: '3.25.2'
- name: Compile
run: |
sudo apt-get update
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.18.x'
cmake-version: '3.25.2'
- uses: actions/checkout@v2
- name: Compile
run: |
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.18.x'
cmake-version: '3.25.2'
- name: Setup WinLibs
uses: bwoodsend/[email protected]
with:
Expand Down
1 change: 0 additions & 1 deletion BUGS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# BUGS

- `io.TTY.set_raw()` stopped working correctly. Run io test to confirm.
- The `catch` block in `try...catch...` fails outside a global scope or when triggered from a descendant function.
107 changes: 62 additions & 45 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ install dependencies on macOS.
```sh
sudo xcode-select # prompt the user to install Xcode CLT if it is not already installed
sudo brew update
sudo brew install readline cmake
sudo brew install openssl cmake
```

Proceed to the [Configure](#configure) section to configure your CMake build.
Expand All @@ -26,7 +26,7 @@ Install the required dependencies using the `apt` package manager.

```sh
sudo apt update
sudo apt install build-essential libreadline-dev cmake
sudo apt install build-essential libssl-dev cmake
```

Proceed to the [Configure](#configure) section to configure your CMake build.
Expand All @@ -37,89 +37,106 @@ Install the required dependencies using the `pacman` package manager.

```sh
sudo pacman -Sy
sudo pacman -S --needed --noconfirm base-devel readline cmake
sudo pacman -S --needed --noconfirm base-devel openssl cmake
```

Proceed to the [Configure](#configure) section to configure your CMake build.

## Windows
#### RedHat, Fedora, CentOS and their derivatives

Install the required dependencies using the `yum` package manager.

```sh
sudo yum check-update
sudo yum groupinstall 'Development Tools'
sudo yum install -y openssl-devel cmake
```

Proceed to the [Configure](#configure) section to configure your CMake build.

### Windows

> Starting from the 3rd of February 2021, Blade's officially supported compilers for the Windows environment is now the
> TDM-GCC and WinLibs compiler. The decision to change the official compiler from Visual Studio and MSYS2 to TDM-GCC and WinLibs
> is to allow a minial configuration effort while installing Blade as well as to allow us to develop Blade faster as trying to
> WinLibs and TDM-GCC compiler. The decision to change the official compiler from Visual Studio and MSYS2 to WinLibs and TDM-GCC
> is to allow for minial configuration effort while installing Blade as well as to allow us to develop Blade faster as trying to
> be cross-compatible with Visual Studio has proven to slow down the growth of the language and the ecosystem and setting up
> MSYS2 environment to compile Blade is more work than required for either TDM-GCC or WinLibs.
> MSYS2 environment to compile Blade is more work than required for either WinLibs or TDM-GCC.
>
> This also allows us to build valid Blade C extensions on Windows with less hassle.
> Check out the [blade-ext-demo](https://github.com/blade-lang/blade-ext-demo) or any of the extension in the
> [ext](https://github.com/blade-lang/blade/ext) directory for more info on how to write a valid C extension for Blade.
> [packages](https://github.com/blade-lang/blade/packages) directory for more info on how to write a valid C extension for Blade.
### Using TDM-GCC or WinLibs
#### Using WinLibs or TDM-GCC with vcpkg

To install Blade with TDM-GCC or WinLibs, install [TDM-GCC](https://github.com/jmeubank/tdm-gcc/releases/download/v10.3.0-tdm64-2/tdm64-gcc-10.3.0-2.exe)
or [WinLibs](https://github.com/brechtsanders/winlibs_mingw/releases/download/11.2.0-9.0.0-msvcrt-r5/winlibs-x86_64-posix-seh-gcc-11.2.0-mingw-w64-9.0.0-r5.zip)
via the given links. Add TDM-GCC or WinLibs `bin` directory to your environment path. TDM-GCC also allows you to add to path during its installation.
After this, run the following commands from the root of your Blade clone:
To install Blade with WinLibs or TDM-GCC, install
[WinLibs](https://github.com/brechtsanders/winlibs_mingw/releases/download/11.2.0-9.0.0-msvcrt-r5/winlibs-x86_64-posix-seh-gcc-11.2.0-mingw-w64-9.0.0-r5.zip)
or [TDM-GCC](https://github.com/jmeubank/tdm-gcc/releases/download/v10.3.0-tdm64-2/tdm64-gcc-10.3.0-2.exe)
via the given links. Add WinLibs or TDM-GCC `bin` directory to your environment path. TDM-GCC also allows you to add to path during its installation.

```terminal
cmake -B build -DCMAKE_MAKE_PROGRAM=mingw32-make -G "Unix Makefiles"
cmake --build build
Next, install [vcpkg](https://vcpkg.io/en/index.html) following the instruction [here](https://vcpkg.io/en/getting-started.html)
and add `vcpkg` to your environment. After this, run the commands below to install the required dependencies:

```bat
vcpkg install curl:x64-windows libffi:x64-windows openssl:x64-windows
```

If you are on an `x86` system, you can also install the x86 versions of the dependencies using the command:

```shell
vcpkg install curl:x86-windows libffi:x86-windows openssl:x86-windows
```

The `blade` executable can be located in the `build/bin` folder. Simply add that folder to your system path to make it available
system-wide.
## Automated Build and Install (Works on all OSX and Linux)

### Using Visual Studio
```shell
bash <(curl -s https://raw.githubusercontent.com/blade-lang/blade/main/scripts/install.sh)
```

Install the 'Desktop Development with C++' workload using the Visual Studio installer. In the 'Installation Details'
section, make sure 'C++ CMake tools for Windows' checkbox is selected.
## Configure

Should you wish to build from the command line, it is recommended to follow the next few steps in the
'Developer Command Prompt' or 'Developer PowerShell' shell for your version of Visual Studio.
Configure CMake by creating an empty `build` directory in the source root directory, and running the appropriate command.

You may instead prefer to open the project within the IDE, either by right-clicking the folder and selecting 'Open in
Visual Studio' or by choosing the 'Open Folder' option after the splash screen. In this case, you should select the
appropriate startup executable by choosing `blade.exe` from the 'Select Startup Item...' toolbar option in the bar above
the code editor.
> During configure, other required dependencies will be downloaded automatically the first time you do a configure so you should ensure you have a good internet connection if you are running configure for the first time.
### Using MSYS2 and MinGW
### Unix (Linux, macOS)

You may opt to use ported GCC or Clang compilers provided through the MSYS2 project.
```sh
cmake -B build
```

This has only been tested using the `mingw64` toolchain. Open up a new `mingw64` terminal, and ensure you have the
required dependencies:
Optionally, if you have `ninja-build` installed, you may use `-G Ninja` to speed up compile times. For example:

```sh
sudo pacman -Sy
sudo pacman -S --needed --noconfirm mingw-w64-x86_64-{cmake,ninja,toolchain}
cmake -B build -G Ninja
```

Proceed to the [Configure](#configure) section to configure your CMake build, and follow the instructions as if you were
using these tools on a UNIX-like system.
CMake will have generated a Unix Makefiles or Ninja build files in the `build` directory.

## Autoinstall (Works on all OSX and Linux)
If you get an error regards missing `OPENSSL_ROOT_DIR` on macOS add the path to `openssl` which should be located at `/usr/local/opt/openssl` or somewhere in `/opt/homebrew/Cellar/`
(for example `/opt/homebrew/Cellar/openssl@3/3.0.7`). Your configure command should look like this:

```sh
bash <(curl -s https://raw.githubusercontent.com/blade-lang/blade/main/scripts/install.sh)
cmake -B build -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl
```

## Configure
### Windows

Configure CMake by creating an empty `build` directory in the source root directory, and running:
If you are configuring on Windows, you'll need to specify the `make` program as well as the `vcpkg` toolchain file.

```sh
cmake -B build # optionally, if you have `ninja-build` installed, you may use '-G Ninja' to speed up compile times.
```shell
cmake -B build -DCMAKE_MAKE_PROGRAM=mingw32-make -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="${PATH_TO_VCPKG}/scripts/buildsystems/vcpkg.cmake"
```

CMake will have generated a Unix Makefiles, Ninja or Visual Studio project in the `build` directory.
On Windows, it is also mostly common to use the `ninja` build system when available. For this, you'll only need to replace the `mingw32-make` with `ninja` in the command.

## Build

Once the build files have been generated, either change to the `build` directory and run the appropriate `make`, `ninja`
or `msbuild` tool (the latter using the 'Developer Tools Command Prompt' on Windows), or ask CMake to call the correct
Once the build files have been generated, either change to the `build` directory and run the appropriate `make` or
`ninja` tool (the latter using the 'Developer Tools Command Prompt' on Windows), or ask CMake to call the correct
tool for you:

```sh
cmake --build build
```

The `blade` executable can be located in the `build` folder.
Blade will be built into a directory called `blade` which will be located in the `build` folder.
57 changes: 41 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.18)
cmake_minimum_required(VERSION 3.18...3.26)

project(blade C)

Expand All @@ -14,8 +14,6 @@ subdirs(thirdparty packages)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)

set(cfsp " ")

# set build type to release if not specified.
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
Expand Down Expand Up @@ -146,8 +144,6 @@ target_include_directories(libblade PUBLIC "${INCLUDE_GEN_DIR}")
set(LIBRARY_NAME_END "${CMAKE_DEBUG_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(SHARED_LIBRARY_NAME_END "${CMAKE_DEBUG_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")

add_dependencies(libblade pcre2)

set_target_properties(libblade
PROPERTIES
OUTPUT_NAME blade
Expand All @@ -160,8 +156,26 @@ if(MINGW OR MUSL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-overread")
endif()

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(PCRE2_USE_STATIC_LIBS ON)
set(PCRE2_BUILD_TESTS OFF)
set(PCRE2_BUILD_PCRE2GREP OFF)
include(FetchContent)
FetchContent_Declare(pcre2
URL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.42/pcre2-10.42.tar.gz
URL_HASH SHA256=c33b418e3b936ee3153de2c61cc638e7e4fe3156022a5c77d0711bcbb9d64f1f
)
FetchContent_MakeAvailable(pcre2)

if(NOT pcre2_POPULATED)
FetchContent_Populate(pcre2)
add_subdirectory(${pcre2_SOURCE_DIR} ${pcre2_BUILD_DIR})
endif()

# link pcre2
target_link_libraries(libblade PRIVATE pcre2)
target_link_libraries(libblade PRIVATE pcre2-8-static)
target_include_directories(libblade PUBLIC "${pcre2_BINARY_DIR}")

if(UNIX)
# Add linenoise as dependency and link it.
Expand All @@ -183,9 +197,11 @@ endif()
target_link_libraries(blade PRIVATE libblade)

add_custom_target(blade_lib_files ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/libs ${OUTPUT_DIR}/libs
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/tests ${OUTPUT_DIR}/tests
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/benchmarks ${OUTPUT_DIR}/benchmarks
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/libs" "${OUTPUT_DIR}/libs"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/tests" "${OUTPUT_DIR}/tests"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/benchmarks" "${OUTPUT_DIR}/benchmarks"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/apps" "${OUTPUT_DIR}/apps"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/bins" "${OUTPUT_DIR}"
COMMENT "Exporting libs, tests, and benchmark scripts..."
)

Expand All @@ -198,6 +214,8 @@ add_custom_command(TARGET blade POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:blade> ${EXE_FILE}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:libblade> ${LIBRARY_FILE}
COMMAND ${EXE_FILE} "${PROJECT_SOURCE_DIR}/scripts/make_blade.b" "${PROJECT_SOURCE_DIR}"
# The first one is useful for development purposes but doesn't in any way harm release.
COMMAND ${EXE_FILE} "${PROJECT_SOURCE_DIR}/scripts/ast.b" "${PROJECT_SOURCE_DIR}/libs/ast"
COMMAND ${EXE_FILE} "${PROJECT_SOURCE_DIR}/scripts/ast.b" "${OUTPUT_DIR}/libs/ast"
COMMENT "Generating Blade header and copy output..."
)
Expand All @@ -213,13 +231,15 @@ message(STATUS " Build type ...................... : ${buildtype}")
message(STATUS " C compiler flags ................ : ${${CMAKE_C_FLAGS}${cfsp}}${CMAKE_C_FLAGS_${buildtype}}")

# for LTO
include(CheckIPOSupported)
check_ipo_supported(RESULT LTOSupported OUTPUT LTOSupportError)
if(LTOSupported)
message(STATUS " IPO/LTO ......................... : enabled")
set_property(TARGET libblade PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS " IPO/LTO ......................... : not supported: <${LTOSupportError}>")
if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
include(CheckIPOSupported)
check_ipo_supported(RESULT LTOSupported OUTPUT LTOSupportError)
if(LTOSupported)
message(STATUS " IPO/LTO ......................... : enabled")
set_property(TARGET libblade PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS " IPO/LTO ......................... : not supported: <${LTOSupportError}>")
endif()
endif()

# Generating single header file...
Expand Down Expand Up @@ -309,3 +329,8 @@ add_blade_test(blade try 8 "list index 10 out of range")
add_blade_test(blade using 0 "ten\nafter")
add_blade_test(blade var 0 "it works\n20\ntrue")
add_blade_test(blade while 0 "x = 51")

# Replace install() with conditional installation.
macro(install)
_install(${ARGN})
endmacro()
Loading

0 comments on commit 023e6e8

Please sign in to comment.