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

Fix releases for macos builds and unix like release builds #164

Merged
20 changes: 12 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
DIST: 'ce-specific'
NAME: 'ce-specific'
# - ARCH: 'arm64'
# DIST: 'macos-11'
# DIST: 'macos-13'
# NAME: 'darwin'
#- ARCH: 'x86_64' # FIXME:
# DIST: 'macos-11'
# NAME: 'darwin'
- ARCH: 'x86_64'
DIST: 'macos-13'
NAME: 'darwin'
# - ARCH: 'arm64' # TODO
# DIST: 'macos-11'
# DIST: 'macos-13'
# NAME: 'darwin'
name: Build ${{ matrix.NAME }} (${{ matrix.ARCH }}) [${{ matrix.DIST }}]
env:
Expand All @@ -43,6 +43,10 @@ jobs:
if [[ "$OSTYPE" != "darwin"* ]]; then
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
sudo apt install cmake
else
brew install llvm@16
brew install gcc
brew install zstd
fi

- name: Build in Docker
Expand All @@ -55,6 +59,6 @@ jobs:
ls ~/.snowball
ls ~/.snowball/stdlib/

- name: Execute tests
run: |
./bin/Release/snowball test --no-progress
#- name: Execute tests
# run: |
# ./bin/Release/snowball test --no-progress
23 changes: 9 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ if(backtrace_ADDED)
"${backtrace_SOURCE_DIR}/simple.c"
"${backtrace_SOURCE_DIR}/sort.c"
"${backtrace_SOURCE_DIR}/state.c")
set(backtrace_INCLUDE_DIRS "${backtrace_SOURCE_DIR}")

# https://go.googlesource.com/gollvm/+/refs/heads/master/cmake/modules/LibbacktraceUtils.cmake
set(BACKTRACE_SUPPORTED 1)
Expand Down Expand Up @@ -131,14 +132,11 @@ if(backtrace_ADDED)
endif()

CPMAddPackage(
NAME sigsegv
GIT_REPOSITORY "https://git.savannah.gnu.org/git/libsigsegv.git"
GIT_TAG "v2.14"
NAME zstd
GIT_REPOSITORY "https://github.com/facebook/zstd.git"
GIT_TAG "v1.5.5"
DOWNLOAD_ONLY YES)
if(sigsegv_ADDED)
if (APPLE)
message(STATUS "TODO: add sigsegv to the build")
endif()
if(zstd_ADDED)
endif()

message(STATUS ${LLVM_DEFINITIONS})
Expand Down Expand Up @@ -212,12 +210,9 @@ else()
endif()

