소스 검색

Merge branch 'master' of https://github.com/odin-lang/Odin

gingerBill 3 년 전
부모
커밋
82110bf487

+ 26 - 4
.github/workflows/ci.yml

@@ -6,8 +6,8 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v1
-      - name: Download LLVM
-        run: sudo apt-get install llvm-11 clang-11 llvm
+      - name: Download LLVM, botan
+        run: sudo apt-get install llvm-11 clang-11 llvm libbotan-2-dev botan
       - name: build odin
         run: make release
       - name: Odin version
@@ -30,13 +30,18 @@ jobs:
           cd tests/core
           make
         timeout-minutes: 10
+      - name: Vendor library tests
+        run: |
+          cd tests/vendor
+          make
+        timeout-minutes: 10
   build_macOS:
     runs-on: macos-latest
     steps:
       - uses: actions/checkout@v1
-      - name: Download LLVM and setup PATH
+      - name: Download LLVM, botan and setup PATH
         run: |
-          brew install llvm@11
+          brew install llvm@11 botan
           echo "/usr/local/opt/llvm@11/bin" >> $GITHUB_PATH
           TMP_PATH=$(xcrun --show-sdk-path)/user/include
           echo "CPATH=$TMP_PATH" >> $GITHUB_ENV
@@ -57,6 +62,16 @@ jobs:
       - name: Odin run -debug
         run: ./odin run examples/demo/demo.odin -debug
         timeout-minutes: 10
+      - name: Core library tests
+        run: |
+          cd tests/core
+          make
+        timeout-minutes: 10
+      - name: Vendor library tests
+        run: |
+          cd tests/vendor
+          make
+        timeout-minutes: 10
   build_windows:
     runs-on: windows-latest
     steps:
@@ -97,6 +112,13 @@ jobs:
           cd tests\core
           call build.bat
         timeout-minutes: 10
+      - name: Vendor library tests
+        shell: cmd
+        run: |
+          call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat
+          cd tests\vendor
+          call build.bat
+        timeout-minutes: 10
       - name: core:math/big tests
         shell: cmd
         run: |

+ 10 - 6
core/os/stat_windows.odin

@@ -115,12 +115,16 @@ cleanpath_strip_prefix :: proc(buf: []u16) -> []u16 {
 	}
 	buf = buf[:N]
 
-	if len(buf) >= 4 {
-		if buf[0] == '\\' &&
-		   buf[1] == '\\' &&
-		   buf[2] == '?'  &&
-		   buf[3] == '\\' {
-			buf = buf[4:]
+	if len(buf) >= 4 && buf[0] == '\\' && buf[1] == '\\' && buf[2] == '?' && buf[3] == '\\' {
+		buf = buf[4:]
+
+		/*
+			NOTE(Jeroen): Properly handle UNC paths.
+			We need to turn `\\?\UNC\synology.local` into `\\synology.local`.
+		*/
+		if len(buf) >= 3 && buf[0] == 'U' && buf[1] == 'N' && buf[2] == 'C' {
+			buf = buf[2:]
+			buf[0] = '\\'
 		}
 	}
 	return buf

+ 8 - 3
core/sys/windows/ws2_32.odin

@@ -39,6 +39,11 @@ foreign ws2_32 {
 		g: GROUP,
 		dwFlags: DWORD,
 	) -> SOCKET ---
+	socket :: proc(
+		af: c_int,
+		type: c_int,
+		protocol: c_int,
+	) -> SOCKET ---
 
 	ioctlsocket :: proc(s: SOCKET, cmd: c_long, argp: ^c_ulong) -> c_int ---
 	closesocket :: proc(socket: SOCKET) -> c_int ---
@@ -76,10 +81,10 @@ foreign ws2_32 {
 	listen :: proc(socket: SOCKET, backlog: c_int) -> c_int ---
 	connect :: proc(socket: SOCKET, address: ^SOCKADDR, len: c_int) -> c_int ---
 	getaddrinfo :: proc(
-		node: ^c_char,
-		service: ^c_char,
+		node: cstring,
+		service: cstring,
 		hints: ^ADDRINFOA,
-		res: ^ADDRINFOA,
+		res: ^^ADDRINFOA,
 	) -> c_int ---
 	freeaddrinfo :: proc(res: ^ADDRINFOA) ---
 	select :: proc(

+ 16 - 1
src/llvm_backend_proc.cpp

@@ -2002,7 +2002,22 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
 						constraints = gb_string_appendc(constraints, regs[i]);
 						constraints = gb_string_appendc(constraints, "}");
 					}
-					
+
+					// The SYSCALL instruction stores the address of the
+					// following instruction into RCX, and RFLAGS in R11.
+					//
+					// RSP is not saved, but at least on Linux it appears
+					// that the kernel system-call handler does the right
+					// thing.
+					//
+					// Some but not all system calls will additionally
+					// clobber memory.
+					//
+					// TODO: FreeBSD is different and will also clobber
+					// R8, R9, and R10.  Additionally CF is used to
+					// indicate an error instead of -errno.
+					constraints = gb_string_appendc(constraints, ",~{rcx},~{r11},~{memory}");
+
 					inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints));
 				}
 				break;

