Kaynağa Gözat

Move to llvm version 10 from llvm version 8

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 5 yıl önce
ebeveyn
işleme
c95a99009c

+ 6 - 7
.github/workflows/release.yml

@@ -16,7 +16,7 @@ jobs:
     - name: Rust stable
       run: rustup default stable
     - name: Compile stdlib
-      run: clang-8 --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
+      run: clang-10 --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
       working-directory: ./stdlib
     - name: Build
       run: cargo build --verbose --release
@@ -36,15 +36,14 @@ jobs:
     steps:
     - name: Checkout sources
       uses: actions/checkout@v2
-    - name: Add LLVM to Path
-      run: echo "::add-path::c:\llvm80\bin"
     - name: Download LLVM
-      run: curl -sS -o c:\llvm.zip https://solang.io/download/llvm80.zip
+      run: curl -sS -o c:\llvm.zip https://solang.io/download/llvm10.0.zip
     - name: Extract LLVM
-      # unzip exists but always exits with code 1
-      run: powershell Expand-Archive c:\llvm.zip -DestinationPath c:\
+      run: unzip c:\llvm.zip -d c:/
+    - name: Add LLVM to Path
+      run: echo "::add-path::c:\llvm10.0\bin"
     - name: Compile stdlib
-      run: clang --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
+      run: clang-10 --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
       working-directory: ./stdlib
     - name: Build
       run: cargo build --release --verbose

+ 5 - 6
.github/workflows/test.yml

@@ -25,7 +25,7 @@ jobs:
     - name: Rust stable
       run: rustup default stable
     - name: Compile stdlib
-      run: clang-8 --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
+      run: clang-10 --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
       working-directory:  ./stdlib
     - name: Build
       run: cargo build --verbose
@@ -38,13 +38,12 @@ jobs:
     steps:
     - name: Checkout sources
       uses: actions/checkout@v2
-    - name: Add LLVM to Path
-      run: echo "::add-path::c:\llvm80\bin"
     - name: Download LLVM
-      run: curl -sS -o c:\llvm.zip https://solang.io/download/llvm80.zip
+      run: curl -sS -o c:\llvm.zip https://solang.io/download/llvm10.0.zip
     - name: Extract LLVM
-      # unzip exists but always exits with code 1
-      run: powershell Expand-Archive c:\llvm.zip -DestinationPath c:\
+      run: unzip c:\llvm.zip -d c:/
+    - name: Add LLVM to Path
+      run: echo "::add-path::c:\llvm10.0\bin"
     - name: Compile stdlib
       run: clang --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
       working-directory: ./stdlib

+ 1 - 1
Cargo.toml

@@ -26,7 +26,7 @@ tiny-keccak = "2.0"
 serde_json = "1.0"
 serde = "1.0"
 serde_derive = { version = "1.0" }
-inkwell = { version = "0.1.0-llvm8sample", features = ["target-webassembly", "llvm8-0"] }
+inkwell = { version = "0.1.0-llvm10sample", features = ["target-webassembly", "llvm10-0"] }
 blake2-rfc = "0.2.18"
 phf = { version = "0.8", features = ["macros"] }
 unicode-xid = "0.2.0"

+ 1 - 1
Dockerfile

@@ -13,7 +13,7 @@ COPY src src/src/
 COPY stdlib src/stdlib/
 COPY build.rs Cargo.toml src/
 WORKDIR /src/stdlib/
-RUN clang-8 --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
+RUN clang-10 --target=wasm32 -c -emit-llvm -O3 -ffreestanding -fno-builtin -Wall stdlib.c sha3.c substrate.c ripemd160.c
 
 WORKDIR /src/
 RUN cargo build --release

+ 17 - 16
docs/installing.rst

@@ -64,8 +64,9 @@ The latest solang release is  on `crates.io <https://crates.io/crates/solang>`_.
 
 Building Solang from source
 ---------------------------
+
 In order to build solang from source, you will need rust 1.42.0 or higher,
-and llvm version 8 or higher with the WebAssembly target enabled.
+and llvm version 10 with the WebAssembly target enabled.
 
 So see if you have the correct version of rust, simply execute:
 
@@ -92,7 +93,7 @@ To make sure you have the correct version of the llvm libraries installed, first
 
   llvm-config --version
 
-The output should be 8.0 or higher. Then check if the WebAssembly target is enabled by running:
+The output should be 10.0. Then check if the WebAssembly target is enabled by running:
 
 .. code-block:: bash
 
@@ -113,7 +114,7 @@ If you do not have the llvm libraries installed then you can either install
 your distribution llvm packages, or compile your own. Compiling your own is helpful
 if you want to do Solang development.
 
-Any build of llvm 8.0, with the WebAssembly target enabled, should work.
+Any build of llvm 10.0, with the WebAssembly target enabled, should work.
 Note that you will also need clang; the Solidity standard library is written in C,
 and is compiled to wasm by clang. The version of clang *must* be the same as the
 version of llvm.
@@ -122,29 +123,29 @@ version of llvm.
 Installing LLVM on Ubuntu
 _________________________
 
-You will need ubuntu 18.04 with backports or later. Just run:
+You will need ubuntu 20.04 (focal) or later. Just run:
 
 .. code-block:: bash
 
-	sudo apt install curl llvm-8-dev clang-8 git zlib1g-dev cargo
+	sudo apt install curl llvm-10-dev clang-10 git zlib1g-dev cargo
 
 Installing LLVM on Debian
 _________________________
 
-You will need Debian Buster with `buster-backports` enabled, or testing.
+You will need at least Debian Bullseye (testing).
 
 .. code-block:: bash
 
-	sudo apt-get install -y llvm-8-dev clang-8 libz-dev pkg-config libssl-dev git
+	sudo apt-get install llvm-10-dev clang-10 zlib1g-dev pkg-config libssl-dev git cargo
 
 Installing LLVM on Fedora
 _________________________
 
-You will need Fedora 30 or later. Running the following:
+You will need Fedora 32 or later. Running the following:
 
 .. code-block:: bash
 
-	sudo dnf install cargo llvm8.0-static llvm8.0-devel zlib-devel clang libffi-devel openssl-devel
+	sudo dnf install cargo llvm-static llvm-devel zlib-devel clang libffi-devel openssl-devel git
 
 .. _llvm-from-source:
 
@@ -152,13 +153,13 @@ Installing LLVM on Windows
 __________________________
 
 A pre-built version of llvm, specifically configured for Solang, is available on
-`solang.io <https://solang.io/download/llvm80.zip>`_. This binary is built using
+`solang.io <https://solang.io/download/llvm10.0.zip>`_. This binary is built using
 the dockerfile used in `Building LLVM using Windows Containers`_. After unzipping
 the file, add the bin directory to your path.
 
 .. code-block::
 
-	set PATH=%PATH%;C:\llvm80\bin
+	set PATH=%PATH%;C:\llvm10.0\bin
 
 Building LLVM from source
 ___________________________
@@ -180,18 +181,18 @@ First if all clone the llvm repository:
 	git clone git://github.com/llvm/llvm-project
 	cd llvm-project
 
-Now switch to the 8.0 release branch:
+Now switch to the 10.0 release branch:
 
 .. code-block:: bash
 
-	git checkout -b release_8.x origin/release/8.x
+	git checkout -b release_10.x origin/release/10.x
 
 Now run cmake to create the makefiles. Replace the *installdir* argument to ``CMAKE_INSTALL_PREFIX`` with with a directory where you would like to have llvm installed, and then run the build:
 
 .. code-block:: bash
 
 	cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_ENABLE_PROJECTS=clang  \
-		-DLLVM_ENABLE_TERMINFO=Off -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+		-DLLVM_ENABLE_TERMINFO=Off -DCMAKE_BUILD_TYPE=Release \
 		-DCMAKE_INSTALL_PREFIX=installdir -B build llvm
 	cmake --build build --target install
 
@@ -219,7 +220,7 @@ is in Solang github repo. Simply run the dockerfile:
 
 	docker build -f build-llvm-linux.dockerfile .
 