#add_dependencies(snowballrt backtrace sigsegv)
target_include_directories(snowballrt PRIVATE ${backtrace_SOURCE_DIR} ${sigsegv_SOURCE_DIR})
if(APPLE)
target_link_libraries(snowballrt PRIVATE zstd backtrace)
else()
target_link_libraries(snowballrt PRIVATE zstd backtrace sigsegv)
endif()
target_include_directories(snowballrt PRIVATE ${backtrace_SOURCE_DIR})
target_link_libraries(snowballrt PRIVATE backtrace)
target_include_directories(snowballrt PRIVATE ${backtrace_INCLUDE_DIRS})

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message(STATUS "Changing rpath origin destination (for macos)")
Expand Down Expand Up @@ -291,7 +286,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include> PRIVATE source)
target_include_directories(${PROJECT_NAME} PUBLIC ${LLVM_INCLUDE_DIRS} ${PROJECT_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PUBLIC ${LLVM_INCLUDE_DIRS} ${PROJECT_INCLUDE_DIRS} ${backtrace_INCLUDE_DIRS})
target_link_libraries (${PROJECT_NAME} PUBLIC ${llvm_libs} ${GLIB_LIBRARIES} ${llvm_libraries} ${targets} ${PROJECT_LIBRARIES} snowballrt)

target_compile_definitions(${PROJECT_NAME} PUBLIC ${PROJECT_COMPILE_DEFINITIONS})
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<a href="https://snowball-lang.gitbook.io/docs/"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="">Website</a> · <a href="">Report Bug</a> · <a href="">Request Feature</a>
<a href="">Website</a> · <a href="https://github.com/snowball-lang/snowball/issues">Report Bug</a> · <a href="https://github.com/snowball-lang/snowball/pulls">Request Feature</a>
</p>

<hr>
Expand Down Expand Up @@ -54,11 +54,8 @@ sudo make install -j100

First, you will need a new snowball project. For that, create a new directory and execute the following command:

```
mkdir myProject
cd myProject

snowball init
```sh
snowball new --name myProject
```

### Executing snowball code
Expand Down
14 changes: 7 additions & 7 deletions app/commands/init.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "app/cli.h"

Check failure on line 2 in app/commands/init.h

View workflow job for this annotation

GitHub Actions / cpp-linter

app/commands/init.h:2:10 [clang-diagnostic-error]

'app/cli.h' file not found
#include "utils/logger.h"

#include <chrono>
Expand All @@ -7,10 +7,10 @@
#include <iostream>
#include <sstream>

using namespace std::chrono;

Check warning on line 10 in app/commands/init.h

View workflow job for this annotation

GitHub Actions / cpp-linter

app/commands/init.h:10:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'namespace' is non-const and globally accessible, consider making it const

#ifndef __SNOWBALL_EXEC_INIT_CMD_H_
#define __SNOWBALL_EXEC_INIT_CMD_H_

Check warning on line 13 in app/commands/init.h

View workflow job for this annotation

GitHub Actions / cpp-linter

app/commands/init.h:13:9 [bugprone-reserved-identifier]

declaration uses identifier '__SNOWBALL_EXEC_INIT_CMD_H_', which is a reserved identifier

#define STRINGIFY(...) #__VA_ARGS__

Expand Down Expand Up @@ -40,14 +40,14 @@

#define CONFIGURATION_FILE "sn.toml"

namespace snowball {

Check warning on line 43 in app/commands/init.h

View workflow job for this annotation

GitHub Actions / cpp-linter

app/commands/init.h:43:11 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'snowball' is non-const and globally accessible, consider making it const
namespace app {
namespace commands {

void init_create_cfg(bool yes, std::string entry, app::Options::InitOptions p_opts) {
std::ofstream outfile(CONFIGURATION_FILE);

std::string version = "1.0.0";
std::string version = "0.0.1";

// TODO: ask questions if p_opts.yes is false
std::string toml_result;
Expand All @@ -61,15 +61,15 @@
outfile << toml.str() << std::endl;
outfile.close();

Logger::message("Configuration", FMT("created configuration file (%s)", CONFIGURATION_FILE));
Logger::message("Configuration", FMT("Configured project file (%s)", CONFIGURATION_FILE));
}

// TODO: Output messages
int init(app::Options::InitOptions p_opts) {
auto start = high_resolution_clock::now();

if (p_opts.create_dir) {
Logger::message("Creating", FMT("creating snowball project directory (%s)", p_opts.name.c_str()));
Logger::message("Creating", FMT("Snowball project at directory %s", p_opts.name.c_str()));
if (!fs::exists(p_opts.name)) fs::create_directory(p_opts.name);
fs::current_path(p_opts.name);
}
Expand All @@ -82,11 +82,11 @@
std::getline(std::cin, answer);

if (answer != "y" && answer != "Y") {
Logger::message("Aborted", "snowball project creation");
Logger::message("Aborted", "Snowball project creation");
return 0;
}

Logger::message("Deleting", "deleting all files in the current directory");
Logger::message("Deleting", "All files in the current directory");
for (auto &p : fs::directory_iterator(fs::current_path())) {
fs::remove_all(p);
}
Expand All @@ -96,7 +96,7 @@
init_create_cfg(p_opts.yes, EXECUTABLE_ENTRY, p_opts);
return 0;
} else if (p_opts.lib) {
Logger::message("Initalizing", FMT("creating snowball project [library]", CONFIGURATION_FILE));
Logger::message("Initalizing", FMT("Current project [library]", CONFIGURATION_FILE));

Logger::warning("Library example is not yet supported by "
"current snowball!");
Expand All @@ -108,7 +108,7 @@
outfile << LIBRARY_MAIN << std::endl;
outfile.close();
} else {
Logger::message("Initalizing", FMT("creating snowball project [executable]", CONFIGURATION_FILE));
Logger::message("Initalizing", FMT("Current project [executable]", CONFIGURATION_FILE));

if (!fs::exists("src")) fs::create_directory("src");
if (!p_opts.skip_cfg) init_create_cfg(p_opts.yes, EXECUTABLE_ENTRY, p_opts);
Expand Down
1 change: 1 addition & 0 deletions build_scripts/release_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
else
brew install llvm@16
brew install gcc
brew install zstd
fi

export LLVM_DIR="/usr/local/opt/llvm@16/lib/cmake"
Expand Down
49 changes: 25 additions & 24 deletions runtime/libs/backtrace.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@

#include "backtrace.h"
#include "backtracing.h"
#include "runtime.h"

namespace snowball {

static struct backtrace_state *state = nullptr;

Check warning on line 7 in runtime/libs/backtrace.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

runtime/libs/backtrace.cc:7:32 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'state' is non-const and globally accessible, consider making it const

Check warning on line 7 in runtime/libs/backtrace.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

runtime/libs/backtrace.cc:7:32 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'state' provides global access to a non-const object; consider making the pointed-to data 'const'
static std::mutex stateLock;

Check warning on line 8 in runtime/libs/backtrace.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

runtime/libs/backtrace.cc:8:19 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'stateLock' is non-const and globally accessible, consider making it const

void backtrace_callback(void *data, const char *msg, int errnum) {
printf("[snowball internal error]: backtrace error: %s (%d)\n", msg, errnum);

Check warning on line 11 in runtime/libs/backtrace.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

runtime/libs/backtrace.cc:11:3 [cppcoreguidelines-pro-type-vararg]

do not call c-style vararg functions
abort();
}

int backtrace_full_callback(void *data, uintptr_t pc, const char *filename,

Check warning on line 15 in runtime/libs/backtrace.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

runtime/libs/backtrace.cc:15:5 [modernize-use-trailing-return-type]

use a trailing return type for this function
int lineno, const char *function) {
auto *bt = ((Backtrace *)data);

Check warning on line 17 in runtime/libs/backtrace.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

runtime/libs/backtrace.cc:17:15 [cppcoreguidelines-pro-type-cstyle-cast]

do not use C-style cast to convert between unrelated types
if (!function || !filename) {

Check warning on line 18 in runtime/libs/backtrace.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

runtime/libs/backtrace.cc:18:8 [readability-implicit-bool-conversion]

implicit conversion 'const char *' -> bool
bt->push(pc);
}
bt->push(BacktraceFrame {function, filename, pc, lineno});
Expand Down Expand Up @@ -60,36 +60,37 @@
if (!(snowball::snowball_flags & SNOWBALL_FLAG_DEBUG))
return;

if (getenv("SN_BACKTRACE") == NULL) {
oss << "\n\e[1;37mnote:\e[0m run with \e[1;37m`SN_BACKTRACE=1`\e[0m environment variable to get a backtrace";
return;
}
if (getenv("SN_BACKTRACE") == NULL) {
oss << "\n\e[1;37mnote:\e[0m run with \e[1;37m`SN_BACKTRACE=1`\e[0m environment variable to get a backtrace";
return;
}

oss << "\n";
oss << "\n\033[1mBacktrace (most recent call first):\033[0m\n";
oss << "\n";
oss << "\n\033[1mBacktrace (most recent call first):\033[0m\n";

if (backtrace.frame_count <= 1) {
oss << " (no backtrace available)\n";
return;
}
for (int i = 1; i < backtrace.frame_count; i++) {
BacktraceFrame frame = backtrace.frames[i];
if (!frame.function || !frame.filename) {
oss << " (#" << i << "): \e[1;30m[" << (void*)frame.address << "]\e[0m - ????\n";
continue;
}
// TODO: demangle function names
oss << " (#" << i << "): \e[1;30m[" << (void*)frame.address << "]\e[0m - " << frame.function << "\n";
oss << "\t\tat \e[1;32m" << frame.filename << "\e[1;36m:" << frame.lineno << "\e[0m\n";
}
if (backtrace.frame_count <= 1) {
oss << " (no backtrace available)\n";
return;
}

for (int i = 1; i < backtrace.frame_count; i++) {
BacktraceFrame frame = backtrace.frames[i];
if (!frame.function || !frame.filename) {
oss << " (#" << i << "): \e[1;30m[" << (void*)frame.address << "]\e[0m - ????\n";
continue;
}
// TODO: demangle function names
oss << " (#" << i << "): \e[1;30m[" << (void*)frame.address << "]\e[0m - " << frame.function << "\n";
oss << "\t\tat \e[1;32m" << frame.filename << "\e[1;36m:" << frame.lineno << "\e[0m\n";
}

oss << "\e[0m\n";
//backtrace.pls_free();
oss << "\e[0m\n";
//backtrace.pls_free();
}

void get_backtrace(Backtrace &backtrace) {
if (!(snowball::snowball_flags & SNOWBALL_FLAG_DEBUG)) {
backtrace = Backtrace();
return;
}

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion runtime/libs/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ void end_stack(void* exep) {
} else {
buf << "\033[0m";
}

print_backtrace(base->backtrace, buf);

buf << "\n\n";
Expand Down
2 changes: 1 addition & 1 deletion runtime/libs/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef _SNOWBALL_RUNTIME_EXCEPTIONS_H_
#define _SNOWBALL_RUNTIME_EXCEPTIONS_H_

#include "backtrace.h"
#include "backtracing.h"

namespace snowball {
uint64_t exception_class();
Expand Down
22 changes: 15 additions & 7 deletions runtime/libs/segfault.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
// TODO: Add support for macOS.

#include "runtime.h"
#include "backtrace.h"

#include <sigsegv.h>
#include "backtracing.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>

namespace snowball {

int segfault_handler(void *fault_address, int serious) {
void segfault_handler(int signal, siginfo_t *fault_info, void *arg) {
std::ostringstream buf;
error_log(buf, "Segmentation fault");
buf << ": \033[0mSegmentation fault at address \e[1;37m" << std::hex << (void*)fault_address << std::dec << "\e[0m";
buf << ": \033[0mSegmentation fault at address \e[1;37m" << std::hex << (void*)fault_info->si_addr << std::dec << "\e[0m";

Backtrace base;
get_backtrace(base);
Expand All @@ -24,11 +26,17 @@ int segfault_handler(void *fault_address, int serious) {
fwrite(output.data(), 1, output.size(), stderr);

exit(1);
return 0;
}

void initialize_segfault_handler() {
sigsegv_install_handler(&segfault_handler);
struct sigaction sa;

memset(&sa, 0, sizeof(struct sigaction));
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = segfault_handler;
sa.sa_flags = SA_SIGINFO;

sigaction(SIGSEGV, &sa, NULL);
// TODO: buffer overflow, etc...
}
}
5 changes: 3 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,11 @@ log info "Updating configuration file"

update_config_file "$shell"

printf "\n ${green}snowball-${OS}-${ARCH}${normal} - successfully installed with stdlib\n\n"
printf "\n ${green}snowball-${OS}-${ARCH}${normal} - successfully installed with runtime included\n"
printf " ${green}snowball-stdlib${normal} - standard library for snowball\n\n"

log info "Snowball successfully installed at: $(pwd)"
log info "Snowball is ready to use! type: \`snowball --help\` to check that it works."
echo ""
echo "\n===================== GREAT! =====================\n"
log info "Checkoutt the documentation at: https://snowball-lang.gitbook.io/docs/fundamentals/hello-world"
log info "Happy coding! 🐱"
2 changes: 1 addition & 1 deletion snowball.version.id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x000008
0x000009
2 changes: 1 addition & 1 deletion snowball.version.str
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.8
0.0.9
5 changes: 5 additions & 0 deletions src/ast/cache/FunctionCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ void Functions::performInheritance(types::DefinedType* ty, types::DefinedType* p
for (auto fn : functions) { setFunction(name, fn.function, fn.state); }
}

for (auto f : parent->getFields()) {
ty->addField(f);
}
ty->hasVtable = parent->hasVtable;

return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/ast/types/DefinedType.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ std::int64_t DefinedType::sizeOf() const {
address += (typeAlignment - (address % typeAlignment)) % typeAlignment;
address += typeSize;
}
if (address == 0) address = 1; // prevent 0-sized types
auto alignment = alignmentOf();
address += (address - (address % alignment)) % alignment;
address += (alignment - (address % alignment)) % alignment;
return address + (hasVtable * 8);
address += (hasVtable * 8);
if (address == 0) address = 1; // prevent 0-sized types
return address;
}

std::int64_t DefinedType::alignmentOf() const {
Expand Down
1 change: 0 additions & 1 deletion src/builder/linker/macos/ld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void Linker::constructLinkerArgs(std::string& input, std::string& output, std::v
linkerArgs.push_back("-L/opt/homebrew/lib");
linkerArgs.push_back("-L/usr/local/lib");
linkerArgs.push_back("-L/usr/lib");
linkerArgs.push_back("-L/opt/homebrew/opt/zstd/lib");

// TODO: we might not find it and we will need to search for System.B
linkerArgs.push_back("-lSystem");
Expand Down
4 changes: 2 additions & 2 deletions src/builder/llvm/initializeVariable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace snowball {
namespace codegen {

void LLVMBuilder::initializeVariable(llvm::Value* var, llvm::Type* ty, unsigned int size) {
assert(llvm::isa<llvm::StructType>(ty));
auto llvmType = llvm::cast<llvm::StructType>(ty);
assert(llvm::isa<llvm::StructType>(ty));
auto llvmType = llvm::cast<llvm::StructType>(ty);
auto initializerName =
FMT("__const.default.%s", llvmType->getName().str().c_str());
auto constInitializer = module->getNamedGlobal(initializerName);
Expand Down
Loading
Loading