Bläddra i källkod

Merge pull request #912 from odin-lang/llvm-api-ci-changes

Update Makefile to compile with LLVM C API
gingerBill 4 år sedan
förälder
incheckning
b8327ad00d
6 ändrade filer med 31 tillägg och 12 borttagningar
  1. 7 3
      .github/workflows/ci.yml
  2. 10 6
      .github/workflows/nightly.yml
  3. 7 1
      Makefile
  4. 1 1
      core/os/stat_unix.odin
  5. 5 0
      examples/demo/demo.odin
  6. 1 1
      src/llvm_backend.cpp

+ 7 - 3
.github/workflows/ci.yml

@@ -7,9 +7,11 @@ jobs:
     steps:
       - uses: actions/checkout@v1
       - name: Download LLVM
-        run: sudo apt-get install llvm
+        run: sudo apt-get install llvm-11 clang-11 llvm
       - name: build odin
         run: make release
+      - name: Odin run -llvm-api
+        run: ./odin run examples/demo/demo.odin -llvm-api
       - name: Odin run
         run: ./odin run examples/demo/demo.odin
       - name: Odin check
@@ -20,14 +22,16 @@ jobs:
       - uses: actions/checkout@v1
       - name: Download LLVM and setup PATH
         run: |
-          brew install llvm
+          brew install llvm@11
           echo "/usr/local/opt/llvm/bin" >> $GITHUB_PATH
           TMP_PATH=$(xcrun --show-sdk-path)/user/include
           echo "CPATH=$TMP_PATH" >> $GITHUB_ENV
       - name: build odin
         run: make release
       - name: Odin run
-        run: ./odin run examples/demo/demo.odin
+        run: |
+          ./odin run examples/demo/demo.odin
+          ./odin run examples/demo/demo.odin -llvm-api
       - name: Odin check
         run: ./odin check examples/demo/demo.odin -vet
   build_windows:

+ 10 - 6
.github/workflows/nightly.yml

@@ -49,9 +49,11 @@ jobs:
     steps:
       - uses: actions/checkout@v1
       - name: (Linux) Download LLVM
-        run: sudo apt-get install llvm
+        run: sudo apt-get install llvm-11 clang-11 llvm
       - name: build odin
         run: make nightly
+      - name: Odin run -llvm-api
+        run: ./odin run examples/demo/demo.odin -llvm-api
       - name: Odin run
         run: ./odin run examples/demo/demo.odin
       - name: Copy artifacts
@@ -78,6 +80,8 @@ jobs:
           echo "CPATH=$TMP_PATH" >> $GITHUB_ENV
       - name: build odin
         run: make nightly
+      - name: Odin run -llvm-api
+        run: ./odin run examples/demo/demo.odin -llvm-api
       - name: Odin run
         run: ./odin run examples/demo/demo.odin
       - name: Copy artifacts
@@ -100,26 +104,26 @@ jobs:
       - uses: actions/setup-python@v2
         with:
           python-version: '3.x'
-      
+
       - name: Install B2 CLI
         shell: bash
         run: |
           python -m pip install --upgrade pip
           pip install --upgrade b2
-      
+
       - name: Display Python version
         run: python -c "import sys; print(sys.version)"
-      
+
       - name: Download Windows artifacts
         uses: actions/download-artifact@v1
         with:
           name: windows_artifacts
-      
+
       - name: Download Ubuntu artifacts
         uses: actions/download-artifact@v1
         with:
           name: ubuntu_artifacts
-      
+
       - name: Download macOS artifacts
         uses: actions/download-artifact@v1
         with:

+ 7 - 1
Makefile

@@ -1,13 +1,19 @@
 GIT_SHA=$(shell git rev-parse --short HEAD)
 DISABLED_WARNINGS=-Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined
 LDFLAGS=-pthread -ldl -lm -lstdc++
-CFLAGS=-std=c++11 -DGIT_SHA=\"$(GIT_SHA)\"
+CFLAGS=-std=c++14 -DGIT_SHA=\"$(GIT_SHA)\"
 CC=clang
 
 OS=$(shell uname)
 
 ifeq ($(OS), Darwin)
 	LDFLAGS:=$(LDFLAGS) -liconv
+	CFLAGS:=$(CFLAGS) $(shell llvm-config --cxxflags --ldflags) -DLLVM_BACKEND_SUPPORT -DUSE_NEW_LLVM_ABI_SYSTEM
+	LDFLAGS:=$(LDFLAGS) -lLLVM-C
+endif
+ifeq ($(OS), Linux)
+	CFLAGS:=$(CFLAGS) $(shell llvm-config-11 --cxxflags --ldflags) -DLLVM_BACKEND_SUPPORT -DUSE_NEW_LLVM_ABI_SYSTEM
+	LDFLAGS:=$(LDFLAGS) $(shell llvm-config-11 --libs core native --system-libs)
 endif
 
 all: debug demo

+ 1 - 1
core/os/stat_unix.odin

@@ -61,7 +61,7 @@ _make_time_from_unix_file_time :: proc(uft: Unix_File_Time) -> time.Time {
 _fill_file_info_from_stat :: proc(fi: ^File_Info, s: OS_Stat) {
 	fi.size = s.size;
 	fi.mode = cast(File_Mode)s.mode;
-	fi.is_dir = S_ISDIR(s.mode);
+	fi.is_dir = S_ISDIR(u32(s.mode));
 
 	// NOTE(laleksic, 2021-01-21): Not really creation time, but closest we can get (maybe better to leave it 0?)
 	fi.creation_time = _make_time_from_unix_file_time(s.status_change);

+ 5 - 0
examples/demo/demo.odin

@@ -1109,6 +1109,11 @@ prefix_table := [?]string{
 };
 
 threading_example :: proc() {
+	if ODIN_OS == "darwin" {
+		// TODO: Fix threads on darwin/macOS
+		return;
+	}
+
 	fmt.println("\n# threading_example");
 
 	{ // Basic Threads

+ 1 - 1
src/llvm_backend.cpp

@@ -2323,7 +2323,7 @@ void lb_debug_complete_types(lbModule *m) {
 						for (unsigned i = 0; i < element_count; i++) {
 							u64 offset_in_bits = i;
 							i64 val = bt->BitSet.lower + cast(i64)i;
-							gb_snprintf(name, gb_count_of(name), "%lld", val);
+							gb_snprintf(name, gb_count_of(name), "%lld", cast(long long)val);
 							elements[i] = LLVMDIBuilderCreateBitFieldMemberType(
 								m->debug_builder,
 								scope,