-This will take a few hours. The result will be an image with llvm compressed in ``/llvm80.tar.bz2``.
+This will take a few hours. The result will be an image with llvm compressed in ``/llvm10.0.tar.bz2``.
 
 
 Building LLVM using Windows Containers
@@ -237,4 +238,4 @@ is in Solang github repo. Simply run the dockerfile:
 
 	docker build -f build-llvm-windows.dockerfile .
 
-This will take a few hours. The result will be an image with llvm compressed in ``c:\llvm80.zip``.
+This will take a few hours. The result will be an image with llvm compressed in ``c:\llvm10.0.zip``.

+ 3 - 5
scripts/build-llvm-linux.dockerfile

@@ -8,14 +8,12 @@ RUN git clone git://github.com/llvm/llvm-project
 
 WORKDIR /llvm-project
 
-RUN git checkout -b release_8.x origin/release/8.x
-
-RUN sed -i '7 a #include <string>' llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+RUN git checkout -b release_10.x origin/release/10.x
 
 RUN cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_ENABLE_PROJECTS=clang  \
     -DLLVM_ENABLE_TERMINFO=Off -DLLVM_TARGETS_TO_BUILD=WebAssembly \
-    -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=/llvm80 -B build llvm
+    -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=/llvm10.0 -B build llvm
 
 RUN cmake --build build --target install
 
-RUN tar jcf /llvm80.tar.bz2 /llvm80/
+RUN tar jcf /llvm10.0.tar.bz2 /llvm10.0/

+ 13 - 14
scripts/build-llvm-windows.dockerfile

@@ -1,12 +1,14 @@
 # escape=`
 
