Skip to content

Commit 3171a90

Browse files
authored
Enable cross-platform support for linux-x86-64, windows-x86-64, macos-x86-64 and macos-arm64
* Provide binaries for Souffle programs using git lfs. * Add dockerized way to build native binaries (except macOS). * Extend CI for Windows and macOS * Update README
1 parent 23d823e commit 3171a90

26 files changed

Lines changed: 335 additions & 135 deletions

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.sh eol=lf
2-
2+
souffle/bin/linux-x86-64/ssa-query-linux-x86-64 filter=lfs diff=lfs merge=lfs -text
3+
souffle/bin/windows-x86-64/ssa-query-windows-x86-64.exe filter=lfs diff=lfs merge=lfs -text

.github/workflows/build.yml

Lines changed: 110 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET
1+
name: .NET (build, test and release if necessary)
22

33
on:
44
push:
@@ -7,14 +7,69 @@ on:
77
branches: [ main ]
88

99
jobs:
10-
build:
10+
build-macos:
11+
runs-on: macos-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
lfs: true
17+
- name: Checkout LFS objects
18+
run: git lfs checkout
19+
- name: Setup Python
20+
uses: actions/setup-python@v2.2.2
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v1
23+
with:
24+
dotnet-version: '6.0.x'
25+
- name: Install Souffle
26+
run: brew install --HEAD souffle-lang/souffle/souffle
27+
- name: Build Souffle program
28+
run: |
29+
cd $GITHUB_WORKSPACE/souffle && CXX=clang++ ./build-souffle-macos-x86-64-arm64.sh
30+
- name: Build dotnet
31+
run: |
32+
dotnet build
33+
dotnet test --verbosity normal
34+
- name: Upload ssa-query-macos-x86-64-arm64
35+
# only do it when it hits the default branch
36+
# this artifact is consumed by the release job
37+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
38+
uses: actions/upload-artifact@v3
39+
with:
40+
name: ssa-query-macos-x86-64-arm64
41+
path: ${{ github.workspace }}/souffle/bin/macos-x86-64-arm64/ssa-query-macos-x86-64-arm64
42+
retention-days: 1
1143

