Skip to content

Commit

Permalink
prebuild DXC-1.7.2207
Browse files Browse the repository at this point in the history
  • Loading branch information
NicSavichev committed Dec 2, 2023
1 parent 2718c21 commit 443f77f
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Build requirements

Requirements for building DXC package:
* Install Python 3
* Install cmake and ninja (`sudo apt install cmake` and `sudo apt install ninja-build` for Ubuntu)

## How to Build

First start `python3 s1_prepare_package.py`, this will clone DXC repo from github, checkout required version and download prebuilt win64 package.
Then it will create base DXC-* folder composed of actual include and lib folders (with `lib/win64` being filled with content of prebuilt win64 package)

Next start `s2_build_linux64.sh` (on linux) or `s2_build_macosx.sh` (on macOS) to build libdxcompiler.so and dxcompiler.dylib respectively.

The last step (optional) is to run `s3_make_package.sh` which will build *.tar.gz for DXC-* folder (you should copy built libs from foreign OS first).

## Releases

Releases will contain packaged *.tar.gz archive with includes and prebuilt dynamic libs for win64, linux and macOS.

Currently used DXC version is: 1.7.2207
88 changes: 88 additions & 0 deletions s1_prepare_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/python3
import sys
if sys.version_info.major < 3:
print("\nERROR: Python 3 or a higher version is required to run this script.")
exit(1)

import subprocess
import pathlib
import os
import urllib
import ssl
import ctypes
import zipfile
import shutil
from urllib import request

ssl._create_default_https_context = ssl._create_unverified_context

def run(cmd):
try:
print('Running: {0}'.format(cmd))
subprocess.run(cmd, shell = True, check = True)
except subprocess.CalledProcessError as e:
error('subprocess.run failed with a non-zero exit code. Error: {0}'.format(e))
except OSError as e:
print('An OSError occurred, subprocess.run command may have failed. Error: {0}'.format(e))

def download_url2(url, file):
file = ".packages/{0}".format(file)
if not pathlib.Path(file).exists():
print("Downloading '{0}' to '{1}' ...".format(url, file));
response = request.urlretrieve(url, file)
else:
print("Package '{0}' already exists".format(file));

def download_url(url):
path, file = os.path.split(os.path.normpath(url))
download_url2(url, file)

def clone_git_repo(DXC_PACKAGE, DXC_VERSION):
prev_cwd = os.getcwd()
if not pathlib.Path(DXC_PACKAGE).exists():
run('git clone "https://github.com/microsoft/{0}.git"'.format(DXC_PACKAGE))

os.chdir(os.path.normpath(DXC_PACKAGE))
run('git fetch --all --tags')
run('git reset --hard origin/main')
run('git checkout v{0}'.format(DXC_VERSION))
if DXC_VERSION == '1.7.2207':
run('git cherry-pick 47f31378a9b51894b0465b33ac1d10ce6349a468')
run('git cherry-pick 396e45cbc49cfba17adf3e813064b07ab4373659')
run({'git submodule init'})
run({'git submodule update'})
os.chdir(prev_cwd)

def download_prebuilt_win():
download_url('https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.7.2207/dxc_2022_07_18.zip')
with zipfile.ZipFile(os.path.normpath('.packages/dxc_2022_07_18.zip'), 'r') as zip_file:
zip_file.extractall('.packages/_win')

# prepare base package data
DXC_PACKAGE = 'DirectXShaderCompiler'
DXC_VERSION = '1.7.2207'

pathlib.Path('.packages').mkdir(parents=True, exist_ok=True)
clone_git_repo(DXC_PACKAGE, DXC_VERSION)
download_prebuilt_win()

if pathlib.Path('DXC-{0}'.format(DXC_VERSION)).exists():
shutil.rmtree('DXC-{0}'.format(DXC_VERSION))
pathlib.Path('DXC-{0}/include'.format(DXC_VERSION)).mkdir(parents=True, exist_ok=True)
pathlib.Path('DXC-{0}/lib'.format(DXC_VERSION)).mkdir(parents=True, exist_ok=True)
pathlib.Path('DXC-{0}/lib/win64'.format(DXC_VERSION)).mkdir(parents=True, exist_ok=True)
pathlib.Path('DXC-{0}/lib/linux64'.format(DXC_VERSION)).mkdir(parents=True, exist_ok=True)
pathlib.Path('DXC-{0}/lib/macosx'.format(DXC_VERSION)).mkdir(parents=True, exist_ok=True)

shutil.copy2('{0}/LICENSE.TXT'.format(DXC_PACKAGE), 'DXC-{0}/LICENSE.TXT'.format(DXC_VERSION))
shutil.copy2('.packages/_win/bin/x64/dxcompiler.dll', 'DXC-{0}/lib/win64/'.format(DXC_VERSION))
try:
shutil.copytree('{0}/include/dxc'.format(DXC_PACKAGE), 'DXC-{0}/include/dxc'.format(DXC_VERSION), dirs_exist_ok=True, ignore_dangling_symlinks=True)
except TypeError as e:
shutil.copytree('{0}/include/dxc'.format(DXC_PACKAGE), 'DXC-{0}/include/dxc'.format(DXC_VERSION), ignore_dangling_symlinks=True)
except OSError as e:
print('Ignoring OSError {0}'.format(e))

print('Basic folder prepared: DXC-{0}/include'.format(DXC_VERSION))
print('Build linux64 and macosx libraries using ./build_linux64.sh and /build_macosx.sh\n (place results to ..lib/linux64 and ..lib\macosx)')
print('And run ./build_result_zip.sh to finally get .zip for upload')
15 changes: 15 additions & 0 deletions s2_build_linux64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

DXC_PACKAGE="DirectXShaderCompiler"
DXC_VERSION="1.7.2207"

cd "$DXC_PACKAGE"

mkdir -p "build/"
cd "build/"

cmake ".." -GNinja -DCMAKE_BUILD_TYPE=Release -C "../cmake/caches/PredefinedParams.cmake"
ninja

cd ../..
cp $DXC_PACKAGE/build/lib/libdxcompiler.so.3.7 DXC-$DXC_VERSION/lib/linux64/libdxcompiler.so
14 changes: 14 additions & 0 deletions s2_build_macosx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/zsh

DXC_PACKAGE="DirectXShaderCompiler"
DXC_VERSION="1.7.2207"

mkdir -p build
mkdir -p build/docs
cd build

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS=-Werror -DCMAKE_CXX_FLAGS=-Wno-deprecated-declarations -C ../$DXC_PACKAGE/cmake/caches/PredefinedParams.cmake ../$DXC_PACKAGE
cmake --build .

cd ..
cp build/lib/libdxcompiler.3.7.dylib DXC-$DXC_VERSION/lib/macosx/dxcompiler.dylib
2 changes: 2 additions & 0 deletions s3_make_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DXC_VERSION="1.7.2207"
tar -czf DXC-$DXC_VERSION.tar.gz DXC-$DXC_VERSION

0 comments on commit 443f77f

Please sign in to comment.