Skip to content

Commit 45166f0

Browse files
authored
Merge pull request #58 from nature-lang/feature/darwin
feat: support darwin architecture
2 parents 7f18825 + 215e05f commit 45166f0

File tree

141 files changed

+27576
-1654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+27576
-1654
lines changed

CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
2727
set(BUILD_TYPE "debug")
2828
# add_compile_definitions(NATURE_DEBUG)
2929
add_compile_definitions(DEBUG_LIR)
30-
# add_compile_definitions(DEBUG_ASM)
30+
add_compile_definitions(DEBUG_ASM)
3131
add_compile_definitions(DEBUG_PARSER)
3232
# add_compile_definitions(DEBUG_INTERVAL)
33+
# add_compile_definitions(DEBUG_MACHO)
3334
add_compile_definitions(ASSERT_ERROR)
3435
# set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O2")
3536
message("cmake type is debug")
@@ -40,20 +41,23 @@ configure_file("${PROJECT_SOURCE_DIR}/config/config.h.in" "${PROJECT_SOURCE_DIR}
4041
aux_source_directory(${PROJECT_SOURCE_DIR}/cmd CMD)
4142
file(GLOB_RECURSE SRC ${PROJECT_SOURCE_DIR}/src/*.c)
4243
aux_source_directory(${PROJECT_SOURCE_DIR}/utils UTILS)
44+
aux_source_directory(${PROJECT_SOURCE_DIR}/utils/ymal UTILS)
4345

4446
# include 搜索路径, 有了这个就不需要在 add_executable 中声明 .h 文件了
47+
include_directories(./include)
4548
include_directories(.)
4649

4750
add_executable(nature main.c ${SRC} ${CMD} ${UTILS})
4851
target_link_libraries(nature m) # 链接数学计算库
4952

50-
enable_testing()
51-
add_subdirectory(tests)
52-
add_subdirectory(runtime EXCLUDE_FROM_ALL)
53-
5453
# custom golang build package
5554
set(PACKAGE_BINARY_NAME npkg)
5655
set(GOBIN /usr/local/go/bin/go)
56+
set(PACKAGE_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_BINARY_NAME})
57+
58+
enable_testing()
59+
add_subdirectory(tests)
60+
add_subdirectory(runtime EXCLUDE_FROM_ALL)
5761

5862
add_custom_target(${PACKAGE_BINARY_NAME} ALL
5963
COMMAND GOOS=${CMAKE_SYSTEM_NAME} GOARCH=${CMAKE_SYSTEM_PROCESSOR} ${GOBIN} build -o ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_BINARY_NAME} ${PROJECT_SOURCE_DIR}/package/main.go

cmake/cross.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ endif ()
1717

1818
# 写入到系统变量中
1919
if (CMAKE_SYSTEM_NAME MATCHES darwin)
20-
message("add compile def __DARWIN")
20+
add_definitions(-D_XOPEN_SOURCE=700)
21+
add_definitions(-D_DARWIN_C_SOURCE)
22+
23+
add_compile_options(-Wno-format)
24+
add_compile_options(-Wno-return-type)
25+
26+
message("add compile def __DARWIN, D_XOPEN_SOURCE, D_DARWIN_C_SOURCE")
2127
add_compile_definitions(__DARWIN=1)
2228
else ()
23-
message("add compile def __LINUX")
29+
add_definitions(-D_GNU_SOURCE)
30+
31+
message("add compile def __LINUX, D_GNU_SOURCE, ")
2432
add_compile_definitions(__LINUX=1)
2533
endif ()
2634

cmake/darwin-amd64-toolchain.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
set(CMAKE_C_COMPILER cc)
22
set(CMAKE_CXX_COMPILER c++)
33

4+
set(CMAKE_C_STANDARD 11)
5+
46
set(CMAKE_SYSTEM_NAME darwin)
57
set(CMAKE_SYSTEM_PROCESSOR amd64)
68

9+
710
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format -Wno-return-type")

cmd/root.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ void cmd_entry(int argc, char **argv) {
2323
}
2424

2525
struct option long_options[] = {
26-
{"archive", no_argument, NULL, 0},
27-
{"output", required_argument, NULL, 'o'},
28-
{NULL, 0, NULL, 0}};
26+
{"archive", no_argument, NULL, 0},
27+
{"output", required_argument, NULL, 'o'},
28+
{NULL, 0, NULL, 0}};
2929

3030
int option_index = 0;
3131
int c;
3232

33-
bool libmain = false;
33+
bool is_archive = false;
3434

3535
// -o 参数解析
3636
// --archive 参数解析 int c;
@@ -61,19 +61,16 @@ void cmd_entry(int argc, char **argv) {
6161
}
6262
case 0: {
6363
assert(strcmp(long_options[option_index].name, "archive") == 0);
64-
libmain = true;
64+
is_archive = true;
6565
break;
6666
}
6767
default:
6868
break;
6969
}
7070
}
7171

72-
if (libmain) {
73-
build_libmain(build_file);
74-
} else {
75-
build(build_file);
76-
}
72+
73+
build(build_file, is_archive);
7774
}
7875

7976
#endif//NATURE_ROOT_H

0 commit comments

Comments
 (0)