12-
runs-on: ubuntu-18.04
44+
build-windows:
45+
runs-on: windows-latest
46+
steps:
47+
- uses: actions/checkout@v2
48+
with:
49+
fetch-depth: 0
50+
lfs: true
51+
- name: Checkout LFS objects
52+
run: git lfs checkout
53+
- name: Setup Python
54+
uses: actions/setup-python@v2.2.2
55+
- name: Setup .NET
56+
uses: actions/setup-dotnet@v1
57+
with:
58+
dotnet-version: '6.0.x'
59+
- name: Build dotnet
60+
run: |
61+
dotnet build
62+
dotnet test --verbosity normal
1363
64+
build-linux:
65+
runs-on: ubuntu-20.04
1466
steps:
1567
- uses: actions/checkout@v2
1668
with:
1769
fetch-depth: 0
70+
lfs: true
71+
- name: Checkout LFS objects
72+
run: git lfs checkout
1873
- name: Install GitVersion
1974
uses: gittools/actions/gitversion/setup@v0.9.7
2075
with:
@@ -27,18 +82,6 @@ jobs:
2782
configFilePath: ${{ github.workspace }}/.github/GitVersion.yml
2883
- name: Setup Python
2984
uses: actions/setup-python@v2.2.2
30-
- name: Setup mono
31-
run: |
32-
sudo apt install gnupg ca-certificates
33-
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
34-
echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic/snapshots/6.12.0.182 main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
35-
sudo apt update
36-
sudo apt-get install -y mono-devel mono-utils
37-
- name: Setup llvm-config and FileCheck
38-
run: |
39-
sudo apt-get install llvm-10 llvm-10-tools
40-
sudo ln -s /usr/bin/llvm-config-10 /usr/bin/llvm-config
41-
llvm-config --version
4285
- name: Setup .NET
4386
uses: actions/setup-dotnet@v1
4487
with:
@@ -47,35 +90,68 @@ jobs:
4790
uses: jwlawson/actions-setup-cmake@v1.9
4891
with:
4992
cmake-version: '3.21.x'
50-
- name: Setup Souffle
93+
- name: Setup dependencies
94+
run: |
95+
sudo chmod +x ci/install-lit.sh && sudo ./ci/install-lit.sh
96+
sudo chmod +x ci/install-llvm.sh && sudo ./ci/install-llvm.sh
97+
sudo chmod +x ci/install-mono.sh && sudo ./ci/install-mono.sh
98+
- name: Build Souffle programs from scratch
5199
run: |
52-
curl -LJO https://github.com/souffle-lang/souffle/releases/download/2.0.2/souffle_2.0.2-1_amd64.deb
53-
sudo apt-get update
54-
sudo apt-get install mcpp
55-
sudo dpkg -i souffle_2.0.2-1_amd64.deb
56-
- name: Setup LIT
100+
cd $GITHUB_WORKSPACE/souffle && rm -r bin/ && ./build-all-with-docker.sh
101+
- name: Build dotnet
57102
run: |
58-
pip install lit
59-
- name: Configure
103+
dotnet build
104+
dotnet test --verbosity normal
105+
- name: Configure LIT test cases
60106
run: |
61107
mkdir build
62108
cd build
63109
cmake ..
64-
- name: Build
65-
run: |
66-
cd build
67-
make build-souffle
68-
make build-dotnet
69-
- name: Unit test
70-
run: |
71-
cd build
72-
make check-unit-test
73110
- name: Integration test
74111
run: |
75112
cd build
76113
lit integration-test -v
114+
115+
release:
116+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
117+
needs: [build-macos, build-windows, build-linux]
118+
runs-on: ubuntu-20.04
119+
steps:
120+
- uses: actions/checkout@v2
121+
with:
122+
fetch-depth: 0
123+
lfs: true
124+
- name: Checkout LFS objects
125+
run: git lfs checkout
126+
- name: Install GitVersion
127+
uses: gittools/actions/gitversion/setup@v0.9.7
128+
with:
129+
versionSpec: '5.x'
130+
- name: Calculate version
131+
id: gitversion
132+
uses: gittools/actions/gitversion/execute@v0.9.7
133+
with:
134+
useConfigFile: true
135+
configFilePath: ${{ github.workspace }}/.github/GitVersion.yml
136+
- name: Setup Python
137+
uses: actions/setup-python@v2.2.2
138+
- name: Setup .NET
139+
uses: actions/setup-dotnet@v1
140+
with:
141+
dotnet-version: '6.0.x'
142+
- name: Build Souffle programs from scratch
143+
run: |
144+
cd $GITHUB_WORKSPACE/souffle && rm -r bin/ && ./build-all-with-docker.sh
145+
- name: Fetch macos binary
146+
uses: actions/download-artifact@master
147+
with:
148+
name: ssa-query-macos-x86-64-arm64
149+
path: ${{ github.workspace }}/souffle/bin/macos-x86-64-arm64/
150+
- name: Build dotnet
151+
run: |
152+
dotnet build
153+
dotnet test --verbosity normal
77154
- name: Generate nuget packages
78-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
79155
run: |
80-
SOUFFLE_BIN_DIR=$(pwd)/build/bin/souffle dotnet pack net-ssa.sln -o:build/bin/net-ssa/package --include-symbols --include-source /p:Version=${{ steps.gitversion.outputs.AssemblySemVer }} /p:AssemblyVersion=${{ steps.gitversion.outputs.AssemblySemVer }} /p:InformationalVersion=${{ steps.gitversion.outputs.InformationalVersion }} /p:PackageVersion=${{ steps.gitversion.outputs.AssemblySemVer }}
156+
dotnet pack net-ssa.sln -o:build/bin/net-ssa/package --include-symbols --include-source /p:Version=${{ steps.gitversion.outputs.AssemblySemVer }} /p:AssemblyVersion=${{ steps.gitversion.outputs.AssemblySemVer }} /p:InformationalVersion=${{ steps.gitversion.outputs.InformationalVersion }} /p:PackageVersion=${{ steps.gitversion.outputs.AssemblySemVer }}
81157
dotnet nuget push build/bin/net-ssa/package/net-ssa-lib.${{ steps.gitversion.outputs.NuGetVersionV2 }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

.github/workflows/docker-ubuntu.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: docker-ubuntu
1+
name: Docker image
22

33
on:
44
push:
@@ -12,5 +12,12 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
lfs: true
18+
- name: Checkout LFS objects
19+
run: git lfs checkout
1520
- name: Build the Docker image
21+
# On purpose Souffle programs aren't compiled from scratch.
22+
# This is helpful if we forget to update the ones shipped in the repository.
1623
run: cd $GITHUB_WORKSPACE && docker build . --file Dockerfile --tag net-ssa:net-ssa

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
## Custom entries
22

3-
souffle/bins/
43
build/
54

65
## Ignore Visual Studio temporary files, build results, and

CMakeLists.txt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ project (NET_SSA)
33

44
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
55

6-
find_package(Dotnet REQUIRED)
7-
find_package(Souffle REQUIRED)
86
find_package(Python3 REQUIRED COMPONENTS Interpreter)
97
find_package(Mono 6.12 REQUIRED COMPONENTS)
108

@@ -17,22 +15,4 @@ find_program(LLVM_CONFIG NAMES llvm-config REQUIRED HINTS /usr/bin/llvm-config)
1715
message(STATUS "Using llvm-config: ${LLVM_CONFIG}")
1816
exec_program("${LLVM_CONFIG} --bindir" OUTPUT_VARIABLE LLVM_BINDIR)
1917

20-
find_program(CLANGXX NAMES clang++ HINTS ${LLVM_BINDIR})
21-
if(NOT CLANGXX)
22-
message(FATAL_ERROR "clang++ not found in ${LLVM_BINDIR}.")
23-
endif()
24-
25-
add_subdirectory(souffle)
26-
27-
set(NET_SSA_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin/net-ssa)
28-
add_custom_target(build-dotnet
29-
COMMAND ${CMAKE_COMMAND} -E env SOUFFLE_BIN_DIR=${SOUFFLE_BIN_DIR} ${DOTNET_COMMAND} build -o ${NET_SSA_BIN_DIR}
30-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
31-
)
32-
33-
add_custom_target(check-unit-test
34-
COMMAND ${CMAKE_COMMAND} -E env SOUFFLE_BIN_DIR=${SOUFFLE_BIN_DIR} ${DOTNET_COMMAND} test --verbosity normal
35-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
36-
)
37-
3818
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/integration-test/lit.site.cfg.py.in" "${CMAKE_CURRENT_BINARY_DIR}/integration-test/lit.site.cfg.py" @ONLY)

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ FROM $REPO:6.0-focal
33

44
COPY . /net-ssa
55

6-
RUN chmod +x /net-ssa/ci/install-souffle.sh && /net-ssa/ci/install-souffle.sh && \
6+
RUN apt update && \
7+
# Installing Souffle is not strictly required but it is handy in case
8+
# a new analysis is implemented. This environment should be enough for quick prototyping.
9+
chmod +x /net-ssa/ci/install-souffle.sh && /net-ssa/ci/install-souffle.sh && \
710
chmod +x /net-ssa/ci/install-cmake.sh && /net-ssa/ci/install-cmake.sh && \
811
chmod +x /net-ssa/ci/install-lit.sh && /net-ssa/ci/install-lit.sh && \
912
chmod +x /net-ssa/ci/install-llvm.sh && /net-ssa/ci/install-llvm.sh && \
1013
chmod +x /net-ssa/ci/install-mono.sh && /net-ssa/ci/install-mono.sh
1114

12-
RUN mkdir build && \
13-
cd build && \
15+
RUN cd /net-ssa && \
16+
dotnet build && \
17+
dotnet test --verbosity normal && \
18+
mkdir /build && \
19+
cd /build && \
1420
cmake ../net-ssa && \
15-
make build-souffle && \
16-
make build-dotnet && \
17-
make check-unit-test && \
1821
lit ./integration-test -vv

Dockerfile-souffle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ubuntu:20.04
2+
3+
COPY . /net-ssa
4+
5+
RUN apt-get update && apt-get install -y wget && \
6+
chmod +x /net-ssa/ci/install-souffle.sh && /net-ssa/ci/install-souffle.sh && \
7+
chmod +x /net-ssa/ci/install-mingw32.sh && /net-ssa/ci/install-mingw32.sh && \
8+
cd /net-ssa/souffle && CXX=g++ ./build-souffle-linux-x86-64.sh && \
9+
# Copy Souffle's headers for mingw32
10+
cp -r /usr/include/souffle/ /usr/x86_64-w64-mingw32/include/souffle/ && \
11+
cd /net-ssa/souffle && CXX=x86_64-w64-mingw32-g++-posix ./build-souffle-windows-x86-64.sh

README.md

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# net-ssa [![.NET](https://github.com/m-carrasco/net-ssa/actions/workflows/build.yml/badge.svg)](https://github.com/m-carrasco/net-ssa/actions/workflows/build.yml) ![Nuget](https://img.shields.io/nuget/v/net-ssa-lib)
1+
# net-ssa [![.NET (build, test and release if necessary)](https://github.com/m-carrasco/net-ssa/actions/workflows/build.yml/badge.svg?branch=main&event=push)](https://github.com/m-carrasco/net-ssa/actions/workflows/build.yml) [![Docker image](https://github.com/m-carrasco/net-ssa/actions/workflows/docker-ubuntu.yml/badge.svg?branch=main&event=push)](https://github.com/m-carrasco/net-ssa/actions/workflows/docker-ubuntu.yml) ![Nuget](https://img.shields.io/nuget/v/net-ssa-lib)
22

33
Microsoft's high-level programming languages, such as C#, are compiled to CIL bytecode. The instruction set architecture of CIL operates on a stack virtual machine with local variables. CIL instruction's operands are implicit because they are elements in the stack. `net-ssa` provides a register-based intermediate representation for CIL where operands become explicit.
44

@@ -14,40 +14,64 @@ If you have any questions or suggestions, feel free to open an issue to discuss
1414

1515
* [Quick setup](#quick-setup)
1616
* [Build from sources](#build-from-sources)
17+
* [Build native dependencies](#build-native-dependencies)
1718
* [Example: net-ssa-cli](#disassembling-with-net-ssa-cli)
1819
* [Example: net-ssa-lib](#disassembling-with-net-ssa-lib)
1920
* [Contributing](#contributing)
2021
* [Acknowledgements](#acknowledgements)
2122

2223
## Quick setup
24+
2325
It is possible to develop and test `net-ssa` without installing any dependency in your system but [Docker](https://docs.docker.com/get-docker/).
26+
However, it is adviced to compile the project at least once in the host system. This is mainly for downloading dependencies and correctly setting up any IDE.
2427

2528
1. `git clone git@github.com:m-carrasco/net-ssa.git`
2629
2. `cd net-ssa`
27-
3. `docker build -t net-ssa/net-ssa .`
28-
4. `docker run --name dev -v $(pwd):/net-ssa -ti net-ssa/net-ssa`
30+
3. `git lfs checkout`
31+
* Install [git lfs](https://git-lfs.github.com/)
32+
4. `dotnet build && dotnet test`
33+
* This is optional, it requires installing dotnet.
34+
5. `docker build -t net-ssa/net-ssa .`
35+
6. `docker run --name dev -v $(pwd):/net-ssa -ti net-ssa/net-ssa`
2936
* This is now an interactive container. `$(pwd)` of the host is shared with the container as `net-ssa` source code folder.
30-
5. Introduce changes in the source code using your IDE as usual.
31-
6. Build and test in the container, execute these commands in the container terminal:
37+
7. Introduce changes in the source code using your IDE as usual.
38+
8. Build and test in the container, execute these commands in the container terminal:
3239
* `cd build`
33-
* `make build-dotnet`
40+
* `(cd /net-ssa && dotnet build)`
3441
* `lit integration-test/ -vvv`
3542
* `exit # once you finish working`
36-
7. `docker start -i dev # to resume the container terminal`
43+
9. `docker start -i dev # to resume the container terminal`
44+
3745

3846
## Build from sources
3947

40-
### Ubuntu 20.04.3
48+
### Ubuntu 20.04
49+
50+
1. `cd net-ssa`
51+
2. `git lfs checkout`
52+
* Install [git lfs](https://git-lfs.github.com/)
53+
3. `dotnet build`
54+
4. `dotnet test`
55+
5. `mkdir build`
56+
6. `cd build && cmake ..`
57+
7. `lit integration-test/ -vvv`
58+
59+
To know the required dependencies for the integration tests (`cmake` and `lit` step), please check the [Dockerfile](https://github.com/m-carrasco/net-ssa/blob/main/Dockerfile).
60+
The Dockerfile executes the shell scripts under the [ci](https://github.com/m-carrasco/net-ssa/tree/main/ci) folder. You would just need to execute them once in your system.
4161

42-
1. Read [Dockerfile](https://github.com/m-carrasco/net-ssa/blob/main/Dockerfile)
62+
### Windows and MacOS
4363

44-
### Ubuntu 18.04
64+
The steps are the same as in Ubuntu. The project building and unit testing is done in the CI. Yet, the integration tests aren't configured.
65+
Anyway, the dependencies should be the same as in Ubuntu. If you encounter any problem while trying this, please open an issue.
4566

46-
1. Read [./github/workflow/build.yml](https://github.com/m-carrasco/net-ssa/blob/main/.github/workflows/build.yml)
67+
## Build native dependencies
4768

48-
### Windows
69+
`net-ssa` has native dependencies, which are shipped in the project already. You shouldn't need to build them. Usually, this is only required for development. The supported systems are:
70+
* Linux - x86-64
71+
* Windows - x86-64
72+
* MacOS - x86-64 and arm64
4973

50-
It has not been tested yet. However, it should work as long as Souffle can be installed. Souffle can run there using _Windows Subsystem for Linux_.
74+
In case they must be re-built, [`./net-ssa/souffle/build-all-with-docker.sh`](https://github.com/m-carrasco/net-ssa/blob/main/souffle/build-all-with-docker.sh) is available. The script compiles these dependencies from scratch using the source code in your repository. Under the hood, the script isolates this process using Docker. This only builds the Linux and Windows dependencies. Cross-compilation for MacOS is incredible difficult. If you are a MacOS user, check the CI to figure out the required dependencies and execute `build-souffle-macos-x86-64-arm64.sh`.
5175

5276
## Examples
5377

ci/install-cmake.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2+
set -e
23
curl -s "https://cmake.org/files/v3.21/cmake-3.21.1-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local

ci/install-lit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2+
set -e
23
apt-get install -y python3-dev pip && pip install lit

0 commit comments

Comments
 (0)