Commit 8f797026 authored by Drew's avatar Drew

Add actual effects to the configurations

This extends #104 by adding actual effects to the configurations rather than have them be no-ops.

Effects include:

* debug instrumentation (new in this PR), for emitting `-g` (see #73 for an obvious extension)
* optimization control / WMO control
* compression level (faster debug atbins)
* test instrumentation (`-enable-testing`)
* `#if ATBUILD_RELEASE` etc. from Swift code

There are some deprecations associated with this PR:

* `whole-module-optimization` atllbuild option is now deprecated; use `--configuration release` instead.  There currently is no plan to control these separately, use `--configuration plain` + `:compileOptions ["-O"]` to get optimization without WMO.  Or open a bug to complain about this change.
* `magic` atllbuild option is now deprecated; to opt out of magic use `--configuration none` instead.

Doc PR to follow.

In addition, CI is now updated to produce release (optimized) builds for atbuild, which significantly optimizes atbuild performance.
parent 86a5dffb
......@@ -13,6 +13,15 @@
// limitations under the License.
public enum Configuration {
public enum DebugInstrumentationType {
///Instrumentation should be included in the target
case Included
///No instrumentation for the target
case Omitted
///Instumentation should be generated separately, e.g. DWARF
case Stripped
}
///Built-in configurations
///The default configuration.
......@@ -105,4 +114,13 @@ extension Configuration {
case .User: return nil
}
}
///Whether debug instrumentation
var debugInstrumentation: DebugInstrumentationType {
switch(self) {
case .Debug, .Test: return .Included
case .Release, .Benchmark: return .Stripped
case .User, .None: return .Omitted
}
}
}
\ No newline at end of file
......@@ -176,9 +176,13 @@ class PackageAtbin:Tool {
let cmd: String
switch Platform.hostPlatform {
case .OSX:
cmd = "tar c --options \"xz:compression-level=9\" -Jf \(tarxz) bin/\(name).atbin -C bin"
let fc = currentConfiguration.fastCompile == true
let compressionLevel = fc ? "0" :"9"
cmd = "tar c --options \"xz:compression-level=\(compressionLevel)\" -Jf \(tarxz) bin/\(name).atbin -C bin"
case .Linux:
cmd = "XZ_OPT=-8 tar cJf \(tarxz) bin/\(name).atbin -C bin"
let fc = currentConfiguration.fastCompile == true
let compressionLevel = fc ? "0" :"8"
cmd = "XZ_OPT=-\(compressionLevel) tar cJf \(tarxz) bin/\(name).atbin -C bin"
default:
fatalError("Unsupported host platform \(Platform.hostPlatform)")
}
......
......@@ -54,6 +54,19 @@ final class Shell : Tool {
mysetEnv("ATBUILD_CONFIGURATION_NO_MAGIC", o ? "1":"0")
}
//expose debug configuration info
let conf: String
switch (currentConfiguration.debugInstrumentation) {
case .Included:
conf = "included"
case .Omitted:
conf = "omitted"
case .Stripped:
conf = "stripped"
}
mysetEnv("ATBUILD_CONFIGURATION_DEBUG_INSTRUMENTATION", conf)
//does bin path not exist?
//let's create it!
let binPath = try! FS.getWorkingDirectory().appending("bin")
......
......@@ -331,7 +331,7 @@ final class ATllbuild : Tool {
let _ = try? FS.createDirectory(path: workDirectory.appending("objects"))
let _ = try? FS.createDirectory(path: workDirectory.appending("include"))
//parse arguments
///MARK: parse arguments
var linkWithProduct: [String] = []
if let arr_ = task[Options.LinkWithProduct.rawValue] {
guard let arr = arr_.vector else {
......@@ -593,15 +593,6 @@ final class ATllbuild : Tool {
///The next task will not be bootstrapped.
defer { Platform.buildPlatform = Platform.hostPlatform }
if task[Options.Magic.rawValue] == nil || task[Options.Magic.rawValue]?.bool == true {
switch(Platform.buildPlatform) {
case .OSX:
linkOptions.append(contentsOf: ["-Xlinker","-dead_strip"])
default:
break
}
}
let sdk: Bool
if task[Options.LinkSDK.rawValue]?.bool == false {
sdk = false
......@@ -626,16 +617,68 @@ final class ATllbuild : Tool {
swiftCPath = findToolPath(toolName: "swiftc", toolchain: toolchain)
}
let enableWMO: Bool
var enableWMO: Bool
if let wmo = task[Options.WholeModuleOptimization.rawValue]?.bool {
enableWMO = wmo
print("wmo is deprecated. Please use --configuration release instead.")
print("If you aren't able to migrate to --configuration, please file a bug with your usecase at https://github.com/AnarchyTools/atbuild/issues")
sleep(5)
}
else { enableWMO = false }
// MARK: Configurations
if currentConfiguration.testingEnabled == true {
compileOptions.append("-enable-testing")
}
//"stripped" is implemented as "included" here, that is a bug
//see https://github.com/AnarchyTools/atbuild/issues/73
if currentConfiguration.debugInstrumentation == .Included || currentConfiguration.debugInstrumentation == .Stripped {
compileOptions.append("-g")
}
if currentConfiguration.optimize == true {
compileOptions.append("-O")
enableWMO = true
}
if task[Options.Magic.rawValue] != nil {
print("Warning: Magic is deprecated. Please migrate to --configuration none. If --configuration none won't work for your usecase, file a bug at https://github.com/AnarchyTools/atbuild/issues")
sleep(5)
}
if currentConfiguration.fastCompile==false && task[Options.Magic.rawValue]?.bool != false {
switch(Platform.buildPlatform) {
case .OSX:
linkOptions.append(contentsOf: ["-Xlinker","-dead_strip"])
default:
break
}
}
switch(currentConfiguration) {
case .Debug:
compileOptions.append("-DATBUILD_DEBUG")
case .Release:
compileOptions.append("-DATBUILD_RELEASE")
case .Benchmark:
compileOptions.append("-DATBUILD_BENCH")
case .Test:
compileOptions.append("-DATBUILD_TEST")
case .None:
break //too much magic to insert an arg in this case
case .User(let str):
compileOptions.append("-DATBUILD_\(str)")
}
// MARK: emit llbuildyaml
let yaml = llbuildyaml(sources: sources, workdir: workDirectory, modulename: name, linkSDK: sdk, compileOptions: compileOptions, linkOptions: linkOptions, outputType: outputType, linkWithProduct: linkWithProduct, linkWithAtbin: linkWithAtbin, swiftCPath: swiftCPath, executableName: executableName, enableWMO: enableWMO)
let _ = try? yaml.write(to: llbuildyamlpath)
if bootstrapOnly { return }
//MARK: execute build
switch moduleMap {
case .None:
break
......@@ -648,7 +691,6 @@ final class ATllbuild : Tool {
}
}
//SR-566
let cmd = "\(findToolPath(toolName: "swift-build-tool",toolchain: toolchain)) -f \(llbuildyamlpath)"
anarchySystem(cmd)
if task[Options.PublishProduct.rawValue]?.bool == true {
......
......@@ -17,5 +17,13 @@
}
}
}
:build {
:tool "atllbuild"
:sources ["src/**.swift"]
:name "conftest"
:output-type "executable"
:publish-product true
}
}
)
\ No newline at end of file
#if ATBUILD_DEBUG
print("Debug build")
#elseif ATBUILD_RELEASE
print("Release build")
#elseif ATBUILD_TEST
print("Test build")
#elseif ATBUILD_BENCH
print("Bench build")
#elseif ATBUILD_JAMES_BOND
print("James bond build")
#endif
\ No newline at end of file
......@@ -19,7 +19,7 @@ commands:
module-name: platforms
module-output-path: .atllbuild/products/platforms.swiftmodule
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-D", "LINUX"]
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-D", "LINUX", "-g", "-DATBUILD_DEBUG"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o"]
......
......@@ -19,10 +19,10 @@ commands:
module-name: platforms
module-output-path: .atllbuild/products/platforms.swiftmodule
temps-path: .atllbuild/llbuildtmp
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk", "-D", "OSX"]
other-args: ["-j8", "-D", "ATBUILD", "-I", ".atllbuild/products/", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk", "-D", "OSX", "-g", "-DATBUILD_DEBUG"]
<atllbuild>:
tool: shell
inputs: ["<atllbuild-swiftc>", ".atllbuild/objects/main.swift.o"]
outputs: ["<atllbuild>", ".atllbuild/products/platforms"]
args: ["/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc", "-o", ".atllbuild/products/platforms", ".atllbuild/objects/main.swift.o", "-Xlinker", "-dead_strip"]
args: ["/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc", "-o", ".atllbuild/products/platforms", ".atllbuild/objects/main.swift.o"]
description: Linking executable .atllbuild/products/platforms
......@@ -8,8 +8,6 @@
:name "wmo"
:output-type "static-library"
:publish-product true
:whole-module-optimization true
:compile-options ["-O"]
}
}
......
......@@ -11,11 +11,7 @@ pwd
echo "****************SELF-HOSTING TEST**************"
if ! $ATBUILD package --use-overlay static; then
echo "Self-host failed; maybe you're not running CaffeinatedSwift?"
echo "Retrying with non-static build"
$ATBUILD package
fi
$ATBUILD atbuild
echo "****************CONFIGURATION TEST**************"
......@@ -38,6 +34,42 @@ if ! grep "\-always some flag --bond james bond" /tmp/configurations.txt; then
exit 1
fi
## try atllbuild-level config
$ATBUILD --configuration debug build
bin/conftest > /tmp/configurations.txt
if ! grep "Debug build" /tmp/configurations.txt; then
echo "Invalid configuration behavior"
exit 1
fi
$ATBUILD --configuration release build
bin/conftest > /tmp/configurations.txt
if ! grep "Release build" /tmp/configurations.txt; then
echo "Invalid configuration behavior"
exit 1
fi
$ATBUILD --configuration test build
bin/conftest > /tmp/configurations.txt
if ! grep "Test build" /tmp/configurations.txt; then
echo "Invalid configuration behavior"
exit 1
fi
$ATBUILD --configuration bench build
bin/conftest > /tmp/configurations.txt
if ! grep "Bench build" /tmp/configurations.txt; then
echo "Invalid configuration behavior"
exit 1
fi
$ATBUILD --configuration JAMES_BOND build
bin/conftest > /tmp/configurations.txt
if ! grep "James bond build" /tmp/configurations.txt; then
echo "Invalid configuration behavior"
exit 1
fi
echo "****************BITCODE TEST**************"
......@@ -403,7 +435,7 @@ $ATBUILD
echo "****************WMO TEST**************"
cd $DIR/tests/fixtures/wmo
$ATBUILD
$ATBUILD --configuration release
echo "****************UMBRELLA TEST**************"
cd $DIR/tests/fixtures/umbrella_header
......@@ -542,4 +574,15 @@ if $ATBUILD --use-overlay foo; then
exit 1
fi
printf "\e[1m\e[32m***ATBUILD TEST SCRIPT PASSED SUCCESSFULLY*****\e[0m"
\ No newline at end of file
printf "\e[1m\e[32m***ATBUILD TESTS PASSED SUCCESSFULLY*****\e[0m\n"
echo "*****************PACKAGING**********************"
cd $DIR
if ! $ATBUILD package --use-overlay static --configuration release; then
echo "Self-host failed; maybe you're not running CaffeinatedSwift?"
echo "Retrying with non-static build"
$ATBUILD package --configuration release
fi
printf "\e[1m\e[32m***ATBUILD BUILT SUCCESSFULLY*****\e[0m\n"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment