pipeline {
    agent any
    stages {
        stage('Build-Linux') { 
            tools {
                jdk 'JDK21'
            }
            steps {
                sh 'java -version'
                sh 'echo $JAVA_HOME'
				sh 'rm -rf build/linux'
                sh 'mkdir -p build/linux'
                sh 'cmake -B build/linux -DCMAKE_BUILD_TYPE=Release' 
                sh 'cmake --build build/linux'
            }
        }
        stage('Build-Windows') { 
            tools {
                jdk 'JDK21-WIN'
            }
            steps {
                sh 'java -version'
                sh 'echo $JAVA_HOME'
				sh 'rm -rf build/windows'
                sh 'mkdir -p build/windows'
                sh 'cmake -B build/windows -DCMAKE_TOOLCHAIN_FILE=mingw.cmake -DCMAKE_BUILD_TYPE=Release' 
                sh 'cmake --build build/windows'
            }
        }
        stage('Package-Artifacts') {
            steps {
                sh '''
                    rm -rf dist
                    mkdir -p dist/native/windows
                    mkdir -p dist/native/linux

                    # copy linux .so and .so.* files
                    find build/linux -type f -name "*.so*" -exec cp {} dist/native/linux/ \\;

                    # copy windows dll files
                    find build/windows -type f -name "*.dll" -exec cp {} dist/native/windows/ \\;

                    # create zip
                    cd dist
                    zip -r ../VoidLoader.zip native
                '''
            }

            post {
                success {
                    archiveArtifacts artifacts: 'VoidLoader.zip', fingerprint: true
                }
            }
        }
    }
}