-# Use the latest Windows Server Core image with .NET Framework 4.8.
+# Use the latest Windows Server Core image
 FROM mcr.microsoft.com/windows/servercore:ltsc2019
 
 SHELL [ "powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]
 
-# Download the Build Tools bootstrapper.
-ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
+# Download Visual Studio Build Tools 16.6. This should match the version on github actions virtual environment.
+# https://docs.microsoft.com/en-us/visualstudio/releases/2019/history
+# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md
+ADD https://download.visualstudio.microsoft.com/download/pr/067fd8d0-753e-4161-8780-dfa3e577839e/4776935864d08e66183acd5b3647c9616da989c60afbfe100d4afc459f7e5785/vs_BuildTools.exe C:\TEMP\vs_buildtools.exe
 
 # Install Visual Studio Build Tools
 RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
@@ -26,9 +28,9 @@ ADD https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.
 RUN C:\TEMP\rustup-init.exe -y
 
 # Git
-ADD https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/MinGit-2.12.2.2-64-bit.zip C:\TEMP\MinGit.zip
+ADD https://github.com/git-for-windows/git/releases/download/v2.28.0.windows.1/MinGit-2.28.0-64-bit.zip C:\TEMP\MinGit-2.28.0-64-bit.zip
 
-RUN Expand-Archive C:\TEMP\MinGit.zip -DestinationPath c:\MinGit
+RUN Expand-Archive C:\TEMP\MinGit-2.28.0-64-bit.zip -DestinationPath c:\MinGit
 
 # LLVM Build requires Python
 # Newer versions than v3.5.4 fail due to https://github.com/microsoft/vcpkg/issues/6988
@@ -44,30 +46,27 @@ RUN Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force ; `
 
 # Invoke-BatchFile retains the environment after executing so we can set it up more permanently
 RUN Invoke-BatchFile C:\BuildTools\vc\Auxiliary\Build\vcvars64.bat ; `
-	$path = $env:path + ';c:\MinGit\cmd;C:\Users\ContainerAdministrator\.cargo\bin;C:\llvm80\bin;C:\Python' ; `
+	$path = $env:path + ';c:\MinGit\cmd;C:\Users\ContainerAdministrator\.cargo\bin;C:\llvm10.0\bin;C:\Python' ; `
 	Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name Path -Value $path ; `
 	Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name LIB -Value $env:LIB ; `
 	Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name INCLUDE -Value $env:INCLUDE ; `
 	Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name LIBPATH -Value $env:LIBPATH ;
 
-RUN git clone -b release/8.x git://github.com/llvm/llvm-project
+RUN git clone -b release/10.x git://github.com/llvm/llvm-project
 
 WORKDIR \llvm-project
 
-# Stop cmake from re-generating build system ad infinitum and fix missing include
-RUN Add-Content llvm\CMakeLists.txt 'set(CMAKE_SUPPRESS_REGENERATION 1)' ; `
-	$header = Get-Content .\llvm\include\llvm\Demangle\MicrosoftDemangleNodes.h ; `
-	$header[8] = '#include <string>' ; `
-	$header | Set-Content .\llvm\include\llvm\Demangle\MicrosoftDemangleNodes.h
+# Stop cmake from re-generating build system ad infinitum
+RUN Add-Content llvm\CMakeLists.txt 'set(CMAKE_SUPPRESS_REGENERATION 1)' ;
 
 # All llvm targets should be enabled or inkwell refused to link
 RUN cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_ENABLE_PROJECTS=clang `
-	-DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=C:/llvm80 `
+	-DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=C:/llvm10.0 `
 	-B build llvm
 RUN cmake --build build --target install
 
 WORKDIR \
 
-RUN Compress-Archive -Path C:\llvm80 -DestinationPath C:\llvm80.zip
+RUN Compress-Archive -Path C:\llvm10.0 -DestinationPath C:\llvm10.0.zip
 
 RUN Remove-Item -Path \llvm-project,C:\TEMP -Recurse -Force

+ 4 - 6
scripts/ci.dockerfile

@@ -8,13 +8,11 @@ RUN git clone git://github.com/llvm/llvm-project
 
 WORKDIR /llvm-project
 
-RUN git checkout -b release_8.x origin/release/8.x
-
-RUN sed -i '7 a #include <string>' llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+RUN git checkout -b release_10.x origin/release/10.x
 
 RUN cmake -G Ninja -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_ENABLE_PROJECTS=clang  \
     -DLLVM_ENABLE_TERMINFO=Off -DLLVM_TARGETS_TO_BUILD=WebAssembly \
-    -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=/llvm80 -B build llvm
+    -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=/llvm10.0 -B build llvm
 
 RUN cmake --build build --target install
 
@@ -29,6 +27,6 @@ RUN apt-get autoclean
 # Get Rust
 RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
 
-COPY --from=builder /llvm80 /llvm80/
+COPY --from=builder /llvm10.0 /llvm10.0/
 
-ENV PATH="/llvm80/bin:/root/.cargo/bin:${PATH}"
+ENV PATH="/llvm10.0/bin:/root/.cargo/bin:${PATH}"

+ 1 - 1
src/emit/ethabiencoder.rs

@@ -1405,7 +1405,7 @@ impl EthAbiEncoder {
                     v.into_pointer_value(),
                     contract
                         .module
-                        .get_type("struct.vector")
+                        .get_struct_type("struct.vector")
                         .unwrap()
                         .ptr_type(AddressSpace::Generic),
                     "string",

+ 2 - 3
src/emit/ewasm.rs

@@ -7,7 +7,6 @@ use std::str;
 use inkwell::attributes::{Attribute, AttributeLoc};
 use inkwell::context::Context;
 use inkwell::module::Linkage;
-use inkwell::types::BasicType;
 use inkwell::types::IntType;
 use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue};
 use inkwell::AddressSpace;
@@ -1367,7 +1366,7 @@ impl TargetRuntime for EwasmTarget {
             length,
             contract
                 .module
-                .get_type("struct.vector")
+                .get_struct_type("struct.vector")
                 .unwrap()
                 .size_of()
                 .unwrap()
@@ -1391,7 +1390,7 @@ impl TargetRuntime for EwasmTarget {
             p,
             contract
                 .module
-                .get_type("struct.vector")
+                .get_struct_type("struct.vector")
                 .unwrap()
                 .ptr_type(AddressSpace::Generic),
             "string",

+ 10 - 8
src/emit/mod.rs

@@ -886,7 +886,7 @@ impl<'a> Contract<'a> {
                     .build_pointer_cast(
                         v.into_pointer_value(),
                         self.module
-                            .get_type("struct.vector")
+                            .get_struct_type("struct.vector")
                             .unwrap()
                             .ptr_type(AddressSpace::Generic),
                         "vector",
@@ -1683,7 +1683,7 @@ impl<'a> Contract<'a> {
                     .build_pointer_cast(
                         v.into_pointer_value(),
                         self.module
-                            .get_type("struct.vector")
+                            .get_struct_type("struct.vector")
                             .unwrap()
                             .ptr_type(AddressSpace::Generic),
                         "vector",
@@ -1841,7 +1841,7 @@ impl<'a> Contract<'a> {
                     .build_pointer_cast(
                         v.into_pointer_value(),
                         self.module
-                            .get_type("struct.vector")
+                            .get_struct_type("struct.vector")
                             .unwrap()
                             .ptr_type(AddressSpace::Generic),
                         "vector",
@@ -3060,7 +3060,7 @@ impl<'a> Contract<'a> {
                         );
                         let vec_size = self
                             .module
-                            .get_type("struct.vector")
+                            .get_struct_type("struct.vector")
                             .unwrap()
                             .size_of()
                             .unwrap()
@@ -3205,7 +3205,7 @@ impl<'a> Contract<'a> {
                         );
                         let vec_size = self
                             .module
-                            .get_type("struct.vector")
+                            .get_struct_type("struct.vector")
                             .unwrap()
                             .size_of()
                             .unwrap()
@@ -4732,7 +4732,7 @@ impl<'a> Contract<'a> {
             }
             ast::Type::Enum(n) => self.llvm_type(&self.ns.enums[*n].ty),
             ast::Type::String | ast::Type::DynamicBytes => {
-                self.module.get_type("struct.vector").unwrap()
+                self.module.get_struct_type("struct.vector").unwrap().into()
             }
             ast::Type::Array(base_ty, dims) => {
                 let ty = self.llvm_var(base_ty);
@@ -4741,13 +4741,15 @@ impl<'a> Contract<'a> {
 
                 let mut aty = match dims.next().unwrap() {
                     Some(d) => ty.array_type(d.to_u32().unwrap()),
-                    None => return self.module.get_type("struct.vector").unwrap(),
+                    None => return self.module.get_struct_type("struct.vector").unwrap().into(),
                 };
 
                 for dim in dims {
                     match dim {
                         Some(d) => aty = aty.array_type(d.to_u32().unwrap()),
-                        None => return self.module.get_type("struct.vector").unwrap(),
+                        None => {
+                            return self.module.get_struct_type("struct.vector").unwrap().into()
+                        }
                     }
                 }
 

+ 5 - 5
src/emit/substrate.rs

@@ -894,7 +894,7 @@ impl SubstrateTarget {
                         v.into_pointer_value(),
                         contract
                             .module
-                            .get_type("struct.vector")
+                            .get_struct_type("struct.vector")
                             .unwrap()
                             .ptr_type(AddressSpace::Generic),
                         "string",
@@ -2079,7 +2079,7 @@ impl TargetRuntime for SubstrateTarget {
             length,
             contract
                 .module
-                .get_type("struct.vector")
+                .get_struct_type("struct.vector")
                 .unwrap()
                 .size_of()
                 .unwrap()
@@ -2103,7 +2103,7 @@ impl TargetRuntime for SubstrateTarget {
             p,
             contract
                 .module
-                .get_type("struct.vector")
+                .get_struct_type("struct.vector")
                 .unwrap()
                 .ptr_type(AddressSpace::Generic),
             "string",
@@ -2671,7 +2671,7 @@ impl TargetRuntime for SubstrateTarget {
             length,
             contract
                 .module
-                .get_type("struct.vector")
+                .get_struct_type("struct.vector")
                 .unwrap()
                 .size_of()
                 .unwrap()
@@ -2695,7 +2695,7 @@ impl TargetRuntime for SubstrateTarget {
             p,
             contract
                 .module
-                .get_type("struct.vector")
+                .get_struct_type("struct.vector")
                 .unwrap()
                 .ptr_type(AddressSpace::Generic),
             "string",

BIN
stdlib/ripemd160.bc


BIN
stdlib/sha3.bc


BIN
stdlib/stdlib.bc


BIN
stdlib/substrate.bc