+ 5 - 2
tests/core/Makefile

@@ -1,7 +1,7 @@
 ODIN=../../odin
 PYTHON=$(shell which python3)
 
-all: download_test_assets image_test compress_test strings_test hash_test
+all: download_test_assets image_test compress_test strings_test hash_test crypto_test
 
 download_test_assets:
 	$(PYTHON) download_assets.py
@@ -16,4 +16,7 @@ strings_test:
 	$(ODIN) run strings/test_core_strings.odin
 
 hash_test:
-	$(ODIN) run hash -out=test_hash -o:speed -no-bounds-check
+	$(ODIN) run hash -out=test_hash -o:speed -no-bounds-check
+
+crypto_test:
+	$(ODIN) run crypto -out=crypto_hash -o:speed -no-bounds-check

+ 6 - 0
tests/vendor/Makefile

@@ -0,0 +1,6 @@
+ODIN=../../odin
+
+all: botan_test
+
+botan_test:
+	$(ODIN) run botan -out=botan_hash -o:speed -no-bounds-check

+ 6 - 1
tests/vendor/build.bat

@@ -5,4 +5,9 @@ set PATH_TO_ODIN==..\..\odin
 echo ---
 echo Running vendor:botan tests
 echo ---
-%PATH_TO_ODIN% run botan %COMMON%
+%PATH_TO_ODIN% run botan %COMMON%
+
+echo ---
+echo Running vendor:glfw tests
+echo ---
+%PATH_TO_ODIN% run glfw %COMMON%

+ 45 - 0
tests/vendor/glfw/test_vendor_glfw.odin

@@ -0,0 +1,45 @@
+package test_vendor_glfw
+
+import "core:testing"
+import "core:fmt"
+import "vendor:glfw"
+
+GLFW_MAJOR :: 3
+GLFW_MINOR :: 3
+GLFW_PATCH :: 4
+
+TEST_count := 0
+TEST_fail  := 0
+
+when ODIN_TEST {
+	expect  :: testing.expect
+	log     :: testing.log
+} else {
+	expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
+		fmt.printf("[%v] ", loc)
+		TEST_count += 1
+		if !condition {
+			TEST_fail += 1
+			fmt.println(message)
+			return
+		}
+		fmt.println(" PASS")
+	}
+	log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
+		fmt.printf("[%v] ", loc)
+		fmt.printf("log: %v\n", v)
+	}
+}
+
+main :: proc() {
+	t := testing.T{}
+	test_glfw(&t)
+
+	fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
+}
+
+@(test)
+test_glfw :: proc(t: ^testing.T) {
+	major, minor, patch := glfw.GetVersion()
+	expect(t, major == GLFW_MAJOR && minor == GLFW_MINOR, fmt.tprintf("Expected GLFW.GetVersion: %v.%v.%v, got %v.%v.%v instead", GLFW_MAJOR, GLFW_MINOR, GLFW_PATCH, major, minor, patch))
+}

+ 1 - 1
vendor/glfw/bindings/bindings.odin

@@ -6,7 +6,7 @@ import vk "vendor:vulkan"
 when ODIN_OS == "linux"   { foreign import glfw "system:glfw" } // TODO: Add the billion-or-so static libs to link to in linux
 when ODIN_OS == "windows" { 
 	foreign import glfw { 
-		"lib/glfw3.lib", 
+		"../lib/glfw3_mt.lib",
 		"system:user32.lib", 
 		"system:gdi32.lib", 
 		"system:shell32.lib",