Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
eltorio committed Sep 22, 2023
0 parents commit 45c32fd
Show file tree
Hide file tree
Showing 21 changed files with 1,269 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
46 changes: 46 additions & 0 deletions .github/workflows/multiarch-docker-hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Ce workflow utilise des actions qui ne sont pas certifiées par GitHub.
# Elles sont fournies par un tiers et régies par
# des conditions d’utilisation du service, une politique de confidentialité et un support distincts.
# documentation en ligne.

# GitHub recommande d’épingler les actions à un SHA de commit.
# Pour obtenir une version plus récente, vous devez mettre à jour le SHA.
# Vous pouvez également référencer une balise ou une branche, mais l’action peut changer sans avertissement.

name: Publish amd64/arm64 to docker Hub
on:
release:
types: [published]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3.4.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2.1.0
with:
platforms: 'arm64'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.5.0
- name: Log in to Docker Hub
uses: docker/login-action@v2.1.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4.4.0
with:
images: ${{ secrets.DOCKER_IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4.0.0
with:
context: .
platforms: linux/arm64, linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM debian:latest
ARG TARGETARCH
ARG DEBIAN_FRONTEND=noninteractive
LABEL maintainer="Ronan <ronan@parapente.eu.org>"
RUN apt update -y \
&& apt install -y lld llvm clang curl vim cmake openssl build-essential
RUN echo "Run for $TARGETARCH" && \
if [[ "$TARGETARCH" == "amd64" ]] ; then \
_ARCH=amd64; \
else \
_ARCH=aarch64 ; \
fi \
&& curl -fLSs https://github.com/Jake-Shadle/xwin/releases/download/0.3.1/xwin-0.3.1-${_ARCH}-unknown-linux-musl.tar.gz | tar -xvz \
&& mv xwin-0.3.1-${_ARCH}-unknown-linux-musl/xwin /usr/local/bin/ \
&& xwin --accept-license splat --output /usr/share/msvc \
&& rm -rf xwin-0.3.1-${_ARCH}-unknown-linux-musl \
&& rm -rf .xwin-cache
# bug in debian base image ???
RUN cmake --version 1> /dev/null 2> /dev/null \
&& apt update -y \
&& apt reinstall libssl3 openssl \
&& cmake --version
COPY test /usr/share/msvc/test
RUN chmod ugo+x /usr/share/msvc/test/test.sh
CMD "/usr/bin/sleep infinity"
651 changes: 651 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# LLVM for MSVC
## Why
I have a Kubernetes cluster running aarch64 linux workers.
I wanted to compile some apps on this cluster.
Mingw(64) is a fantastic tool but…
The main idea was to use the current Windows SDK and the MSVC runtime like you do with Visual Studio.
I found a fantastic tool https://github.com/Jake-Shadle/xwin made by Jake Shadle. His tool can download the CRT and the SDK directly from Microsoft servers.
And thanks to clang/llvm and its target x86_64-pc-windows-msvc , building Windows x86_64 apps on linux aarch64 is possible…

In /usr/share/msvc/test you'll find a minimal Windows application.
With /usr/share/msvc/test/test.sh you can test a full compilation and executable generation.

# Compile with script
test.sh contains:
```sh
#!/bin/bash
export MSVC_BASE=/usr/share/msvc
clang -target x86_64-pc-windows-msvc -I$MSVC_BASE/sdk/include/um -I$MSVC_BASE/sdk/include/shared -I$MSVC_BASE/sdk/include/ucrt -I$MSVC_BASE/crt/include -I./include -c src/test.c -o test.o
clang -target x86_64-pc-windows-msvc -I$MSVC_BASE/sdk/include/um -I$MSVC_BASE/sdk/include/shared -I$MSVC_BASE/sdk/include/ucrt -I$MSVC_BASE/crt/include -I./include -c src/MainWindow.c -o MainWindow.o
clang -target x86_64-pc-windows-msvc -I$MSVC_BASE/sdk/include/um -I$MSVC_BASE/sdk/include/shared -I$MSVC_BASE/sdk/include/ucrt -I$MSVC_BASE/crt/include -I./include -c src/AboutDialog.c -o AboutDialog.o

lld-link /libpath:$MSVC_BASE/sdk/lib/um/x86_64 /libpath:$MSVC_BASE/sdk/lib/ucrt/x86_64 /libpath:$MSVC_BASE/crt/lib/x86_64 \
/subsystem:WINDOWS \
user32.lib kernel32.lib gdi32.lib comctl32.lib \
vcruntime.lib uuid.lib ucrt.lib \
test.o MainWindow.o AboutDialog.o \
/out:test.exe
```
27 changes: 27 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Namespace='sandbox'

default_registry('ttl.sh/sanbox-llvm-17az3650')
Registry='ttl.sh/sanbox-llvm-17az3650'

allow_k8s_contexts('kubernetesOCI')

#Registry='registry.oci.sctg.eu.org'
#default_registry(Registry)

os.putenv ( 'DOCKER_USERNAME' , 'ociregistry' )
os.putenv ( 'DOCKER_PASSWORD' , 'eiFooxoh8h4e' )
os.putenv ( 'DOCKER_EMAIL' , 'none@example.org' )
os.putenv ( 'DOCKER_REGISTRY' , Registry )
os.putenv('NAMESPACE',Namespace)

# docker_build('highcanfly/llvm4msvc:latest', '.', entrypoint='/bin/bash')

k8s_yaml('./test/test.yaml')

custom_build('highcanfly/llvm4msvc','./kaniko-build.sh',[
'./test'
],skips_local_docker=True,
live_update=[
sync('./test', '/usr/share/msvc/test')
])

58 changes: 58 additions & 0 deletions kaniko-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# Tiltfile looks like:
# os. putenv ( 'DOCKER_USERNAME' , 'registry-user' )
# os. putenv ( 'DOCKER_PASSWORD' , 'password' )
# os. putenv ( 'DOCKER_EMAIL' , 'none@example.org' )
# os. putenv ( 'DOCKER_REGISTRY' , 'registry.example.org' )
# Namespace='sandbox-hcfp'
# os.putenv('NAMESPACE',Namespace)
# allow_k8s_contexts('kubernetes-admin')
# k8s_yaml(helm('./k8s/helm/hcfmailerplus', name='hcfmailer-plus', namespace=Namespace, values='dev-values.yaml'))
# custom_build('highcanfly/hcfmailer-plus','./kaniko-build.sh',['./autocert', './scripts'],skips_local_docker=True)

#kubectl create secret generic registry-credentials --from-file=.dockerconfigjson=$HOME/.docker/config.json --type=kubernetes.io/dockerconfigjson
#
# EXPECTED_REF=serveur/highcanfly_hcfmailer-plus:tilt-build-1683738819
# EXPECTED_IMAGE=highcanfly_hcfmailer-plus
# EXPECTED_TAG=tilt-build-1683738819
# REGISTRY_HOST=server.fqdn
# EXPECTED_REGISTRY=server.fqdn
echo "NAMESPACE=$NAMESPACE"
KANIKO_POD=$(kubectl -n $NAMESPACE get pods | grep "kaniko" | cut -d' ' -f1)
BAD_RANDOM=$(echo $RANDOM-$RANDOM-$RANDOM-$RANDOM | openssl dgst -sha1 )
echo "Random seed is $BAD_RANDOM"
kubectl create namespace $NAMESPACE
#kubectl create -n $NAMESPACE secret generic ssh-key-secret --from-file=ssh-privatekey=$HOME/.ssh/id_ecdsa --from-file=ssh-publickey=$HOME/.ssh/id_ecdsa.pub --from-literal=ssh-key-type=ecdsa
echo "CURRENT KANIKO POD is kaniko-$BAD_RANDOM"
kubectl -n $NAMESPACE delete pod --wait=false $KANIKO_POD 2>/dev/null
tar -cv --exclude "node_modules" --exclude "dkim.rsa" --exclude "private" --exclude "k8s" --exclude ".git" --exclude ".github" --exclude-vcs --exclude ".docker" --exclude "_sensitive_datas" -f - . | gzip -9 | kubectl run -n $NAMESPACE kaniko-$BAD_RANDOM \
--rm --stdin=true \
--image=highcanfly/kaniko:latest --restart=Never \
--overrides='{
"apiVersion": "v1",
"spec": {
"containers": [
{
"name": "kaniko",
"image": "highcanfly/kaniko:latest",
"imagePullPolicy": "IfNotPresent",
"stdin": true,
"stdinOnce": true,
"args": [
"-v","info",
"--cache=false",
"--dockerfile=Dockerfile'$EXT'",
"--context=tar://stdin",
"--skip-tls-verify",
"--destination='$EXPECTED_REF'",
"--image-fs-extract-retry=3",
"--push-retry=3",
"--single-snapshot"
]
}
],
"restartPolicy": "Never"
}
}'

#kubectl delete -n $NAMESPACE secret/registry-credentials
Binary file added test/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions test/include/AboutDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <windows.h>

/* Dialog procedure for our "about" dialog */
INT_PTR CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

/* Show our "about" dialog */
void ShowAboutDialog(HWND owner);
6 changes: 6 additions & 0 deletions test/include/Globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <windows.h>

/* Global instance handle */
extern HINSTANCE g_hInstance;
12 changes: 12 additions & 0 deletions test/include/MainWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <windows.h>

/* Window procedure for our main window */
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

/* Register a class for our main window */
BOOL RegisterMainWindowClass(void);

/* Create an instance of our main window */
HWND CreateMainWindow(void);
12 changes: 12 additions & 0 deletions test/include/Resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#define IDI_APPICON 101
#define IDR_MAINMENU 102
#define IDR_ACCELERATOR 103
#define IDD_ABOUTDIALOG 104
#define ID_FILE_EXIT 40001
#define ID_HELP_ABOUT 40002

#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
Binary file added test/res/.DS_Store
Binary file not shown.
Binary file added test/res/Application.ico
Binary file not shown.
30 changes: 30 additions & 0 deletions test/res/Application.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Supports Windows Vista / Server 2008 -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Supports Windows 7 / Server 2008 R2 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Supports Windows 8 / Server 2012 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Supports Windows 8.1 / Server 2012 R2 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Supports Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
</assembly>
73 changes: 73 additions & 0 deletions test/res/Resource.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <windows.h>
#include "Resource.h"

/* Win32 application icon */
IDI_APPICON ICON "Application.ico"

/* Our main menu */
IDR_MAINMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Help"
BEGIN
MENUITEM "&About", ID_HELP_ABOUT
END
END

/* Application manifest */
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "Application.manifest"

/* Executable version information */
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE
#else
FILEFLAGS 0
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", "Transmission Zero"
VALUE "FileDescription", "Win32 Example Application"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "Win32App"
VALUE "LegalCopyright", "�2017 Transmission Zero"
VALUE "OriginalFilename", "Win32App.exe"
VALUE "ProductName", "Win32 Example Application"
VALUE "ProductVersion", "1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END

/* Our "about" dialog */
IDD_ABOUTDIALOG DIALOGEX 0, 0, 147, 67
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
ICON IDI_APPICON,IDC_STATIC,7,7,20,20
LTEXT "Win32 Example Application",IDC_STATIC,34,7,89,8
LTEXT "�2017 Transmission Zero",IDC_STATIC,34,17,86,8
DEFPUSHBUTTON "OK",IDOK,90,46,50,14,WS_GROUP
END

/* Our accelerators */
IDR_ACCELERATOR ACCELERATORS
BEGIN
"A", ID_HELP_ABOUT, VIRTKEY, ALT, NOINVERT
END
39 changes: 39 additions & 0 deletions test/src/AboutDialog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "AboutDialog.h"
#include "Globals.h"
#include "Resource.h"

/* Dialog procedure for our "about" dialog */
INT_PTR CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
{
WORD id = LOWORD(wParam);

switch (id)
{
case IDOK:
case IDCANCEL:
{
EndDialog(hwndDlg, (INT_PTR)id);
return (INT_PTR)TRUE;
}
}
break;
}

case WM_INITDIALOG:
{
return (INT_PTR)TRUE;
}
}

return (INT_PTR)FALSE;
}

/* Show our "about" dialog */
void ShowAboutDialog(HWND owner)
{
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), owner, &AboutDialogProc);
}
Loading

0 comments on commit 45c32fd

Please sign in to comment.